2015-12-23 28 views
0

我已經在管理面板的每個類別中排序產品。它在前端不起作用,但在主頁中一切正常。我檢查了這個鏈接,我想知道如何使它強制排序按位置STACK QUE類別產品排序除主頁外無效

我也指的是在網格視圖相同的list.phtml。誰能幫我?謝謝!

回答

0

以防萬一有人碰到相同的錯誤。這是我設法使它工作的解決方案。首先,你需要的Toolbar.php從法師核心用下面的代碼複製並粘貼在當地法師游泳池和發現功能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; 
} 
0

要通過下面的代碼位置寫排序創建獲得產品收集應用程序/設計/前端//默認/模板/目錄/產品後/ 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); 
    } 
} 

希望它會爲你工作。

相關問題