Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

…set the default sort order for catalog pages? 
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

A small note:

If you just want to change the order from asc to desc, the posts earlier in this thread have changed with 1.3 coming out.

In /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php change line 97 so it looks like:

/**
* Default direction
*
* @var string
*/
protected $_direction = ‘desc’;

/**

 
Magento Community Magento Community
Magento Community
Magento Community
 
vary
Member
 
Total Posts:  60
Joined:  2008-12-15
China,Hongkong
 
Discovery - 31 March 2009 11:51 PM

A small note:

If you just want to change the order from asc to desc, the posts earlier in this thread have changed with 1.3 coming out.

In /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php change line 97 so it looks like:

/**
* Default direction
*
* @var string
*/
protected $_direction = ‘desc’;

/**

I changed code with your method,but no effect,it’s still show sorts as before. (1.3 version)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Discovery
Enthusiast
 
Total Posts:  767
Joined:  2007-12-29
 

@vary I just found my above tip and it does work fine. Remember to check your cache is disabled before posting to Magento forums!

 
Magento Community Magento Community
Magento Community
Magento Community
 
andietheke
Member
 
Total Posts:  40
Joined:  2008-07-14
 

To edit the standard given sort by “position” I changed /app/code/core/Mage/Catalog/Model/Config.php lines 296ff:

public function getAttributeUsedForSortByArray()
{
$options = array(

====>>>>>THIS LINE MUST BE CHANGED TO YOUR STANDARD

(line 299) ‘position’ => Mage::helper(’catalog’)->__(’Position’)
<<<<<<<<================
);
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
$options[$attribute[’attribute_code’]] = Mage::helper(’catalog’)->__($attribute[’frontend_label’]);
}

return $options;
}

I changed it to
‘name’ => Mage::helper(’catalog’)->__(’name’)
because the client want the products sorted by name ^^
Anyone a better way by setting it up in the backoffice?

 
Magento Community Magento Community
Magento Community
Magento Community
 
fragilem17
Member
 
Total Posts:  56
Joined:  2009-02-15
 

@above ... in version 3.1 you can set the default sort in the backend..

I’m also looking for an option to sort on multiple fields.
not just sorted on price, but on price and a custom attribute used for sorting.

Any idea on how to handle this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
fragilem17
Member
 
Total Posts:  56
Joined:  2009-02-15
 

solution to multiplesorting ! using magento1.3.0

notice that I dont let the user sort the data, i’ve disabled/removed the dropdown in the phtml..
don’t think the default sorting can be changed after this mod and this could be overwritten when updating magento to a newer version.
this is by all means a quick hack and defenitly not the way to go grin

open up:
\app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

change line 159 in the method “setCollection” where you can find

$this->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());

info

$this->getCollection()->setOrder('sell_type''DESC'); // sell_type is a custom attribute i want to sort on
$this->getCollection()->setOrder('price''ASC');
// second param i want to sort on
 
Magento Community Magento Community
Magento Community
Magento Community
 
Boa1969
Jr. Member
 
Total Posts:  6
Joined:  2009-03-11
 

OK, I am officially lost.  I got all my new products on my main page, and I increased the number that show up to the amount I wanted, but I just can’t seem to get them to sort properly.

I would like them to sort on news_from_date and then alphabetically after that (for products that have the same news_from_date entry). 

They seem to be sorting by entity_id and from oldest to newest order.

I am really not much of a coder (a little html, shell, perl, php), and I have gone crosseyed reading forums trying to fix this.  I have tried many different methods mentioned in the forums, to no avail.

Can anyone please point me in the right (very specific) direction?  You can even point and call me n00b, if you want… grin

Running 1.3.0
Grunge Theme from magthemes.com
Zblocks
color views plus
Manage Products (Enhanced)
GoDaddy.com deluxe hosting plan

Boa1969
http://www.worldofstrange.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rodiney
Jr. Member
 
Total Posts:  3
Joined:  2008-11-14
 

Hello guys,

Someone have this solution?

$this->_availableOrder = array(
‘visited’ => $this->__(’produtct+morevisited’),
‘saleschampiom’ => $this->__(’Product+more+sale’),

‘name’ => $this->__(’Name’),
‘price’ => $this->__(’Price’)
);

Whats the correct variables on the 2 first fieds???

 
Magento Community Magento Community
Magento Community
Magento Community
 
Schnix
Jr. Member
 
Total Posts:  16
Joined:  2009-03-02
 
fragilem17 - 13 May 2009 02:26 AM

solution to multiplesorting ! using magento1.3.0

notice that I dont let the user sort the data, i’ve disabled/removed the dropdown in the phtml..
don’t think the default sorting can be changed after this mod and this could be overwritten when updating magento to a newer version.
this is by all means a quick hack and defenitly not the way to go grin

open up:
\app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

change line 159 in the method “setCollection” where you can find

$this->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());

info

$this->getCollection()->setOrder('sell_type''DESC'); // sell_type is a custom attribute i want to sort on
$this->getCollection()->setOrder('price''ASC');
// second param i want to sort on

i have 1.3.x and changed function getCurrentOrder()

at the end it says
return $keys[0];

so no matter what you selected in system config, it will sort by [0:"relevance”,1:"name”,2:"price"]

so i simply return return $keys[2];

thats it, hard coded until magento solves this for me....

schnix

 
Magento Community Magento Community
Magento Community
Magento Community
 
Schnix
Jr. Member
 
Total Posts:  16
Joined:  2009-03-02
 

i still have the problem that this solution only works for advanced search and category listings, but not for quick search.

i tried to change setListOrders in /catalogsearch/block/result.php to accept price order.
now the select box at the quick search page is set to price, but it is not sorted by price :(

getCurrentOrder from the toolbar.php is called from that page, but it simply does not affect the order…

any suggestions how to order quick search results by price?

greetings
schnix

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rodiney
Jr. Member
 
Total Posts:  3
Joined:  2008-11-14
 

Schinx, run a Layered Navigation Indices script, on ADmin - Cache Management.
Works for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
CK Rock
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2008-06-11
 

For those of you who don’t want to alter the core code, but want to sort by one of the default Magento sort options (like “name") adding this to the /app/design/frontend/default/[theme]/layout/catalog.xml file seems to work:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
    <!-- 
Add this line -->
    <
action method="setDefaultOrder"><field>name</field></action>
    <!--
    ...
    -->
</
block>

This would make your code “upgrade-proof”.  Feel free to correct this if it’s wrong.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hugoto
Member
 
Avatar
Total Posts:  33
Joined:  2008-08-11
 
fragilem17 - 13 May 2009 12:49 AM

@above ... in version 3.1 you can set the default sort in the backend..

Hi Where is that option?

Thnks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hugoto
Member
 
Avatar
Total Posts:  33
Joined:  2008-08-11
 
Hugoto - 22 July 2009 11:59 AM

fragilem17 - 13 May 2009 12:49 AM
@above ... in version 3.1 you can set the default sort in the backend..

Hi Where is that option?

Thnks

Founded:  System > Configuration > Catalog > Frontend > Product listing sort by

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
akamyself
Jr. Member
 
Total Posts:  14
Joined:  2008-08-15
 

With 1.3.2.1 it’s really weird that articles can be sorted by position, name or price in the frontend while by best value, name or price in the backend…

I just want to have my categories sorted by position but previous solutions posted here does not seem to work anymore, I searched the toolbar.php but couldn’t find a line about the default sorting.

Anyone knows how to do this in these last versions of magento ?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top