这是标准行为,还是我做错了什么?

// 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

我正在尝试避免重写输出此代码的块,因为我们的一个插件已经这样做(bleh),所以这就是为什么我使用该事件的原因。

有帮助吗?

解决方案

可以选择包含整个 Catalog/Model/Resource/Product/Collection.php 用我的新方法 app/code/local/Mage 文件夹,但是除非绝对必要,否则我不愿诉诸于此。

其他提示

为什么不将父藏在您自己的块中?

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();
    }
}

你可以观察 controller_action_layout_load_before 并使用类似的东西

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

听起来有人弄错了,并实现了 new 而不是工厂方法 getSingleton()getModel() 无法在模块中解决此问题。

因此,如果您想拥有正确的类,则必须更改使用的模块 new

许可以下: CC-BY-SA归因
scroll top