public function resolve(CartItemInterface $item, $request) { $productId = $request->query->get('productId'); // If no product id given, or product not found, we throw exception with nice message. if (!$productId || !($product = $this->getProductRepository()->find($productId))) { throw new ItemResolvingException('Requested product was not found'); } // Assign the product to the item and define the unit price. $item->setVariant($product); $item->setUnitPrice($product->getPrice()); // Everything went fine, return the item. return $item; }
public function resolve(CartItemInterface $item, $request) { $productId = $request->get('product'); $quantity = intval($request->get('quantity')); if ($quantity < 1) { throw new ItemResolvingException('Quantity must be 1 or higher'); } // If no product id given, or product not found, we throw exception with nice message. if (!$productId || !($product = $this->productRepository->find($productId))) { throw new ItemResolvingException('Requested product was not found'); } /** @var $product ProductInterface */ $item->setUnitPrice($product->getPrice()); /** @var $item OrderItem */ $item->setProduct($product); $this->modifier->modify($item, $quantity); // Everything went fine, return the item. return $item; }