/** * @param CartItemInterface $item * @param Request $request * * @throws ItemResolvingException * @return CartItemInterface|void */ public function resolve(CartItem $item, Request $request) { $productId = $request->query->get('id'); $itemForm = $request->request->get('cart_item_simple'); $productRepository = $this->manager->getRepository('EcommerceBundle:Product'); if (!$productId || !($product = $productRepository->find($productId))) { // no product id given, or product not found throw new \Exception('Requested product was not found'); } // assign the product and quantity to the item $item->setProduct($product); $item->setQuantity(intval($itemForm['quantity'])); // calculate item price adding the special charge $price = $product->getPrice(); if ($this->specialPercentageCharge > 0) { $price += $price * ($this->specialPercentageCharge / 100); } $item->setUnitPrice(intval($price)); return $item; }
/** * {@inheritdoc} */ public function equalsProduct(CartItem $cartItem) { return $this->getProduct()->getId() === $cartItem->getProduct()->getId(); }