71759

How to add Rating to sort list in Magento 1.7

Looking for some help adding sort by Rating in Magento. I have added code snippets to toolbar.php which seem to add the sort by Rating but when trying to select it, it gets stuck until I reload the page. Any help would be greatly appreciated. Code can be found below: This is the Toolbar.php file.

// Begin new Code

$this->getCollection()->joinField('rating', 'review/review_aggregate', 'rating_summary', 'entity_pk_value=entity_id', '{{table}}.store_id=1', 'left'); // End new Code

AND

// Add rating to "Sort by"

$_availableOrder = $this->_availableOrder; $_availableOrder['rating'] = 'Rating'; return $_availableOrder; $this->_availableOrder = array( ‘rating_summary’ => Mage::helper(’catalog’)->__(’Rating’), ‘price’ => Mage::helper(’catalog’)->__(’Price’), ‘newest’ => Mage::helper(’catalog’)->__(’Newest’), ‘name’ => Mage::helper(’catalog’)->__(’Name’) );

Answer1:

Best is to make this in a module but here you go:

First we shall alter the way products are retrieved from the database, to include the overall rating (shown as the number of stars on the product) along with the rest of the product attributes. Copy the file app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php and open it for editing.

In the new List.php file find the following line (around line 86):

$this->_productCollection = $layer->getProductCollection();

After this add the following:

$this->_productCollection->joinField('rating_summary', 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type'=>1, 'store_id'=> Mage::app()->getStore()->getId()), 'left');

Now we need to add in an option so that the customer can select "Rating" as an attribute to sort by. Copy the file app/code/core/Mage/Catalog/Model/Config.php to app/code/local/Mage/Catalog/Model/Config.php and edit.

In the new Config.php file find the following code (which should start around line 298):

$options = array( 'position' => Mage::helper('catalog')->__('Position') );

Replace with code with:

$options = array( 'position' => Mage::helper('catalog')->__('Position'), 'rating_summary' => Mage::helper('catalog')->__('Rating') );

Now when viewing categories on your website you should have an option of "Rating" in addition to the others. Note that the sort order defaults to ascending so the lowest rated products will be displayed first. The sort order can be changed by the customer by clicking the arrow next to the drop-down box. Aside from this caveat the new sort is fairly easy to implement and extends the usefulness of the ratings.

Credits: https://www.fontis.com.au/blog/sort-products-rating

Recommend

  • How to filter data between two times from hh:mm to hh:mm in mongoDB
  • Elasticsearch result to table
  • How I can populate data in birt report by passing parameters in the URL
  • laravel first0rNew Integrity Constraint Violation
  • Sorting a Directory before Looping Through - PowerShell
  • invalid value in “less” when comparing np.nan in an array
  • Adding to Grid Selection for grid.php file
  • Google Maps API and DynamicMapsEngineLayer: Loop Over Features in the Map
  • why flask sqlalchemy model query does not get newest records?
  • Gulp globbing excluding files then unexcluding not working as described
  • Multiple values for an AND/OR statement
  • Drupal: create a node with employee working hours
  • Magento not sending forgot password emails
  • What is the priceRange parameter for Google Structured Data Reviews?
  • CodeIgniter - Autoload
  • How would i implement an infinite scroll in my DOM
  • Protocol issue connecting Derby by db2 ODBC
  • Cakephp Form Helper
  • Possible race conditions when creating and updating a struct in the same request - coldfusion
  • Are there algorithms for putting a digest into the file being digested?
  • SQL Server 2005, Caches and all that jazz
  • Play Framework nested form errors missing
  • jQuery Slick Slider showing some empty slides
  • Error Processing Request: Mage registry key “_singleton/inchoo_notes/feed_updates” already exists
  • Show records ordered with maximum price first in PHP & MySQL
  • SqlCommand back up Database
  • Find JSON nested nodes using multiple string values
  • Hector: how to query parts of a Composite Type
  • Magento site down due to mysql error General error: 1030 Got error -1 from storage engine
  • converting text file into xml using php?
  • Listbox within Listbox and scrolling trouble in Windows Phone 7 Silverlight
  • Disable Enter in editText android
  • Getting last autonumber in access
  • How to check if every primary key value is being referenced as foreign key in another table
  • python regex in pyparsing
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • Append folder name and increment by 1 using batch script
  • UserPrincipal.Current returns apppool on IIS