/** * add product * * @param tpyProductInterface $product * @param int $count * * @return tpyCartInterface */ public function addProduct(tpyProductInterface $product, $count = 1) { foreach ($this->getItems() as $item) { if ($item->getProductIdentifier() == $product->getUid()) { $cartItem = $item; break; } } if (isset($cartItem)) { $cartItem->increaseCount($count); } else { $cartItem = new tpyCartItem(); $cartItem->setCount($count)->setProductIdentifier($product->getUid())->setProductData($product->toJson()); $this->getItems()->add($cartItem); } return $this; }