I understand that the _data of a simple model (e.g., cataloginventory/stock_item) is an array of field value pairs, which corresponding to the fields of database tables. I was curious to know the content of _data for EAV models, so I checked the _data of catalog/product using the debug() function.

The finding is that it contains the field values pairs of catalog_product_entity, and also some attribute of this entity. They are make sense to me. The point I can't understand is that is also contain a pair:

[stock_item (Mage_CatalogInventory_Model_Stock_Item)] => Array
                [item_id] => 1
                [product_id] => 1

, which is an instance of cataloginventory/stock_item. This is neither an attribute of catalog/product entity, nor a field in catalog_product_entity, why it is included?

Is there a convention of _data for EAV models?

1 Answer 1


In theory _data can contain anything.
You can add your custom values in there by using setData($key, $value).
Usually it contains like you said, the values for the columns in the table, or for attributes in case it's an EAV entity, but for some particular cases it can contain other values.
This happens for the products for example.
Here is why.
In the module Mage_CatalogInventory there is an observer for the event catalog_product_load_after. This event is called each time you call $product->load().
The method executed is Mage_CatalogInventory_Model_Observer::addInventoryData.
This one calls $productStockItem->assignProduct($product);.
If we dig deeper we end up in Mage_CatalogInventory_Model_Stock_Item::assignProduct that calls at one point $product->setStockItem($this);. This is eqivalent to $product->setData('stock_item', $this).
So you end up having the instance of Mage_CatalogInventory_Model_Stock_Item in _data['stock_item'].

Your Answer

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

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