Exemple #1
0
 /**
  * Adds a product as an item to the cart
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @param int $quantity The quantity of the item to add to the cart
  * @param ShoppProduct|ShoppCartItem $Product Product object or cart item object to add to the cart
  * @param mixed $Price Price object to add to the cart
  * @param int $category The id of the category navigated to find the product
  * @param array $data Any custom item data to carry through
  * @return boolean
  **/
 public function additem($quantity = 1, &$Product, &$Price, $category = false, $data = array(), $addons = array())
 {
     if ('ShoppCartItem' == get_class($Product)) {
         $NewItem = $Product;
     } else {
         $NewItem = new ShoppCartItem($Product, $Price, $category, $data, $addons);
         if (!$NewItem->valid() || !$this->addable($NewItem)) {
             return false;
         }
     }
     do_action('shopp_cart_before_add_item', array($NewItem));
     $id = $NewItem->fingerprint();
     if ($this->exists($id)) {
         $Item = $this->get($id);
         $Item->add($quantity);
         $this->added($id);
     } else {
         $NewItem->quantity($quantity);
         $this->add($id, $NewItem);
         $Item = $NewItem;
     }
     $Totals = false === $this->Totals ? new OrderTotals() : $this->Totals;
     $Shipping = ShoppOrder()->Shiprates;
     $Totals->register(new OrderAmountCartItemQuantity($Item));
     $Totals->register(new OrderAmountCartItem($Item));
     foreach ($Item->taxes as $taxid => &$Tax) {
         $Totals->register(new OrderAmountItemTax($Tax, $id));
     }
     $Shipping->item(new ShoppShippableItem($Item));
     if (!$this->xitemstock($this->added())) {
         return $this->remove($this->added());
     }
     // Remove items if no cross-item stock available
     do_action_ref_array('shopp_cart_add_item', array($Item));
     return true;
 }