Async Order a module which enable a feature that order can be process the asynchronously which stands that order will be marked as “received” and order placement will be go into the queue and then all the processes of orders will be done from the queue on a first-in-first-out basis.
You can enable Async Order feature using the command-line interface:
bin/magento setup:config:set --checkout-async 1
or you can set command writes the following to the app/etc/env.php file:
... 'checkout' => [ 'async' => 1 ]
Let understand the flow of Asynchronous Order.
For example, a customer adds a product to their shopping cart. They fill out the Shipping Address, select their preferred Shipping Method, select a payment method, and place the order.
The shopping cart will be cleared, the order will be marked as Received, but the Product quantity is not adjusted yet, customer did not receive any confirmation E-mail.
The order details are not yet available because the order has not been fully processed.
It remains in the queue until the placeOrderProcess consumer begins, verifies the order with the inventory check feature (enabled by default), and updates the order as follows:
- Product available—the order status changes to Pending, the product quantity is adjusted, an email with order details is sent to the customer, and the successful order details become available for viewing in the Orders and Returns list with actionable options, such as reorder.
- Product out of stock or low supply—the order status changes to Rejected, the Product quantity is not adjusted, an email with order details about the issue is sent to the customer, and the rejected order details become available in the Orders and Returns list with no actionable options.
Cron should be working then it queue will be processed otherwise all the processes will be in Pending status and the order will never process.
Once all the order process has been done so the order will be shown at the admin end and the customer get the order confirmation mail.
Let’s understand the code flow.
When the customer placed an order so customer gets the order as ‘received’ status and the customer can’t perform any action.
All the order-related data comes into the sales_order table and where only a few data are present like quote_id, store_id, customer_id etc as compared to normal orders. (Shipping and payment info are not saved into it yet.)
When the queue runs so Magento\AsyncOrder\Model\Consumer calls it’s process() function where gets the order-related data like payment, shipping method and address from the queue_message table.
and then proceed for order management and Magento\Checkout\Model\PaymentInformationManagement calls it’s function savePaymentInformationAndPlaceOrder() and it’s saves payment Information, shipping Address and then it placed an order.
AsyncOrder compatibility
Category | Supported Feature |
Checkout types | OnePage Checkout Standard Checkout B2B Negotiable Quote |
Payment methods | Check/Money Order Cash on Delivery Braintree PayPal PayFlow Pro |
Shipping methods | All shipping methods are supported. |
Excluding payment methods
Developers can explicitly exclude certain payment methods from Asynchronous Order placement by adding them to the Magento\AsyncOrder\Model\OrderManagement::paymentMethods
array. Orders that use excluded payment methods are processed synchronously.
Example.
<type name="Magento\AsyncOrder\Model\OrderManagement"> <arguments> <argument name="paymentMethods" xsi:type="array"> <item name="hosted_pro" xsi:type="string">hosted_pro</item> <item name="payflow_advanced" xsi:type="string">payflow_advanced</item> <item name="payflow_link" xsi:type="string">payflow_link</item> </argument> </arguments> </type>
Let’s understand the Aysn order with the Braintree payment method.
When the customer adds a product to the cart and then selects a shipping method and Braintree payment so at the moment the customer will enter the card details and authorise the payment but at this time amount does not deduct from the account.
Order will be generated with payment additional information and details will be saved to the queue_message table.
- payment_method_nonce -> The one-time payment token generated by the Braintree payment gateway based on card details. It will be used to call the sales API when the queue runs.
- device_data –> Contains a fingerprint provided by Braintree JS SDK and should be sent with sale transaction details to the Braintree payment gateway.
When the queue runs so first all the details will be cross-checked at the Braintree end.
PayPal\Braintree\Gateway\Validator\GeneralResponseValidator::validate() function validates the details when the details are verified then create a transaction at the Braintree portal.
If there is any error to create a transaction so it will return the response as a failure and mark the order as rejected other cases it will generate the transaction at the portal and set the transaction to Magento order PayPal\Braintree\Gateway\Response\TransactionIdHandler::handle() function.
Magento Order at admin end
Here is the reference to the Braintree sandbox.
Happy Coding.
Be the first to comment.