예제 #1
0
 private function generateProduct($count = 10)
 {
     // create simple parameter
     $propertyType = new PropertyType();
     $propertyType->id = 4;
     $propertyType->name = 'number';
     $propertyType->status_id = self::DEFAULT_STATUS_ID;
     $propertyType->save();
     // create a parameter implementation
     $property = new Property();
     $property->name = "Rok výroby";
     $property->type_id = $propertyType->id;
     $property->status_id = self::DEFAULT_STATUS_ID;
     $property->save();
     $partners = Partner::all();
     $feeds = Feed::all();
     // select brand
     $brands = Brand::all();
     // categories
     $categories = Category::all();
     for ($i = 0; $i < $count; $i++) {
         $brand = $brands[rand(0, count($brands) - 1)];
         $year = rand(2000, 2015);
         $name = sprintf("%s %s %d", $brand->title, $this->types[$brand->code][0], $year);
         $ean = EanUtil::getInstance()->generateEan();
         $product = new Product();
         $product->brand_id = $brand->id;
         $product->name = $name;
         $product->status_id = self::DEFAULT_STATUS_ID;
         $product->ean = $ean;
         $product->product_id = substr($ean, 0, 6);
         $product->save();
         $propertyYear = new ProductProperty();
         $propertyYear->value = "s:4:\"{$year}\"";
         $propertyYear->status_id = self::DEFAULT_STATUS_ID;
         $propertyYear->product_id = $product->id;
         $propertyYear->property_id = $property->id;
         $propertyYear->save();
         $this->generateProductFeedItem($product, $partners, $feeds);
         $category = $categories[rand(0, count($categories) - 1)];
         $productCategory = new Product\ProductCategory();
         $productCategory->product_id = $product->id;
         $productCategory->category_id = $category->id;
         $productCategory->status_id = self::DEFAULT_STATUS_ID;
         $productCategory->save();
         // $this->generateProductGallery($product);
     }
 }
예제 #2
0
 private function parseCategory()
 {
     $items = Category::all();
     $_items = [];
     foreach ($items as $item) {
         $_items[] = (object) ["id" => $item->id, "parent_id" => $item->parent_id, "title" => $item->name, "slug" => $item->slug];
     }
     $items = $_items;
     $childs = array();
     foreach ($items as &$item) {
         $childs[$item->parent_id][] =& $item;
     }
     unset($item);
     foreach ($items as &$item) {
         if (isset($childs[$item->id])) {
             $item->childs = $childs[$item->id];
         }
     }
     $this->categoryCache = $childs[0];
 }
예제 #3
0
 /**
  *
  * @param int $productId
  * @return type
  * @throws Exception
  */
 public function all()
 {
     $items = Category::all();
     $_items = [];
     foreach ($items as $item) {
         $_items[] = (object) ["id" => $item->id, "parent_id" => $item->parent_id, "title" => $item->name, "urlKey" => $item->slug, "slug" => $item->slug, "thumbPath" => $item->thumb_path];
     }
     $items = $_items;
     $childs = array();
     foreach ($items as &$item) {
         $childs[$item->parent_id][] =& $item;
     }
     unset($item);
     foreach ($items as &$item) {
         if (isset($childs[$item->id])) {
             $item->childs = $childs[$item->id];
         }
     }
     return $childs[0];
 }