Closed m2-assistant[bot] closed 2 years ago
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-6908 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
This is really detailed issue, thanks
This issue is automatically created based on existing pull request: magento/magento2#36224: Fix best practice "Asynchronous order data processing" for auto invoiced orders
Description
Configuring order grid async indexing is meant to be a pretty quick win.
Configuring this value means we can still take orders and let the cron job be responsible for populating the admin tables, but unfortunately it only works when an order is not automatically invoiced during creation (so for us this breaks when used with paypal/stripe/etc)
Toggling the setting
dev/grid/async_indexing=1
is meant to ensure we do not populatesales_order_grid
,sales_invoice_grid
, and other grid tables during the synchronous request in which the order is being placed as any failure to insert into these admin panel grids could cause the actual order to fail and rollback with an error like soI haven't traced this back fully through the git history, but I believe this has been broken for a while.
To reproduce and testing
I have reproduced this on a vanilla installation of 2.4.5, you need a payment method which automatically creates the invoice when placing the order (for us on production this is Paypal/Stripe/etc) but for these test purposes I'll use the free checkout option.
The configuration
Also you should create a simple product that is in stock for purchasing, with a price of 0.00.
For the purposes of a quick test (and because I don't know if you have your crons running in your Magento internal test instances) I hacked up the grid reindexing code to throw an exception, we should be able to place the order and see the success page, verifying that we never try to reindex the grid during the place order action.
To reproduce the issue
Expected result:
sales_order_grid
orsales_invoice_grid
for your orderActual result:
https://user-images.githubusercontent.com/600190/193256993-d8b41219-0221-4cce-a245-7e64ab251679.mp4
When you take this approach you can see in the logs a stack trace showing the piece of code that is attempting to synchronously reindex the grid tables despite the flag being set.
The issue is this plugin which attempts to attach addresses to newly created invoices, and also reindex the grid.
https://github.com/magento/magento2/blob/d6ff7b706e25d9ca2ffd7ad66ebf29a6eda8c686/app/code/Magento/Sales/Model/Order/Invoice/Plugin/AddressUpdate.php#L52-L74
Seeing as we're creating the invoice during the same time as we're creating the order, this causes the
dev/grid/async_indexing
flag to not be respected.Proposed Solution
I believe using the same kind of logic that exists in
Magento\Sales\Model\GridAsyncInsert
andMagento\Sales\Model\GridSyncInsertObserver
should suffice, which is what i've put in this pull request.I've not yet chased down the static/unit/integration testing etc, as I wanted to get this out there and get a discussion going before burning any more time on this, if this solution looks acceptable I'll tidy thing up a bit.
Any input / comments / criticisms? I'd really like this patched in before we get into Black Friday / Christmas and any feedback is appreciated.
Contribution checklist (*)