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

Page 1 of 11
…set the default sort order for catalog pages? 
 
macsmart
Jr. Member
 
Total Posts:  29
Joined:  2007-08-31
Greensboro, NC
 

How do I set the default sort order for catalog pages?

It looks like the default is “Best Value” and I’d like it to be “name” (Alpha) descending. Is this possible in the current release?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
macsmart
Jr. Member
 
Total Posts:  29
Joined:  2007-08-31
Greensboro, NC
 

nobody?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@macsmart: it’s not configurable from admin yet, take a look in app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php function getCurrentOrder() - it will take the first available. So you can either change this method or change available orders on line 41

 
Magento Community Magento Community
Magento Community
Magento Community
 
macsmart
Jr. Member
 
Total Posts:  29
Joined:  2007-08-31
Greensboro, NC
 

Perfect!

Here’s what I did, in case anyone else is interested:

in Toolbar,php, (near line 40) I changed this:

$this->_availableOrder = array('position'=>__('Best Value'), 'name'=>'Name''price'=>__('Price'));

to this:

$this->_availableOrder = array('name'=>'Name''position'=>__('Best Value'), 'price'=>__('Price'));

Thanks again, Moshe!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hadifarnoud
Sr. Member
 
Total Posts:  210
Joined:  2007-10-07
Guildford, Surrey, UK
 

oh, this really helped me,it would be great if we can add more Order fiter and Set default for those

 
Magento Community Magento Community
Magento Community
Magento Community
 
woodz51
Jr. Member
 
Total Posts:  6
Joined:  2008-05-11
 

worked like a charm!

 
Magento Community Magento Community
Magento Community
Magento Community
 
WisdOMbooks
Sr. Member
 
Avatar
Total Posts:  144
Joined:  2007-08-31
Kolkata (Calcutta) - INDIA
 

I have got rid of the Best Value ,
which I can’t understand much, in any case…
for ex.: what does it mean its code name position ? and
what is the VALUE it’s talking about:
money value? convenience?? ethics ???  tongue laugh

In the same place, app / code / core / Mage / Catalog / Block / Product / List / Toolbar.php,
from this:

$this->_availableOrder = array('name'=>'Name''position'=>__('Best Value'), 'price'=>__('Price'));
I just cut out this:
'position'=>__('Best Value'),
leaving this:
$this->_availableOrder = array('name'=>'NAME''price'=>__('PRICE'));
It works in my front end, but I am not sure if it is a correct practice or
if it may give trouble somewhere, sometimes, later on…

Could some of the code-gurus around here confirm if the above is OK ?

Also, it could be wonderful to be able to add a choice of
DATE , i.e. from newest to oldest and vice-versa.
Anyone would like to suggest the code for this?

As usual…
THANK YOU for your valuable time !

A n g e l o

 
Magento Community Magento Community
Magento Community
Magento Community
 
ptjedi
Sr. Member
 
Avatar
Total Posts:  250
Joined:  2008-03-12
Porto, Portugal
 

Thanks for this piece of code. It helped me! wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
liotropi
Sr. Member
 
Total Posts:  182
Joined:  2008-02-21
Athens, Greece
 

thanks, very useful

however, I have to agree with WisdOMbooks
there should be more options for sorting
price is useful
I would suggest date also (newest)

 
Magento Community Magento Community
Magento Community
Magento Community
 
RPGShop
Sr. Member
 
Total Posts:  143
Joined:  2008-06-16
 

We need things sorted by product entered date since my industry is very front-line driven. So I wen and changed things to this:

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

And that actually worked. It shows products from newest to oldest books in that category. Thank god the default was to show newest to oldest (DESC).

This is definatly an option that should be added.

James
http://www.rpgshop.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
onepack
Sr. Member
 
Total Posts:  98
Joined:  2008-06-02
Amsterdam
 

Moshe, you rock!

 
Magento Community Magento Community
Magento Community
Magento Community
 
RPGShop
Sr. Member
 
Total Posts:  143
Joined:  2008-06-16
 
RPGShop - 16 June 2008 07:39 PM

We need things sorted by product entered date since my industry is very front-line driven. So I wen and changed things to this:

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

And that actually worked. It shows products from newest to oldest books in that category. Thank god the default was to show newest to oldest (DESC).

I was wrong, I think the default is ASC… how do I change the default for Newest to be DESC?  I see a function to getCurrentDirection() but not sure that’ll help. How do I set it to ‘desc’ to start with on each page?

 
Magento Community Magento Community
Magento Community
Magento Community
 
bkmacdaddy
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2008-04-04
Honolulu, HI
 
RPGShop - 21 June 2008 01:12 AM

I was wrong, I think the default is ASC… how do I change the default for Newest to be DESC?  I see a function to getCurrentDirection() but not sure that’ll help. How do I set it to ‘desc’ to start with on each page?

Figured it out: in the same toolbar.php file, around lines 101-110, change this:

public function getCurrentDirection()
{
if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) {
$dir = strtolower($dir);
if (in_array($dir, array(’desc’, ‘asc’))) {
return $dir;
}
}
return ‘asc’;
}

To this:

public function getCurrentDirection()
{
if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) {
$dir = strtolower($dir);
if (in_array($dir, array(’desc’, ‘asc’))) {
return $dir;
}
}
return ‘desc’;
}

Along with your ‘newest’ entity_id it works like a charm!

 
Magento Community Magento Community
Magento Community
Magento Community
 
basty
Jr. Member
 
Total Posts:  16
Joined:  2008-08-10
North-Germany
 

Thanks a lot! (Can somebody add this hack to the wishlist? It would be better if you can configure this sort-options in the shop-settings)

 
Magento Community Magento Community
Magento Community
Magento Community
 
vlad.ifrim
Jr. Member
 
Total Posts:  3
Joined:  2008-06-17
 

in case someone finds this useful (I know how frustrating magento can get) this is what I had to do:
- I had to sort the products alphabetically in “sort by manufacturer” mode; this means I had to have products sorted after two fields: first by manufacturer and then by name;

what I did is change the same file: app / code / core / Mage / Catalog / Block / Product / List / Toolbar.php

at about line 72 I changed this

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

to this:

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

it works just fine.

ofcourse that someone can change the hardcoded value like “asc” to get the current direction with “$this->getCurrentDirection()”; and any other hacks someone may need in its project.

Hope that helped!! Cheers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
eliteeternity
Member
 
Avatar
Total Posts:  74
Joined:  2008-07-16
 

WOOOT! GO MOSHE!!! Just remember to put the “,” marks where they should be if you mess with the syntax. I got a fatal error until my noobness figured out I didn’t have a “,” where it should have been.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 11