1

我想在例如类中的单个方法中更改单行代码Mage_Reports_Model_Resource_Product_Collection。最简单的方法似乎是将整个类文件复制到app/code/local/...,但后来我已经替换了原始类,而不是覆盖了方法。

如何创建一个继承自 egMage_Reports_Model_Resource_Product_Collection并且只覆盖一个方法的新类?并且仍然告诉 Magento 使用我的新类而不是原来的类。

4

2 回答 2

1

这是重写产品集合的工作代码:

<global>
    <models>
        <reports_resource>
            <rewrite>
                <product_collection>Company_ModelName_Model_Resource_Product_Collection</product_collection>
            </rewrite>
        </reports_resource>
    </models>
</global>

它应该适用于Mage::getResourceModel('reports/product_collection')通话。

是的,我没有包括<config>标签,我认为你应该已经有<global>一个,所以我觉得没有必要。

于 2012-09-26T11:11:01.007 回答
0

从理论上讲,模型的重写将是......

<config>
    <global>
        <models>
            <reports>
                <rewrite>
                    <resource_product_collection>Namespace_Extension_Model_Resource_Product_Collection</resource_product_collection>
                </rewrite>
            </reports>
        </models>
    </global>
</config>

不过,我从来没有亲自重写过资源模型,所以我不能发誓它会起作用。这在很大程度上取决于集合的加载方式。

于 2012-09-26T10:04:17.043 回答