Ejemplo n.º 1
0
 /**
  * Store or update the item on local storage.
  *
  * @param  \Cartalyst\Cart\Collections\ItemCollection  $item
  * @param  \Cartalyst\Cart\Cart  $cart
  * @return \App\Models\CartItem
  */
 protected function storeItem(ItemCollection $item, Cart $cart)
 {
     // Get the product that was added to the shopping cart
     $product = Product::find($item->get('id'));
     // Get the cart from storage that belongs to the instance
     $_cart = $this->cart($cart->getInstance());
     // Does the product exist on storage?
     if (!($_item = $_cart->items()->whereProductId($product->id)->first())) {
         $_item = $_cart->items()->create(['product_id' => $product->id, 'quantity' => $item->get('quantity')]);
     } else {
         $_item->update(['quantity' => $item->get('quantity')]);
     }
     return $_item;
 }