3

In How to create order programmatically in Magento 2? it shows two methods on how to place a quote as an order. The first method uses

$order = $this->quoteManagement->submit($quote);

via \Magento\Quote\Model\QuoteManagement. This returns an \Magento\Sales\Model\Order object.

The second method is using

$cart = $this->cartRepositoryInterface->get($cart->getId());
$order_id = $this->cartManagementInterface->placeOrder($cart->getId());

This method uses both the \Magento\Quote\Api\CartRepositoryInterface $cartRepositoryInterface and the \Magento\Quote\Api\CartManagementInterface $cartManagementInterface.

Another approach I found is basically the first one, but using \Magento\Quote\Api\CartManagementInterface instead...

What are the differences between those approaches?

Abdul Pathan
2,84212 silver badges22 bronze badges
asked Jun 24, 2019 at 10:58

1 Answer 1

1

Calling $this->cartManagementInterface->placeOrder($cart->getId()) will still use $this->quoteManagement->submit($quote); to create the order, only difference is that after the order is successfully created, the checkout session is updated with the quote and order details:

 $this->checkoutSession->setLastQuoteId($quote->getId());
 $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
 $this->checkoutSession->setLastOrderId($order->getId());
 $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
 $this->checkoutSession->setLastOrderStatus($order->getStatus());

This is useful if you're placing your order from frontend since the success page is using the checkoutSession info for displaying.

answered May 18, 2020 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.