我相信缺少的“钥匙”是以下两项:
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultOrder"><string>relevance</string></action>
您应该能够以几种不同的方式完成此操作……在任何一种情况下,您都需要制作所述文件的本地副本。
1)如果您还没有,请添加“catalogsearch.xml”的本地副本
注意:
由于 Magento 布局工作“级联”,因此最好先检查任何“其他”可用的 Magento 布局目录(“基础”除外)。例如,在我的例子中,我们使用 EE,因此我们首先检查“企业”布局目录以复制文件,然后再查看“基本”目录。
“catalogsearch.xml”的常见位置:
/app/design/frontend/base/default/layout/catalogsearch.xml(作为最后的手段) /app/design/frontend/enterprise/default/layout/catalogsearch.xml(对于 EE) 注意:可能有不同的位置PE也是......我不是100%。
2) 在“catalogsearch.xml”的“catalogsearch_result_index”部分添加以下内容:
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultOrder"><string>relevance</string></action>
例如:
引用“search_result_list”句柄(即企业布局):
<reference name="search_result_list">
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultOrder"><string>relevance</string></action>
</reference>
所以它最终看起来类似于:
<catalogsearch_result_index>
...other code
<reference name="search_result_list">
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultOrder"><string>relevance</string></action>
</reference>
...other code
</catalogsearch_result_index>
或者您可以直接放置在“search_result_list”块中(即基本布局):
<catalogsearch_result_index translate="label">
<label>Quick Search Form</label>
<reference name="root">
<action method="setTemplate"><template>page/3columns.phtml</template></action>
</reference>
<reference name="left">
<block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
<reference name="content">
<block type="catalogsearch/result" name="search.result" template="catalogsearch/result.phtml">
<block type="catalog/product_list" name="search_result_list" template="catalog/product/list.phtml">
<action method="setDefaultDirection"><string>desc</string></action>
<action method="setDefaultOrder"><string>relevance</string></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
<action method="setListOrders"/>
<action method="setListModes"/>
<action method="setListCollection"/>
</block>
</reference>
</catalogsearch_result_index>
3) 确保转储 Magento 缓存/存储并重新索引。
另一种选择是将它们作为“隐藏”表单元素放置在“form.mini.phtml”中
1) 将以下内容放在“form.mini.phtml”的表单中:
<input type="hidden" name="order" value="relevance">
<input type="hidden" name="dir" value="desc">
现在,“form.mini.phtml”中表单的开头看起来类似于:
<form id="search_mini_form" action="<?php echo $this->helper('catalogsearch')->getResultUrl() ?>" method="get">
<input type="hidden" name="order" value="relevance">
<input type="hidden" name="dir" value="desc">
...other code
2) 在 'catalogsearch.xml' 中的 'default' 部分('header' 参考句柄)中将路径更改为 'form.mini.phtml' 模板:
<default>
<reference name="header">
<block type="core/template" name="top.search" as="topSearch" template="custom_template/catalogsearch/form.mini.phtml"/>
</reference>
... other code
3) 确保转储 Magento 缓存/存储并重新索引。
最后说明...
下面是我们将其设置为的“自定义模板”路径结构。位于“企业”目录中,因此我的自定义文件将位于:/app/design/frontend/enterprise/custom_template/layout/catalogsearch.xml /app/design/frontend/enterprise/custom_template/template/catalogsearch/form.mini .phtml
希望这有意义并有所帮助。