There are two methods which retrieve model data.
Can anyone explain what is the difference between them ? Any help will be appreciated.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
getOrigData() returns the data in the object at the time it was initialised/populated.
After the model is initialised you can update that data and
getData() will return what you currently have in that object.
Have a look at
grep -R "origData" app/ so you can have a look at what is used.
In EE, it's very useful to log what is changed (Enterprise_Logging) module.
This is easiest explained by an example:
$product = Mage::getModel('catalog/product')->load(123); $product->getData('something'); // returns "foo" $product->setData('something', 'bar'); $product->getData('something'); // returns "bar" $product->getOrigData('something'); // returns "foo"
In a nutshell, every model (once loaded) will make a copy of the originally loaded data and store it in
Model_Class::_origData property. This makes it possible to do optimizations for
_beforeSave calls so that queries only modify the changed data and not rewrite the same data all the time.
Also, any time you call
setData() a flag is set that the model has changed data. You can check if a model has changed data by calling