Try the Demo

Magento Forum

   
Page 1 of 3
Product listing sort by
 
umpa
Jr. Member
 
Total Posts:  7
Joined:  2009-03-06
 

Product listing sort by - how can I easy change it in new version?
I see Toolbar.php have changed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MikeL117
Jr. Member
 
Total Posts:  8
Joined:  2009-03-01
 

Set default sort method in:

Admin>System>Configuration>Catalog>Frontend>"Product listing sort by”

Set allowable sort methods in:
Admin>Catalog>Attributes>Manage Attributes>Properties>Frontend Properties>"Used for sorting in product listing”

Any that are set to “yes” in this field are allowed attributes to sort by.

Unfortunately it makes it rather more difficult to put other properties into the list that are not simple attributes.

It is simpler to use and quite flexible and I’m sure someone will find the bit of code to add to put other stuff in there. If you have modified toolbar.php for an earlier version you need to either re[place it with the new one or remove it from local. The previous methods no longer work.

Hope this helps
Mike

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

this is a nice fix magento team!
But why not take it just one step further? how do we set wether we want it to sort desc or asc default?

anybody found the cleanest fix? to allow for a default asc or desc?

 
Magento Community Magento Community
Magento Community
Magento Community
 
GuyGadbois
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2008-12-04
 

I prefer to use date (created_at) as default, tried lots of stuff including messing around with catalog.xml but ended up with this (temporary) solution. Also hard coded sort options in the array. It’s not perfect but anyway…

(replace Extension with appr. name)

app/etc/modules/Extension_Catalog.xml

<?xml version="1.0"?>
<config>
     <
modules>
        <
Extension_Catalog>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Extension_Catalog>
     </
modules>
</
config>

app/code/local/Extension/Catalog/etc/config.xml

<?xml version="1.0"?>

<config>
   <
modules>
      <
Extension_Catalog>
         <
version>0.1.0</version>
      </
Extension_Catalog>
   </
modules>
   <global>
      <
blocks>
         <
catalog>
             <
rewrite>
               <
product_list_toolbar>Extension_Catalog_Block_Product_List_Toolbar</product_list_toolbar>
            </
rewrite>
         </
catalog>
      </
blocks>
   </global>
</
config>

app/code/local/Extension/Catalog/Block/Product/List/Toolbar.php

<?php
class Extension_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{

    
public function getAvailableOrders()
    
{
        
// return $this->_availableOrder;
        
        
$t = array(
            
'created_at'     => $this->__('Date'),                // sort by Date option (default)
//            'position'      => $this->__('Best Value'),
            
'name'          => $this->__('Name'),
            
'price'         => $this->__('Price')
        );
        
        return 
$t;
    
}

    
public function setDefaultOrder($field)
    
{
//        if (isset($this->_availableOrder[$field])) {
//            $this->_orderField = $field;
//        }

        
$this->_orderField 'created_at';
        
        return 
$this;
    
}

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

        
$this->_direction 'desc';

        return 
$this;
    
}    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
rtgr
Jr. Member
 
Total Posts:  12
Joined:  2008-11-20
 

Why don’t do something like :

<?php
class Extension_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{

    
public function getAvailableOrders()
    
{
        
// return $this->_availableOrder;
        
        
$t = array(
            
'created_at'     => $this->__('Date'),                // sort by Date option (default)
//            'position'      => $this->__('Best Value'),
            
'name'          => $this->__('Name'),
            
'price'         => $this->__('Price')
        );
        
        
$statement true;

        if(
$statement)
        
{

          $this
->_orderField 'created_at';
          
$this->_direction 'desc';
        
}


        
return $t;
    
}


}

seems to work for me, but i only need to change the default sort on a certain category, so i have an if-statement in getAvailableOrders()

 Signature 

MediaCT

 
Magento Community Magento Community
Magento Community
Magento Community
 
kerry
Jr. Member
 
Avatar
Total Posts:  11
Joined:  2007-12-26
Texas
 
MikeL117 - 31 March 2009 07:25 AM

Set default sort method in:

Admin>System>Configuration>Catalog>Frontend>"Product listing sort by”

Set allowable sort methods in:
Admin>Catalog>Attributes>Manage Attributes>Properties>Frontend Properties>"Used for sorting in product listing”

Any that are set to “yes” in this field are allowed attributes to sort by.

Mike, there is no menu ...>Properties>Frontend Properties>"Used for sorting in product listing” - see attached screenshot. What do you mean?

TIA,
Kerry

Image Attachments
magento-manage-attributes-screen.png
 Signature 

http://www.osCommerceManuals.com
http://www.PithyProductions.com
http://www.KerryWatson.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
moki
Jr. Member
 
Total Posts:  18
Joined:  2008-03-22
 

The option is at the bottom of the “Edit Attribute” page, see attached screen shot.

My problem is that I can’t select my previously created attributes as sortable options.  The dropdown menu is just greyed out (see attached screen shot).  Anyone have any ideas about that?

Thanks!

Image Attachments
Picture 2.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
kamrool
Jr. Member
 
Total Posts:  1
Joined:  2009-04-03
 

·GuyGadbois
I am also wanna sort by date, and I was following the detail about above , But It did not work out, Can anyone tell me what to do, the Toolbar.php, can you show full codes in it ?

Thanks a lot
Kamrool

 
Magento Community Magento Community
Magento Community
Magento Community
 
john-michael
Jr. Member
 
Total Posts:  22
Joined:  2009-03-05
 

GuyGadbois,

Like kamrool, the solution you provided didn’t work for me either. I’m using 1.3.1. Any suggestions?

EDIT: I take that back, the solution above works fine for 1.3.1.

 Signature 

JM.

Blacklisted Cards
Real Job Descriptions
Funny Ass Blog

 
Magento Community Magento Community
Magento Community
Magento Community
 
Boa1969
Jr. Member
 
Total Posts:  6
Joined:  2009-03-11
 

This isn’t working for me at all.  I think something is over riding the settings somewhere.  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
 
NicholasMorris
Member
 
Total Posts:  51
Joined:  2009-04-06
 

Hi there,
Going by MikeL117’s comments, i can see how to change that, but I’m actually looking for a way to order by the ID number rather than sku. Is there a way to do this is 1.31?
Thanks
Nic

 
Magento Community Magento Community
Magento Community
Magento Community
 
MikeL117
Jr. Member
 
Total Posts:  8
Joined:  2009-03-01
 

Hi All

Sorry so slow responding, I had forgotten I had left this post (in fact, I had completely forgotten what the method was until I stumbled across this thread when trying to implement it in my live store ohh  ).

Just to clarify the process:

In Admin select Manage Attributes from the menu. then from the list of attributes edit the one you want to add to the list of available sort orders. At the bottom of the page (in 1.3.1) in the Frontend Properties section there is a drop-down box labelled “Used for sorting in product listing” with Yes/No options. Select Yes then go to the “Manage Label/Options” tab and add the name you wan the users to see in the correct views.
Finally go to System>Configuration and find the Catalog tab, in the Frontend section there is a drop-down box called “Product listing sort by” where you can select the default setting for the catalog listings.

To change the default direction I hacked (a local copy of) the Toolbar.php file by changing ‘asc’ to ‘desc’ in line 97

/ * Default direction
     
*
     * @var 
string
     
*/
    protected 
$_direction           'desc';

The solutions provided by Guy and rtgr above look to be rather better in the long term.

If you prefer to not mess with core code (even a local copy of) then you can hack your local template version of Toolbar.phtml with something like this (about line 95)

<!-- set desc for Special Price and New -->
                
<?php if($_key == 'news_from_date'): ?>
                    
<option value="<?php echo $this->getOrderUrl($_key, 'desc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                
<?php else: ?>
                    
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                
<?php endif; ?>

@moki
Sorry I can’t see why your option is greyed out.

@Boa1969
My method above sorts by news_from_date with version 1.3.1 (I had too many problems with 1.3.0). Unfortunately at the moment there is no easy way to sort by two properties.

@OverloadWeb
Since the introduction of this improved method in version 1.3 there is not an easy way to sort by other attributes than the standard produce attributes, unless yo wan to expand on the above methods by Guy and rtgr. You would have to look at the available properties for Product ID and try to persuade Magento to use it.
A pragmatic workaround (assuming you don’t already have thousands of existing products) would be to make another product attribute and copy the Product ID into that. Crude but may be a way out for now.

Thanks for the ideas a simple extension may be the way, if only I could find the time to write one.  LOL

Mike

Image Attachments
MagentoSort1.jpgMagentoSort2.jpgMagentoSort3.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
NicholasMorris
Member
 
Total Posts:  51
Joined:  2009-04-06
 

hey Mike!
Thanks for that!!!  I did end up taking the easy way out - my client was happy for me to change the SKU number so i did that instead.  But i appreciate your response!
Cheers
Nic

 
Magento Community Magento Community
Magento Community
Magento Community
 
viditech
Jr. Member
 
Total Posts:  7
Joined:  2008-08-27
 

moki - The “Used for sorting in product listing” property is grayed out for me as well and states “depends on design theme” after the drop box.  Were you able to find out how to enable this function?  Thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hugoto
Member
 
Avatar
Total Posts:  33
Joined:  2008-08-11
 
GuyGadbois - 01 April 2009 09:17 AM

I prefer to use date (created_at) as default, tried lots of stuff including messing around with catalog.xml but ended up with this (temporary) solution. Also hard coded sort options in the array. It’s not perfect but anyway…

(replace Extension with appr. name)

app/etc/modules/Extension_Catalog.xml

<?xml version="1.0"?>
<config>
     <
modules>
        <
Extension_Catalog>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Extension_Catalog>
     </
modules>
</
config>

app/code/local/Extension/Catalog/etc/config.xml

<?xml version="1.0"?>

<config>
   <
modules>
      <
Extension_Catalog>
         <
version>0.1.0</version>
      </
Extension_Catalog>
   </
modules>
   <global>
      <
blocks>
         <
catalog>
             <
rewrite>
               <
product_list_toolbar>Extension_Catalog_Block_Product_List_Toolbar</product_list_toolbar>
            </
rewrite>
         </
catalog>
      </
blocks>
   </global>
</
config>

app/code/local/Extension/Catalog/Block/Product/List/Toolbar.php

<?php
class Extension_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{

    
public function getAvailableOrders()
    
{
        
// return $this->_availableOrder;
        
        
$t = array(
            
'created_at'     => $this->__('Date'),                // sort by Date option (default)
//            'position'      => $this->__('Best Value'),
            
'name'          => $this->__('Name'),
            
'price'         => $this->__('Price')
        );
        
        return 
$t;
    
}

    
public function setDefaultOrder($field)
    
{
//        if (isset($this->_availableOrder[$field])) {
//            $this->_orderField = $field;
//        }

        
$this->_orderField 'created_at';
        
        return 
$this;
    
}

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

        
$this->_direction 'desc';

        return 
$this;
    
}    
}

Thank youuuuuuuuu!!!!

Im really really really disappointed with magento.... here in my company we’re moving to virtuemart! think about it

 
Magento Community Magento Community
Magento Community
Magento Community
 
Loic_LC
Sr. Member
 
Avatar
Total Posts:  194
Joined:  2007-12-19
Paris, France
 

Thank you GuyGadbois
worked fine for me.
Hope you’ll tell us if you find a better solution.

Thnkas again

 Signature 

Essential modules : Enhanced grid / Mass Product Relater/ Fooman Speedster / PDF Customiser / Simple order export

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