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? 
 
SG1
Jr. Member
 
Total Posts:  8
Joined:  2009-07-27
 

Thanks for all comments, the most of them help me a lot.

I would like to know if I could create a new atribute (Backend) and then use that attribute to order the products, hope I’ll be able to… in the meantime I will try by myself, if I find out a solution, I’ll post it here.

Regards.

 
Magento Community Magento Community
Magento Community
Magento Community
 
akamyself
Jr. Member
 
Total Posts:  14
Joined:  2008-08-15
 
akamyself - 03 August 2009 05:01 AM

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

For what it’s worth, tried the ‘best value’ sorting and it equals sorting by position.

Go figure…

 
Magento Community Magento Community
Magento Community
Magento Community
 
SG1
Jr. Member
 
Total Posts:  8
Joined:  2009-07-27
 
SG1 - 07 August 2009 12:52 AM

Thanks for all comments, the most of them help me a lot.

I would like to know if I could create a new atribute (Backend) and then use that attribute to order the products, hope I’ll be able to… in the meantime I will try by myself, if I find out a solution, I’ll post it here.


Regards.

Yes!!, it’s possible to create a new “attribute”, assign it to one or more “attribute set” and then order product list by that new attribute.  (Magento v1.1.7)

I created a new atrributed called “product_position” through Backend and I did the following modifications in a file: (yes, I know it’s hard coded but it’s only a test)

Modified File: DOCUMENT_ROOT\app\code\core\Mage\Catalog\Block\Product\List.php

Code modified: I just added two new methods in the class: Mage_Catalog_Block_Product_List (hard coded):

/**/
    public function getSortBy(){
    
        
return "product_position";
    
    
}
    
    
/**/
    
public function getSortOrder(){
    
        
return "desc";
    
    
}

The next step is to abstract my modifications in order not to hack the code and keep it just in case I upgrade to a new Magento Version , but I don’t know how to (I’m a noob in Magento), any ideas, suggestions or improvements are welcome.

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

hi there, is there anybody who every change its product list ?
at app/code/core/Mage/Catalog/Block/Product/List.php, change its _getProductCollection function ??

what I’m doing now is show A-Z products, so I change the code but there still many problems remains. One of them is sort problem, is there anyone who got the same issue ?

my code in _getProductCollection function :

if (is_null($this->_productCollection)) {
            $alphabet 
$this->getRequest()->getParam('key');
            
            
$toolbar $this->getToolbar();
            
$pageVarName $toolbar->getPageVarName();
            
$page $this->getRequest()->getParam($pageVarName);
            
            
$order $toolbar->getCurrentOrder();
            
$dir $toolbar->getCurrentDirection();
            
            
$collection Mage::getResourceModel('catalog/product_collection')
                ->
addAttributeToFilter('name', array('like'=> $alphabet.'%'))
                ->
addAttributeToFilter('status', array('enable' => true))
                ->
setCurPage($toolbar->getCurrentPage())
                ;
        
            
$attributes Mage::getSingleton('catalog/config')->getProductAttributes();
            
$collection->addAttributeToSelect($attributes);
            
            if ((int) 
$limit $toolbar->getLimit()) {
                $collection
->setPageSize($limit);
            
}
            
            
// this SETORDER STILL GOT LITTLE PROBLEM
            //if ($order) {
            //    $collection->setOrder($order, $dir);
            //} 
            
            
$collection->load();
            
$this->_productCollection $collection;

please give me your advice ....

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

still waiting for nice suggestion of what I’m doing....

 
Magento Community Magento Community
Magento Community
Magento Community
 
carolsancos
Jr. Member
 
Total Posts:  5
Joined:  2008-11-23
 

Thank you vlad.ifrim!! I spent hours looking for that

 
Magento Community Magento Community
Magento Community
Magento Community
 
E9
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2009-04-25
 

Well, i wanted to thank you for this tip, but i tried to open the file and search for the string to replace it but i could not find it.
i dono if the magento ver. makes a difference
mine is: 1.3.2.3
is there any other way please?
or can i pay someone to fix this for me?

thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
scjunkies
Member
 
Total Posts:  55
Joined:  2008-09-03
Houston, Texas, USA
 
E9 - 23 September 2009 01:42 AM

Well, i wanted to thank you for this tip, but i tried to open the file and search for the string to replace it but i could not find it.
i dono if the magento ver. makes a difference
mine is: 1.3.2.3
is there any other way please?
or can i pay someone to fix this for me?

thank you

Did you get anyone to help you?  I want to display random products on the category list.  However, the Hack listed above does not seem to apply to version 1.3.2.4.  Can anyone help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
E9
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2009-04-25
 

Well so far no one replied yet

but i submitted the request to one of the companies that i bought some plugins from
and i hope that they reply soon

i will keep you posted here in case they replied to me

mean while, have a look at their plugins it is really good to have and use

its here:

http://www.hello-magento.com/extensions-modules-plugins/

if you wanted to buy any of them, just refer my domain: q8shop.biz

they are really a good team of support

thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
E9
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2009-04-25
 

I finally got the reply from the Support team @ http://www.hello-magento.com/

and this was their answer:
____________________

Could you use the code in the content of cms home page:

{{block type="newproducts/newproductstoolbar" number_day="300" name="newproducts_simpletoolbar"
template="hm/newproducts_simpletoolbar.phtml" }}

The number_day =300 it means it will list products in last 300days and sort by date.

_____________________

and it works for my website:  http://www.q8shop.biz

you may have a look

 
Magento Community Magento Community
Magento Community
Magento Community
 
scjunkies
Member
 
Total Posts:  55
Joined:  2008-09-03
Houston, Texas, USA
 

E9 Thanks for the reply but what you posted did not help me. I’m looking to list the products in a category randomly. There was a solution for that in this post on page 2 i think. However, with the upgrade to 1.3.2.x it no longer works.  Better stated, I don’t know how to implement it due to the change in the core files.

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcm1
Jr. Member
 
Total Posts:  6
Joined:  2009-02-26
 

I need to sort price descending. I changed it to price in admin.

I changed line 97 in Toolbar.php to:

protected $_direction = ‘desc’;

(instead of asc)

Worked nicely.

Thanks for all the previous posts.

 
Magento Community Magento Community
Magento Community
Magento Community
 
wrist watches
Jr. Member
 
Total Posts:  8
Joined:  2009-10-25
London, UK
 
bkmacdaddy - 30 June 2008 07:45 PM

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!

Worked a treat for me to.....many thanks.....

 
Magento Community Magento Community
Magento Community
Magento Community
 
MattBlalock
Jr. Member
 
Total Posts:  20
Joined:  2009-03-29
 

I’m using Magento version 1.3.2.2 and the code is very different, looks like some serious Session integration was implemented.

It is still possible to make this change there though. Just scan the document, around line 98 change asc to desc and bam!

Works like a charm!

 
Magento Community Magento Community
Magento Community
Magento Community
 
benz001
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2009-02-05
Sydney
 

As CK hinted at earlier, much of this can now be done ‘simply’ through the layout XML.
If you only want to change default sort order you can do it in catalog.xml just by adding the following action:

<action method="setDefaultDirection"><dir>desc</dir></action>

This action will work in any block of type “catalog/product_list_toolbar”, so the XML snippet would be:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
        <
action method="setDefaultDirection"><dir>desc</dir></action>
    <!-- 
The following code shows how to set your own pager increments -->
    <!--
        <
action method="setDefaultListPerPage"><limit>4</limit></action>
        <
action method="setDefaultGridPerPage"><limit>9</limit></action>
        <
action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
        <
action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
        <
action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
        <
action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
        <
action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
    -->
</
block>

This block is used twice in catalog.xml once for normal product lists and once for layered navigation product lists, so just make the same change in both places.

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