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; }