Ejemplo n.º 1
0
 /**
  * add a product to the order
  * 
  * @param tpyProductInterface $product
  * @param int                 $count
  */
 public function addItem(tpyProductInterface $product, $count)
 {
     $itemRelation = $this->getTable()->getRelation('Items');
     if ($this->exists()) {
         $itemCollection = $itemRelation['table']->findByOrderId($this->getId());
         $is_new_item = true;
         foreach ($itemCollection as $item) {
             if ($product->getId() === $item->getProductId()) {
                 $is_new_item = false;
                 break;
             }
         }
     } else {
         $is_new_item = true;
     }
     if ($is_new_item) {
         $item = new tpyOrderItem();
         $item->setProduct($product);
         $item->setOrder($this);
     }
     $item->setCount($item->setCount() + $count);
     $this->save();
 }
 public function getCountOfProduct(tpyProductInterface $product)
 {
     $count = 0;
     foreach ($this->getItems() as $item) {
         if ($item->getProductIdentifier() == $product->getUid()) {
             return $item->getCount();
         }
     }
     return 0;
 }
Ejemplo n.º 3
0
 /**
  * get count of a specific product
  * @param tpyProductInterface $product
  * @return int Count of product
  */
 public function getCountOfProduct(tpyProductInterface $product)
 {
     return $this->_items[$product->getUid()]['count'];
 }