简体   繁体   English

Magento搜索结果顺序错误

[英]Magento search results in wrong order

I'm working on a Magento 1.9.1.0 project and the search results aren't being displayed in the correct order. 我正在研究Magento 1.9.1.0项目,但搜索结果的显示顺序不正确。 I've modified a function to fetch the results in order of position (which almost works), but it appears to be looping through each category first, listing the products from that category in order of position and name and then moving on to the next category - for example, if I search "a": 我已经修改了一个功能,以按位置顺序获取结果(几乎可行),但是它似乎首先遍历每个类别,按位置和名称的顺序列出该类别的产品,然后继续进行下一个类别-例如,如果我搜索“ a”:

Anti-Slip Bath Mat, Bath Safety Strips, Square Shower Mat, Walking Frame, (here the order breaks, because it's entered a new category) Alarm Clock, Amplified Phone. 防滑浴室防滑垫,浴室安全带,方形淋浴垫,行走框架(由于输入了新类别,因此在此顺序中断了)闹钟,放大电话。

I'd have liked it to have returned: 我希望它返回:

Alarm Clock, Amplified Phone, Bath Safety Strips, Square Shower Mat, Walking Frame, Anti-Slip Bath Mat 闹钟,放大电话,浴室安全带,方形淋浴垫,行走框架,防滑浴室垫

(Anti-Slip Bath Mat would be last, because the position of everything else is 0 where as this product has a position of 10). (防滑浴垫将排在最后,因为其他所有产品的位置均为0,而该产品的位置为10)。

Is there a way I can amend this search just display all products without ordering them in category order? 有没有办法我可以修改此搜索,而只显示所有产品而无需按类别顺序订购? The function I'd written to achieve what I have so far is: 我为实现到目前为止所编写的功能是:

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;

}

and... 和...

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

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

}

EDIT: What I'm trying to achieve is to sort products by a custom attribute called "pay_in_store", but the results seem to spit out the first category of results in the correct order and then the results from that category that don't have the option "pay_in_store" checked. 编辑:我想要实现的是通过一个名为“ pay_in_store”的自定义属性对产品进行排序,但是结果似乎以正确的顺序吐出了第一类结果,然后从该类中没有了结果选项“ pay_in_store”已选中。 Then it jumps to the next category and does the same. 然后,它跳到下一个类别并执行相同的操作。 I don't want this on a per-category basis - I just need all products emptying into the results. 我不希望每个类别都这样-我只需要将所有产品清空到结果中即可。

add below code your local.xml or in your any layout.xml file 在下面的代码中添加您的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM