1

I have an issue with layered navigation filter count. I have changed the product collection of sort, everything is working fine except the product count. Can anyone help.

Toolbar.php

class Andrw_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{
    public function setCollection($collection)
    {
    parent::setCollection($collection);

    if ($this->getCurrentOrder()) {
        //echo $this->getCurrentOrder();
        if($this->getCurrentOrder() == 'price_desc') {
            $this->_collection->setOrder('price','DESC')->getSelect();

        }
        if($this->getCurrentOrder() == 'price_asc') {
            $this->_collection->setOrder('price','ASC')->getSelect();

        }
        if($this->getCurrentOrder() == 'position') {//'relevance'

            $this->_collection->getSelect()
            ->joinLeft(
                array('sfoi' => $this->_collection->getResource()->getTable('sales/order_item')),
                'e.entity_id = sfoi.product_id',
                array('qty_ordered' => new Zend_Db_Expr('SUM(sfoi.qty_ordered)'))
                )
            ->joinLeft(
                array('si' => $this->_collection->getResource()->getTable('cataloginventory_stock_item')),
                'si.product_id = e.entity_id',
                array('instock' => 'si.is_in_stock')
                )
            ->joinLeft(
                array('_table_views' => $this->_collection->getResource()->getTable('report_viewed_product_aggregated_monthly')),
                '_table_views.product_id = e.entity_id',
                array('views' => new Zend_Db_Expr('SUM(_table_views.views_num)'))
                )
            ->group('e.entity_id')
            ->order(array('instock DESC','qty_ordered DESC','views DESC'));

        }
   }
}

Collection.php

class Andrw_Catalog_Model_Resource_Product_Collection extends 
Mage_Catalog_Model_Resource_Product_Collection
{
    protected function _getSelectCountSql($select = null, $resetLeftJoins = true)
  {
   $this->_renderFilters();
   $countSelect = (is_null($select)) ?
       $this->_getClearSelect() :
       $this->_buildClearSelect($select);

   if(count($countSelect->getPart(Zend_Db_Select::GROUP)) > 0) {
       $countSelect->reset(Zend_Db_Select::GROUP);
   }

   $countSelect->columns('COUNT(DISTINCT e.entity_id)');
   if ($resetLeftJoins) {
       $countSelect->resetJoinLeft();
   }
   return $countSelect;
}
}
  • can anyone help me to solve this – Dalbin Shimy May 26 '18 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.