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?
customerId is updated in the order databaseWhat doesn't work?
customerId is instantly set back to NULL by another scriptHow can I find out what script updates the customerId to NULL again, after my observer is done running?
I had the same problem - my assumption was that calling the save method on the order triggered whatever was listening to the sales_order_save_before/after events, one of which was setting the customer ID back to null. I worked around this by saving only the attributes I wanted, rather than triggering a save on the entire order:
$order
->setCustomerId($customer->getId())
->setCustomerIsGuest(0)
->setCustomerGroupId($customer->getGroupId());
$order->getResource()
->saveAttribute($order, 'customer_id' )
->saveAttribute($order, 'customer_is_guest')
->saveAttribute($order, 'customer_group_id');
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With