Exemplo n.º 1
0
 /**
  * Adds an item to the wishlist
  *
  * @param string $variant_id            
  * @param \Shop\Models\Products $product            
  * @param array $post            
  */
 public function addItem($variant_id, \Shop\Models\Products $product, array $post)
 {
     $wishlistitem = \Shop\Models\Carts::createItem($variant_id, $product, $post);
     // Is the item already in the wishlist?
     // if so, inc quantity
     // otherwise add the wishlistitem
     $exists = false;
     foreach ($this->items as $key => $item) {
         if ($item['hash'] == $wishlistitem->hash) {
             $exists = true;
             $wishlistitem->id = $item['id'];
             $wishlistitem->quantity = $wishlistitem->quantity + $item['quantity'];
             $this->items[$key] = $wishlistitem->cast();
             break;
         }
     }
     if (!$exists) {
         $this->items[] = $wishlistitem->cast();
     }
     return $this->save();
 }