My custom module observes the sales_order_place_after
event, and creates a customer and associates the customer with the order by setting customerId
for the order.
What works?
- Order is placed
- Customer is created
- The
customerId
is updated in the order database
What doesn’t work?
- The
customerId
is instantly set back toNULL
by another script
How can I find out what script updates the customerId
to NULL
again, after my observer is done running?
2
Answers
You should change event to sales_model_service_quote_submit_success
Example Code (Magento 2 Version): events.xml
GenerateObserver.php
I had the same problem – my assumption was that calling the
save
method on the order triggered whatever was listening to thesales_order_save_before/after
events, one of which was setting the customer ID back tonull
. I worked around this by saving only the attributes I wanted, rather than triggering a save on the entire order:This allowed me to successfully associate a customer with the order in Magento EE 1.14.3.10 using the
sales_model_service_quote_submit_success
event.