Example #1
0
 /**
  * Add an item to the cart.
  *
  * @param  Array  $product
  * @return \Anam\Phpcart\Collection
  */
 public function add(array $product)
 {
     $this->collection->validateItem($product);
     // If item already added, increment the quantity
     if ($this->has($product['id'])) {
         $item = $this->get($product['id']);
         return $this->updateQty($item->id, $item->quantity + $product['quantity']);
     }
     $this->collection->setItems($this->session->get($this->getCart(), []));
     $items = $this->collection->insert($product);
     $this->session->set($this->getCart(), $items);
     return $this->collection->make($items);
 }