0

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

1
  • I had similar problem, but it seems to work if I took the event out of <adminhtml> for some reason.
    – frostshoxx
    Commented Jun 2, 2017 at 23:13

1 Answer 1

1

My options were inverted and therefore the value wasn't matching the label

2
  • Now it is working? Commented Feb 6, 2015 at 12:20
  • Yes it is except filtering unfortunately
    – Tom Burman
    Commented Feb 6, 2015 at 12:21

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.