How override model in Magento correctly?

馋奶兔 提交于 2020-01-20 08:09:26

问题


guys.

I need to override 2 functions in different classes (CatalogSearch/Layer.php and CatalogSearch/Mysql4/Fulltext/Collection.php). So, I have a config file:

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

Hence, Layer.php has been overridden correctly , but Collection.php hasn't - '/local/My/Modulename/Model/CatalogSearch/Mysql4/Fulltext/Collection.php' was not even included. Why?

Thank you for any help.


回答1:


The resource models are probably handled separately, try this:

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


来源:https://stackoverflow.com/questions/6575826/how-override-model-in-magento-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!