Having some issues with an observer on the EAV product collection event for the Adminhtml product grid.
I am simple trying to add 2 new columns into the grid. Heres my XML:
<adminhtml>
<events>
<adminhtml_block_html_before>
<observers>
<vendor_module>
<class>vendor_module/adminhtml_observer</class>
<method>onBlockHtmlBefore</method>
</vendor_module>
</observers>
</adminhtml_block_html_before>
<eav_collection_abstract_load_before>
<observers>
<vendor_module>
<class>vendor_module/adminhtml_observer</class>
<method>onEavLoadBefore</method>
</vendor_module>
</observers>
</eav_collection_abstract_load_before>
</events>
</adminhtml>
This calls these 2 methods:
public function onBlockHtmlBefore(Varien_Event_Observer $observer) {
/** @var Mage_Adminhtml_Block_Widget_Grid $block */
$block = $observer->getBlock();
if (!isset($block)) return $this;
if ($block->getType() == 'adminhtml/catalog_product_grid') {
Mage::getModel('vendor_module/adminhtml_product_grid')->buildNewColumns($block);
}
}
public function onEavLoadBefore(Varien_Event_Observer $observer) {
/** @var Mage_Eav_Model_Entity_Collection_Abstract $collection */
$collection = $observer->getCollection();
if (!isset($collection)) {
return $collection;
}
$collection
->addAttributeToSelect('gender')
->addAttributeToSelect('season');
$observer->setCollection($collection);
}
The columns get outputted fine, but for some reason the data of season and gender doesn't get appended to the collection. After step debugging it seems that this observer doesn't get the collection at all or should i say there are no items in the collection.
Have any ideas? I assume that when i have the collection successfully and update the attributes being selected that they will show in the Grid for each product?
Magento 1.6.2.0