Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 添加一个新的“;按“排序”;在Magento 1.9中_Php_Sorting_Magento - Fatal编程技术网

Php 添加一个新的“;按“排序”;在Magento 1.9中

Php 添加一个新的“;按“排序”;在Magento 1.9中,php,sorting,magento,Php,Sorting,Magento,实际上,我们只需要按名称升序和降序排序。 我的atribute是“name”,所以我在/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php中这样做了: public function setCollection($collection) { $this->_collection = $collection; $this->_collection->setCurPage($this->getC

实际上,我们只需要按名称升序和降序排序。 我的atribute是“name”,所以我在
/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)
部分,它就会起作用。
如何为升序添加第二个名称?

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


请参阅下面的屏幕。这可能会对你有所帮助。

你能进一步解释一下你想做的逻辑吗?实际上。。。我不能。我们负责这一部分的人被流放了,我不知道我在做什么!但我摸索着前进了一步。在Catalog/manage Atributes下,我将名称重命名为Ascending,并创建了另一个名为Descending的属性。在将这些代码写入上面的代码后,Magento开始工作!