コード例 #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);
     }
 }