/** * add a product to the order * * @param timpanyProductInterface $product * @param int $count */ public function addItem(timpanyProductInterface $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 timpanyOrderItem(); $item->setProduct($product); $item->setOrder($this); } $item->setCount($item->setCount() + $count); $this->save(); }
public function getCountOfProduct(timpanyProductInterface $product) { $count = 0; foreach ($this->getItems() as $item) { if ($item->getProductIdentifier() == $product->getIdentifier()) { return $item->getCount(); } } return 0; }
/** * get count of a specific product * @param timpanyProductInterface $product * @return int Count of product */ public function getCountOfProduct(timpanyProductInterface $product) { return $this->_items[$product->getIdentifier()]['count']; }