在Magento 1.9中添加一个新的“排序方式”


Adding a new "Sort by" in Magento 1.9

实际上我们只需要按名称升序和降序排序。我的致敬是"名字",所以我在/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php这样做:

public function setCollection($collection)
{
    $this->_collection = $collection;
    $this->_collection->setCurPage($this->getCurrentPage());
    $limit = (int)$this->getLimit();
    if ($limit) {
        $this->_collection->setPageSize($limit);
    }
            if ($this->getCurrentOrder()) 
        {
            if(($this->getCurrentOrder()) == 'name')    
                { 
                    $this->_collection->addAttributeToSort('name','desc');
                } 
                /*
            else if(($this->getCurrentOrder()) == 'name','asc') 
                { 
                    $this->_collection->addAttributeToSort('name','asc'); 
                }*/
            else 
                {
                    $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
                }
        }
    return $this;
}

添加它总是在几个指南中重复,可悲的是大多数跳过命名文件夹和文件,但只要注释掉else if (asc)部分,它就可以工作。如何为升序添加第二个名称?

请转到管理面板中的以下路径目录 -> 属性 ->管理属性 -> 在属性代码列下方搜索属性"名称"。单击搜索按钮。单击您的属性名称。然后将"用于产品列表中的排序"选项编辑为"是"。并保存属性。

请参阅下面的屏幕简介。它可能会对您有所帮助。点击这里