mage-os / mageos-common-async-events

This module implements the most common events like order creation or customer change for the Mage-OS Asynchronous Events module.
MIT License
6 stars 2 forks source link

Use sales_order_save_commit_after event #10

Open joachimVT opened 3 weeks ago

joachimVT commented 3 weeks ago

Hi

I am using the mageos-common-async-events module to dispatch a webhook call when a new order is placed is. The event sales_order_save_after fires, but it fails when the consumer is trying to fetch the order by order ID. Despite having the correct order ID in the observer, when the consumer is trying to fetch the order, it returns an error: The entity that was requested doesn't exist. Verify the entity and try again.

This is apparently because all _save_after observers allow for modification of the entity in question before MySQL commits it to the database, where as _save_commit_after observers waits until after the MySQL transaction has been committed. Since we don't want to modify the order, and instead we want to wait until after it's been saved completely in the DB, it would be better to use sales_order_save_commit_after instead of order_save_after.

What do you think

avstudnitz commented 3 weeks ago

@joachimVT Sounds reasonable. I'll test that and make the changes when I get to it. Otherwise, I'd be happy to receive a Pull Request from you :-) Does the same apply to the sales_order_shipment_save_after, sales_order_invoice_save_after and sales_order_creditmemo_save_after events?

joachimVT commented 3 weeks ago

Hi @avstudnitz I can make a PR for this change. I didn't test the other events, but the same logic applies for the other entities I think.