0

I already sort the products in every category in the Admin Panel. It doesn't work accordingly in the Frontend but in the Homepage everything is fine. I checked on this link and I want to know how to make it enforce sorting by position STACK QUE

I'm also referring to the same list.phtml in Grid view. Can anyone help me? Thank you!

Community
  • 1
  • 1
KiD Cajes
  • 121
  • 8

2 Answers2

0

Just in case someone bump into the same error. Here is the solution I managed to make it work. First you need to copy the Toolbar.php from the mage core and paste it in the local mage pool and find the the function setCollection and replace it with the following code:

    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;
}
KiD Cajes
  • 121
  • 8
0

To create sort by position write below code after getting product collection in 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);
    }
}

Hope it will work for you.

Manish Kumar
  • 397
  • 3
  • 10