【问题标题】:How override model in Magento correctly?如何正确覆盖 Magento 中的模型?
【发布时间】:2011-07-04 20:29:15
【问题描述】:

伙计们。

我需要覆盖不同类中的 2 个函数(CatalogSearch/Layer.php 和 CatalogSearch/Mysql4/Fulltext/Collection.php)。所以,我有一个配置文件:

<config>
    <modules>
        <my_modulename>
            <version>0.1</version>
        </my_modulename>
    </modules>
    <global>
        <models>
            <catalogsearch>
                <rewrite>
                    <layer>My_Modulename_Model_CatalogSearch_Layer</layer>
<mysql4_fulltext_collection>My_Modulename_Model_CatalogSearch_Mysql4_Fulltext_Collection </mysql4_fulltext_collection>
                </rewrite>
            </catalogsearch>
        </models>
    </global>
</config>

因此,Layer.php 已被正确覆盖,但 Collection.php 没有 - '/local/My/Modulename/Model/CatalogSearch/Mysql4/Fulltext/Collection.php' 甚至不包括在内。为什么?

感谢您的帮助。

【问题讨论】:

    标签: magento overriding


    【解决方案1】:

    资源模型可能是分开处理的,试试这个:

    <global>
        <models>
            <catalogsearch>
                <rewrite>
                    <layer>My_Modulename_Model_CatalogSearch_Layer</layer>
                </rewrite>
            </catalogsearch>
            <catalogsearch_mysql4>
                <rewrite>
                    <fulltext_collection>My_Modulename_Model_CatalogSearch_Mysql4_Fulltext_Collection</fulltext_collection>
                </rewrite>
            </catalogsearch_mysql4>
        </models>
    </global>
    

    【讨论】:

    • 完全正确...这可能是我没有尝试过的最后一个变体。我认为这是正确的 My_Modulename_Model_CatalogSearch_Mysql4_Fulltext_Collection
    • 查看app/code/core/Mage/CatalogSearch/etc/config.xml,您将看到&lt;catalogsearch&gt;&lt;catalogsearch_mysql4&gt; 的模型声明,这是您的重写将合并到的地方。它没有&lt;catalogsearch_mysql4_fulltext&gt; 部分,所以我怀疑它会起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 2014-05-21
    • 1970-01-01
    • 2011-03-13
    • 2012-09-22
    相关资源
    最近更新 更多