So ,i am developing some extension for the company I work for on Magento (enterprise) and I was testing some code in an Observer going like this:
$_customer=Mage::getModel("customer/customer")->load($_order->getCustomerId());
$_customer->setData("blah_attribute","blah_value");
$_customer->save();
die();
And while I was calling $_customer->save() and that seemed like the correct way to save my customer object the data was never getting saved! So I dug into that save() function and down the road ended up realizing that this function was not actually saving but just building an array of things to update in the database. So I figured maybe it just builds all that big array of things to update (there seems to be also an array of things to insert, an array of things to delete and so on..) and at some point later it must go through those arrays and actually do it. I can understand how that can improve performance but that can also make testing pretty confusing! So anyways at some point I just removed the
die();
and suddenly my data was actually getting saved. (hours wasted! :/ )
I was wondering if anyone would be able to provide a little more insight on how that save() process actually works?
- Which classes are called? When? By what processes?
- How come it saves afterwards? At which point?
- Can this sometimes cause problems?
- Is there a way to force the save to happen right away?