Пример #1
0
 public static function content()
 {
     $ids = array_keys(self::$data);
     if (!$ids) {
         return array();
     }
     $products = Product::whereIn('id', $ids)->get();
     foreach ($products as &$row) {
         $row->qty = self::$data[$row->id]['qty'];
     }
     return $products;
 }
Пример #2
0
 public function products($withSubs = true)
 {
     $catIds = $withSubs ? array_merge(array($this->id), $this->childIds(true)) : array($this->id);
     return Product::getByCategoryIds($catIds);
 }
Пример #3
0
 public function getMigration($act = null, $page = 1)
 {
     $updated = 0;
     $total = 0;
     $perIteration = 200;
     switch ($act) {
         case 'product-images':
             set_time_limit(0);
             $total = Product::count();
             $products = Product::select('id', 'image')->forPage($page, $perIteration)->get();
             // $products = Product::forPage($page, $perIteration)->get();
             if (!count($products)) {
                 $page = 0;
                 return 'END';
             }
             $page++;
             foreach ($products as $product) {
                 $images = DB::table('product_pictures')->where('product_id', $product->id)->get();
                 foreach ($images as $img) {
                     $file = public_path(trim($img->img_large, '/'));
                     if (!file_exists($file)) {
                         continue;
                     }
                     \ImageField::setValue($product, 'image', array('image' => $file));
                     // print_r($product->getAttribute('image'));exit;
                     if ($product->forceSave()) {
                         // echo $product->sku;
                     } else {
                         print_r($product->errors());
                         exit;
                     }
                     $updated++;
                 }
             }
             echo Redirect::to(Admin::url('shop/catalogue/migration/product-images' . ($page > 1 ? '/' . $page : '')));
     }
     //--------------------------------------------------------------------------
     return AdminUI::actions(array(array('title' => 'product-images' . ($page > 1 ? ' : ' . $page . ' of ' . floor($total / $perIteration) : ''), 'class' => 'danger', 'link' => 'shop/catalogue/migration/product-images' . ($page > 1 ? '/' . $page : ''))), '') . ($updated ? ' UPDATED:' . $updated : '');
 }