Example #1
0
	/**
	 * Adds a product as an item to the cart
	 *	 
	 * @since 1.0
	 *
	 * @param int $quantity The quantity of the item to add to the cart
	 * @param Product $Product Product object to add to the cart
	 * @param Price $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
	 **/
	function add ($quantity,&$Product,&$Price,$addons=array(),$data=array(),$category=false) {

		$NewItem = new Item($Product,$Price,$addons,$data,$category);
		if (!$NewItem->valid()) return false;

		if (($item = $this->hasitem($NewItem)) !== false) {
			$this->contents[$item]->add($quantity);
			$this->added = $item;
		} else {
			$NewItem->quantity($quantity);
			$this->contents[] = $NewItem;
			$this->added = count($this->contents)-1;
		}

		do_action_ref_array('ecart_cart_add_item',array(&$NewItem));
		$this->Added = &$NewItem;

		$this->changed(true);
		return true;
	}
 /**
  * add()
  * Adds a product as an item to the cart */
 function add($quantity, &$Product, &$Price, $category, $data = array())
 {
     $NewItem = new Item($Product, $Price, $category, $data);
     if (!$NewItem->valid()) {
         return false;
     }
     if (($item = $this->hasitem($NewItem)) !== false) {
         $this->contents[$item]->add($quantity);
         $this->added = $this->contents[$item];
         $this->data->added = $item;
     } else {
         $NewItem->quantity($quantity);
         $this->contents[] = $NewItem;
         $this->data->added = count($this->contents) - 1;
         $this->added = $this->contents[$this->data->added];
         if ($NewItem->shipping && !$this->data->ShippingDisabled) {
             $this->data->Shipping = true;
         }
     }
     do_action_ref_array('shopp_cart_add_item', array(&$NewItem));
     $this->updated();
     return true;
 }