5

By default, I have sorting set to by Name, and when particular categories are selected, it's usually by Price. However, I am not sure how to assign a default sort-by setting when shopping by an option other than category. I have an attribute in my layered nav called "Size" and when that is used as the filter, I would like to sort by Price.

I guess the question then is if there is a way to do this in XML -- first how to call out the proper scope for a shopping option other than category, and second how to change the sort-by setting. I'm guessing though that it's not possible through XML and that I'll have to go deeper, but any advice is appreciated!

grok_in_full
  • 370
  • 3
  • 18

2 Answers2

0

I think you are going to have to override a core file in order to accomplish what you want (don't modify a core file -- override the class by copying it the local code pool or rewriting the class). By default the order is the sort order set in the admin panel. In order to change that you are going to have to modify that logic.

I started by looking in the Mage_Catalog_Block_Layer_Category class. This has a reference to the Mage_Catalog_Model_Layer_Filter_Category class. This class handles getting the categories for the layered navigation.

The function I think you need to look at is _getItemsData(). I think you'll either want to modify the logic for $categories to set the order you want (this is probably the more preferable option) or you may be able to do some custom sorting on the items that get placed into the $data array.

Josh Pennington
  • 6,418
  • 13
  • 60
  • 93
0

go to app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product and open collection.php file and look into the function named as a addAttributeToSort() this function is responsible for sorting attribute, here you can put your logic for sorting and override your file after testing

Mufaddal
  • 5,398
  • 7
  • 42
  • 57