3
votes

I am using following tutorial to display the most sold product sort by option(Filtering) to display on product listing page in magento?

Tutorial

enter image description here

/app/code/local/Mage/Catalog/Model/Resource/Product/collection.php

<?php
public function sortByReview($dir){
 $table = $this->getTable('review/review'); 
 $entity_code_id = Mage::getModel('review/review')->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE);  
 $cond = $this->getConnection()->quoteInto('t2.entity_pk_value = e.entity_id and ','').$this->getConnection()->quoteInto('t2.entity_id = ? ',$entity_code_id); 

 $this->getSelect()->joinLeft(array('t2'=>$table), $cond,array('review' => new Zend_Db_Expr('count(review_id)'))) 
->group('e.entity_id')->order("review $dir"); 
 }
 ?> 

But I want to sort products which are most sold from every category.

How can I do this? Is there any free extension available for this?

1

1 Answers

1
votes

I did the following thing as the client did not want automatically filter most sold product.

I created an attribute "popular" as drop down and give values from 1 to 5.Then marked "Used for Sorting in Product Listing" to Yes.

After this the attribute was visible under sorting options.