cancel
Showing results for 
Search instead for 
Did you mean: 

Changing 'Default Product Listing Sort By' default sort order for a custom attribute

Changing 'Default Product Listing Sort By' default sort order for a custom attribute

Hi guys,

 

I have a custom attribute called Select Photographer which appears in the category display settings area like so:

 

 

It allows users to use the Sort By to Group Photographers By Name A-Z or Group Photographers By Name Z-A in the front end.

 

 

Unfortunately, when selected as the default, it seems to auto sort by DSC. I'm not sure why this is the case, as this was put in by some freelancers who I have since parted ways with.

 

I have searched endlessly to try and find the responsible code for this, but can't find it anywhere. I'm thus wondering the best way to make this attribute default sort in the other direction ? Perhaps I should put an If statement in app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php which says if the attribute is this, default sort by ASC?

 

public function setDefaultDirection($dir)
{
if (in_array(strtolower($dir), array('asc', 'desc'))) {
$this->_direction = strtolower($dir);
}
return $this;

 

The problem is, I don't want to affect the Sort By Group By Photographer options on the front end, only when this attribute is set via the back end. I also only want the change in sort order to occur for this attribute.

 

I have also tried simply making Group by Photographer A-Z option selected via the HTML, but that doesn't work either. Though, if there was a way to disable Magento's default sort by, it could be a viable work around.

 

Any help is much appreciated! Thanks

1 REPLY 1

Re: Changing 'Default Product Listing Sort By' default sort order for a custom attribute

Hi @webjing0

 

 

For your requirement you need to change the code into this file:

Magento Root -> App -> Design -> Frontend -> [YOUR THEME] ->template-> Catalog -> Product -> List -> Toolbar.phtml

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now