Question

Is this standard behavior, or am I doing something wrong?

// in event 'catalog_product_collection_load_before'
get_class($observer->getCollection());
 > Mage_Catalog_Model_Resource_Product_Collection
get_class(Mage::getModel('catalog/resource_product_collection'));
 > MyStuff_Catalog_Model_Resource_Product_Collection

I'm trying to avoid rewriting the block that outputs this code, since one of our plugins already does so (bleh), so that's why I'm using the event.

Was it helpful?

Solution

There is the option to include the entire Catalog/Model/Resource/Product/Collection.php with my new methods in the app/code/local/Mage folder, but I'm hesitant to resort to that unless it's absolutely necessary.

OTHER TIPS

Why not set the parent collection within your own block?

class Company_Module_Block_Customcollection extends Mage_Catalog_Block_Product_List {

    /**
     * Set collection to Product list before Html is rendered
     */
    public function _beforeToHtml() {
        parent::setCollection(Mage::getModel('catalog/category')->setCollection()); // <- Or custom collection
        parent::_beforeToHtml();
    }
}

You can observe controller_action_layout_load_before and use something like

public function observe($observer) {
    if ($observer->getEvent()->getAction()->getFullActionName() == 'checkout_cart_index')) {
         $observer->getEvent()->getLayout()->getUpdate()->addHandle('module_block');
    }
}

Sounds like someone made it wrong and instanciated with new instead of the factory methods getSingleton() and getModel() there is no way to fix this in your module.

So if you want to have the correct class, you have to change the module which uses the new

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top