Magento搜索结果输入错误

时间:2015-06-29 15:27:50

标签: php magento magento-1.9

我正在处理Magento 1.9.1.0项目,搜索结果没有以正确的顺序显示。我已经修改了一个按位置顺序获取结果的函数(几乎可以工作),但它似乎首先循环遍历每个类别,按位置和名称的顺序列出该类别的产品,然后继续下一个类别 - 例如,如果我搜索" a":

防滑浴垫,浴缸安全条,方形淋浴垫,行走架,(此处订单中断,因为它已进入新类别)闹钟,放大电话。

我已经喜欢它回来了:

闹钟,放大电话,浴缸安全带​​,方形淋浴垫,行走架,防滑浴垫

(防滑浴垫将是最后一个,因为其他一切的位置为0,因为此产品的位置为10)。

有没有办法可以修改此搜索只显示所有产品而不按类别顺序排序?为实现目前的目标而编写的函数是:

public function setListOrders()
{
    $category = Mage::getSingleton('catalog/layer')
        ->getCurrentCategory();
    /* @var $category Mage_Catalog_Model_Category */
    $availableOrders = $category->getAvailableSortByOptions();
    unset($availableOrders['position']);
    $availableOrders = array_merge(array(
        'relevance' => $this->__('Relevance'),
        'name' => $this->__('Name'),
        'position' => $this->__('Position')
    ), $availableOrders);

    $this->getListBlock()
        ->setAvailableOrders($availableOrders)
        ->setDefaultDirection('asc')
        ->setSortBy('position');
    return $this;

}

和...

protected function _getProductCollection()
{
    if (is_null($this->_productCollection)) {
        $this->_productCollection = $this->getListBlock()->getLoadedProductCollection();
    }

return $this->_productCollection->addAttributeToSort('position')->addAttributeToSort('name');

}
编辑:我想要实现的是按照名为" pay_in_store"的自定义属性对产品进行排序,但结果似乎按正确顺序吐出第一类结果然后该类别的结果没有选项" pay_in_store"检查。然后它跳转到下一个类别并执行相同的操作。我不希望每个类别都有这个 - 我只需要将所有产品排空到结果中。

1 个答案:

答案 0 :(得分:0)

在local.xml或任何layout.xml文件中添加以下代码

<catalogsearch_result_index>
 <reference name="search_result_list">
    <action method="setDefaultDirection"><param>asc</param></action>
    <action method="setSortBy"><param>attribute_you_want_to_use</param></action>
 </reference>
</catalogsearch_result_index>