Ejemplo n.º 1
0
 /**
  * Remove all variants if any.
  *
  * @param Product $product
  * @return bool
  */
 public function cleanUpVariants(Product $product)
 {
     if ($product->hasVariants()) {
         $this->getVariantRepository()->whereProduct($product)->delete();
     }
     return true;
 }
Ejemplo n.º 2
0
 public function store(AddItemToCartRequest $request, Product $product, StockValidator $stockValidator)
 {
     $attributes = $request->input('attributes', []);
     // If product has variant but the selected attributes don't match one
     // use the first variant by default.
     $variant = $product->variants()->hasAttributeOptions($attributes)->first();
     if ($product->hasVariants() and !$variant) {
         $variant = $product->variants()->first();
     }
     $stockValidator->validate($product, $variant, $request->input('quantity'));
     $this->cartManager->addItemToCart($this->user(), $product, $variant, $request->all());
     Session::flash('added_to_cart', 1);
     return $this->success('add');
 }