9

There are two methods which retrieve model data.

$model->getData();
$model->getOrigData();

Can anyone explain what is the difference between them ? Any help will be appreciated.

1
  • 2
    Nevermind, I didn't mean that. so I just wanna clarify confusing areas in magento. Because I have moved this e-commerce platform recently.
    – Sukeshini
    Sep 30, 2013 at 16:24

2 Answers 2

10

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 Varien_Object (getOrigData,setOrigData), 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.

1
15

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 $model->hasDataChanges().

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.