Magento “Recently Viewed Products” Sort Order

Home / Blog / Magento “Recently Viewed Products” Sort Order

For most users, the “recently viewed products” should be ordered based on the last product viewed. Previous versions of Magento had defects filed describing the recently viewed products were being ordered by the index ID, but this has apparently been resolved in the latest versions. The forum post here describes the defect: http://www.magentocommerce.com/boards/viewthread/9752/ .

Well, when helping a recent client, he was running on Enterprise version 1.9, and he was still having the ordering issue. I took a look, and it appears that if the “recently viewed products” widget is on anything but a product view page, the ordering order yasmin will still not work.

The solution that I implemented was to “rewrite” the Mage_Reports_Model_Mysql4_Product_Index_Viewed_Collection class and override it’s setAddedAtOrder() method. The setAddedAtOrder() method adds the added_ad column as the sort order column ONLY if the index table has been joined to the query. This only occurs on the product view page. The overridden method should look as such:

public function setAddedAtOrder($dir = 'desc')
{
    $this->_joinIdxTable();

    $this->getSelect()->order('added_at '.$dir);

    return $this;
}

This ensures that every time we attempt to set the order, it will join the index table appropriately.

Showing 2 comments
  • Ross Kendall

    Thanks for the tip!

  • Pieter Pabst

    Just ran into a Magento 1.4.1 CE shop that displayed the symptoms you describe here. The issue was resolved by applying the overrided method you posted above :-).

    Thanks for sharing!

Leave a Comment