Esempio n. 1
0
 /**
  * Add a product to the cart, if the product id already exists then increment its quantity
  * @param integer  $id
  * @param string  $name
  * @param integer  $price
  * @param integer $quantity
  * @param array   $options
  * @return array
  */
 public function add($id, $name = '', $price = 0, $quantity = 1, array $options = [])
 {
     $cartItems = $this->getCartSession();
     foreach ($cartItems as &$cartItem) {
         if ($cartItem['id'] == $id) {
             $cartItem['quantity'] = $cartItem['quantity'] + $quantity;
             $this->session->set(config('sescart.session_name'), $cartItems);
             return $cartItem;
         }
     }
     $newItem = ['id' => $id, 'name' => $name, 'price' => $price, 'quantity' => $quantity, 'options' => $options];
     $this->session->push(config('sescart.session_name'), $newItem);
     return $newItem;
 }