Ejemplo n.º 1
0
 /**
  * Adds an item to the shopping basket
  * 
  * @param 	Model_Basket_Item 	$item 	The item to be added
  */
 public function add_item(Interface_Basket_Item $item, $quantity = 1)
 {
     if (!$this->loaded()) {
         $this->save();
     }
     // check if the item is already in the basket
     $basket_item = $this->get_basket_item($item->get_id());
     if ($basket_item instanceof Model_Basket_Item) {
         // item is already in the basket so just increase the quantity
         $basket_item->quantity += $quantity;
     } else {
         $basket_item = new Model_Basket_Item();
         $basket_item->basket_id = $this->id;
         $basket_item->set_item($item);
         $basket_item->quantity = $quantity;
     }
     $basket_item->save();
 }
Ejemplo n.º 2
0
 /**
  * Setter for the item property. The item must be set before any of
  * the other functionality of the Model_Basket_Item class will work.
  * 
  * @param 	Interface_Basket_Item 	$item 	The item that this object will act as a wrapper for
  */
 public function set_item(Interface_Basket_Item $item)
 {
     $this->_item = $item;
     $this->item_type = get_class($this->_item);
     $this->item_identifier = $this->_item->get_id();
 }