quoteRepository = $quoteRepository; $this->quoteCreation = $quoteCreation; $this->quoteFilling = $quoteFilling; $this->shippingConfiguration = $shippingConfiguration; $this->paymentConfiguration = $paymentConfiguration; $this->purchase = $purchase; } /** * Place an order. * * @param Store $store * @param Customer $customer * @param InstantPurchaseOption $instantPurchaseOption * @param Product $product * @param array $productRequest * @return int order identifier * @throws LocalizedException if order can not be placed. * @throws Throwable if unpredictable error occurred. * @since 100.2.0 */ public function placeOrder( Store $store, Customer $customer, InstantPurchaseOption $instantPurchaseOption, Product $product, array $productRequest ) : int { $quote = $this->quoteCreation->createQuote( $store, $customer, $instantPurchaseOption->getShippingAddress(), $instantPurchaseOption->getBillingAddress() ); $quote = $this->quoteFilling->fillQuote( $quote, $product, $productRequest ); $quote->collectTotals(); $this->quoteRepository->save($quote); $quote = $this->quoteRepository->get($quote->getId()); try { $quote = $this->shippingConfiguration->configureShippingMethod( $quote, $instantPurchaseOption->getShippingMethod() ); $quote = $this->paymentConfiguration->configurePayment( $quote, $instantPurchaseOption->getPaymentToken() ); $orderId = $this->purchase->purchase( $quote ); return $orderId; } catch (Throwable $e) { $quote->setIsActive(false); $this->quoteRepository->save($quote); throw $e; } } }