Sorting 除主页外,类别产品排序不起作用

Sorting 除主页外,类别产品排序不起作用,sorting,magento,categories,product,gridview-sorting,Sorting,Magento,Categories,Product,Gridview Sorting,我已经在管理面板中对每个类别的产品进行了排序。它不工作,因此在前端,但在主页上一切都很好。我检查了这个链接,我想知道如何使它强制按位置排序 我还在网格视图中引用相同的list.phtml。有人能帮我吗?谢谢大家! 以防万一有人碰到同样的错误。这是我设法使它工作的解决方案。首先,您需要从mage core复制Toolbar.php并将其粘贴到本地mage池中,然后找到函数setCollection并用以下代码替换它: public function setCollection($colle

我已经在管理面板中对每个类别的产品进行了排序。它不工作,因此在前端,但在主页上一切都很好。我检查了这个链接,我想知道如何使它强制按位置排序


我还在网格视图中引用相同的list.phtml。有人能帮我吗?谢谢大家!

以防万一有人碰到同样的错误。这是我设法使它工作的解决方案。首先,您需要从mage core复制Toolbar.php并将其粘贴到本地mage池中,然后找到函数setCollection并用以下代码替换它:

    public function setCollection($collection)
{
    $this->_collection = $collection;

    $this->_collection->setCurPage($this->getCurrentPage());

    // we need to set pagination only if passed value integer and more that 0
    $limit = (int)$this->getLimit();
    if ($limit) {
        $this->_collection->setPageSize($limit);
    }
     if ($this->getCurrentOrder()) {
      if(($this->getCurrentOrder())=='position'){
          $this->_collection->setOrder('position','asc');
      }
      else {
       $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
      }
    }
    return $this;
}

要创建按位置排序,请在app/design/frontend//default/template/catalog/product/list.phtml中获取产品集合后编写以下代码

$_productCollection = new Varien_Data_Collection();
$sortedCollection = array();
foreach ($_defaultProductCollection as $key => $_product) {
    if(!isset($sortedCollection[$positions[$_product->getId()]])){
        $sortedCollection[$positions[$_product->getId()]] = array();
    }
    $sortedCollection[$positions[$_product->getId()]][] = $_product;
}
ksort($sortedCollection);
foreach ($sortedCollection as $_products) {
    foreach ($_products as $_product) {
        $_productCollection->addItem($_product);
    }
}
希望它对你有用