Exemple #1
0
 private function esProduct($product)
 {
     $price = $this->getPrice($product);
     $images = $this->getImages($product);
     $productCategory = ProductCategory::where('product_id', $product->id)->get();
     $this->parseCategory();
     $category = $this->getCategory($productCategory[0]->category_id);
     logger()->info(sprintf("Found a price for %d: %f", $product->id, $price));
     $texts = $product->texts;
     $description = isset($texts[0]) ? $texts[0]->value : Lipsum::short()->text(3);
     $rating = ["stars" => 4.5, "count" => 23];
     $fixture = ["id" => $product->id, "title" => $product->brand->title . " " . $product->name, "brand" => $product->brand, "code" => str_slug($product->id . " " . $product->brand->title . " " . $product->name), "description" => $description, "category" => $category, "categoryFull" => json_encode($this->categoryCache), "productCode" => "123456", "labels" => $product->labels, "rating" => $rating, "supplier" => ["title" => "Partner 001", "code" => "partner-001"], "price" => ["price" => $price * 1, "priceVat" => $price * 1.2, "currencyCode" => "CZK"], "availability" => ["count" => 12, "code" => "partner_on_store"], "urlKey" => str_slug($product->id . " " . $product->brand->title . " " . $product->name), "url" => $category["road"] . "/" . str_slug($product->id . " " . $product->brand->title . " " . $product->name), "thumbnail" => isset($images[0]) ? $images[0] : [], "params" => [], "attachments" => [], "media" => [], "images" => $images, "alternatives" => []];
     return $fixture;
 }
 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);
     }
 }