magento:覆盖 Mage_CatalogSearch_Model_Query 以无效方法 prepareResult 结束

magento: override Mage_CatalogSearch_Model_Query ends with Invalid Method prepareResult

我尝试覆盖 Mage_CatalogSearch_Model_Query。

现在我尽量做到最少:

正在将重写块添加到 config.xml

<config>
...
  <global>
    <models>
      ...
      <catalogsearch>
        <rewrite>
          <fulltext>MyCompany_CatalogSearch_Model_Query</fulltext>
        </rewrite>
      </catalogsearch>
    </models>
  </global>
</config>

添加我的class

    <?php

    class MyCompany_CatalogSearch_Model_Query extends Mage_CatalogSearch_Model_Query
    {
    }

但是我得到

Invalid method MyCompany_CatalogSearch_Model_Query::prepareResult(Array ( ) )

我没有提供任何 prepareResult,但是当我不覆盖查询 class 时,它正在工作,所以我认为我应该继承这个方法,对吗?

我做错了什么?

看起来您正在尝试重写 Mage_CatalogSearch_Model_Fulltext class,而不是 Mage_CatalogSearch_Model_Query。这引发了这个问题。

调用catalogsearch/fulltext时,应该使用catalogsearch/query中没有的prepareResult方法。

如果您的目标是重写 catalogsearch/query,请按以下方式重写配置:

  <catalogsearch>
    <rewrite>
      <query>MyCompany_CatalogSearch_Model_Query</query>
    </rewrite>
  </catalogsearch>

如果你的目标是重写 Mage_CatalogSearch_Model_Fulltext class,请这样做:

class MyCompany_CatalogSearch_Model_Query extends Mage_CatalogSearch_Model_Fulltext
    {
    }

希望对您有所帮助。 :)