Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

overriding - How override model in Magento correctly?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...