Try the Demo

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’;

/**

 Signature 

How to ask questions

 
Magento Community Magento Community
Magento Community
Magento Community
 
vary
Member
 
Total Posts:  60
Joined:  2008-12-15
China,Hongkong
 
Discovery - 01 April 2009 12:51 AM

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
 
kron
Member
 
Total Posts:  64
Joined:  2008-06-12
 

I am on version 1.3.1 and it seems things are different - I just added this to the toolbar.phtml at the top.

$myAvailableOrder = array(
            
'sku'  => $this->__('Sku'),
            
'position'  => $this->__('Best Value'),
            
'name'      => $this->__('Name'),
            
'price'     => $this->__('Price')
        ); 
 
 
$this->setAvailableOrders($myAvailableOrder);

It seems to work for me—there are a bunch of methods you can access in Toolbar.php

PLUS EXTRA BONUS of not having to worry about future upgrades doing it this way...(as long as they keep this functionality the same)

 
Magento Community Magento Community
Magento Community
Magento Community
 
kron
Member
 
Total Posts:  64
Joined:  2008-06-12
 
Cigar Joe - 10 March 2009 11:45 AM

Has anyone figured out how to do a multiple sort?

What exists now

$this->_availableOrder = array(
‘brand’ => $this->__(’Brand’),
‘name’ => $this->__(’Name’),
‘packaged_in’ => $this->__(’Packaged’)
);

$this->setDefaultOrder(’brand’);

What I want to do is:
$this->_availableOrder = array(
‘brand’, ‘name’ => $this->__(’Brand’),
‘name’,’brand’ => $this->__(’Name’),
‘packaged_in’,’brand’,’name’ => $this->__(’Packaged’)
);

$this->setDefaultOrder(’brand’, ‘name.);

This will allow me to get a useable list for the user.

Has anyone had any progress with multiple sort??? I could really use this option for a more in depth sort. Please share

 
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!

 Signature 

How to ask questions

 
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 03: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 01: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
Magento Community
Magento Community
    Back to top