覆盖magento中的资源模型类

时间:2014-05-26 14:02:04

标签: magento overwrite

我将 Mage_Catalog_Model_Resource_Product_Collection 类重写为 Namespace_Catalog_Model_Resource_Product_Collection 以覆盖受保护的函数( _preparePriceExpressionParameters )。

这是我在config.xml中编写的代码,用于覆盖此类文件。

<models>
    <catalog>
            <rewrite>
                    <resource_product_collection>Namespace_Catalog_Model_Resource_Product_Collection</resource_product_collection>
            </rewrite>
    </catalog>
</models>

但它不起作用,然后我更改了下面的代码,但这也不起作用。

<models>
    <catalog_resource_product>
        <rewrite>
            <collection>Namespace_Catalog_Model_Resource_Product_Collection</collection>
        </rewrite>
    </catalog_resource_product>
</models>

任何人都可以知道我做错了什么。

2 个答案:

答案 0 :(得分:3)

rewrite上方的节点必须与您要覆盖的模型中的<resourceModel>匹配,因此:

<global>
    <models>
        <namespace_catalog>
            <class>Namespace_Catalog_Model</class>
        </namespace_catalog>
        <catalog_resource>
            <rewrite>
                <product_collection>Namespace_Catalog_Model_Resource_Product_Collection</product_collection>
            </rewrite>
        </catalog_resource>
    </models>
</global>

答案 1 :(得分:0)

最后一个应该没问题。也许另一个模块已经覆盖了Mage_Catalog_Model_Resource_Product_Collection,这与你的覆盖相冲突。

相关问题