Example #1
0
 /**
  * @param Product $product
  *
  * @return ProductOption
  */
 protected function createProductOptionFor(Product $product) : ProductOption
 {
     $productOption = new ProductOption(['label' => uniqid('ProductOption', false)]);
     $product->options()->save($productOption);
     $productOption->stockItems()->save(new StockItem());
     return $productOption;
 }
 /**
  * @param Product $product
  */
 private function addProductOption(Product $product)
 {
     $productOption = new ProductOption(['label' => ucfirst($this->faker()->unique()->word)]);
     $product->options()->save($productOption);
     // Add stock items for the product option.
     $this->repeat(function () use($productOption) {
         $productOption->stockItems()->save(new StockItem());
     }, random_int(5, 10));
     $imagesIDs = [];
     foreach ($this->makeImages() as $image) {
         $imagesIDs[] = $image->id;
     }
     $productOption->images()->attach($imagesIDs);
     $productOption->save();
 }
 /**
  * @param Product $product
  * @param string  $label
  *
  * @return ProductOption
  */
 public function addOptionForProduct(Product $product, string $label)
 {
     $productOption = new ProductOption(['label' => $label]);
     return $product->options()->save($productOption);
 }