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 2 of 11
…set the default sort order for catalog pages? 
 
Thejosh13
Sr. Member
 
Total Posts:  252
Joined:  2008-06-23
 

Its pretty shocking they still have not added such basic features. It makes me wonder what they are doing over there?

They must underestimate the performance effect on our stores of these kind of basic features.

I know the first product in each of my product pages is the most viewed product. If people come back a 2nd time I want to show them something different.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

Maybe someone will need it so I decide to put:

To get listed category products in Random way I changed Toolbar.php

and add random field (note I’ve add it first to make it by default)

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

also we need to catch the moment it start to sort to provide it:
at function setCollection()
change from this:

public function setCollection($collection)
    
{
        parent
::setCollection($collection);
        if (
$this->getCurrentOrder()) {
            $this
->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        
}
        
return $this;
    
}
to this:
public function setCollection($collection)
    
{
        parent
::setCollection($collection);
        if (
$this->getCurrentOrder()) {
           
if($this->getCurrentOrder() == 'random'{
             $this
->getCollection()->getSelect()->order('rand()');
            
}
           
else {
            $this
->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
           
}
        }
        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
bradsugar
Jr. Member
 
Total Posts:  28
Joined:  2008-08-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).

This is definatly an option that should be added.

James
http://www.rpgshop.com

Good job...I really love this…

 
Magento Community Magento Community
Magento Community
Magento Community
 
BungleFeet
Jr. Member
 
Total Posts:  26
Joined:  2008-08-20
 
Moshe - 25 October 2007 07:57 AM

@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

Moshe, is there any way I can alter this code without invalidating my installation to updates?  Can I place patched code in app/code/local and have Magento load the patched code instead?

Cheers,

Bungle

 
Magento Community Magento Community
Magento Community
Magento Community
 
BungleFeet
Jr. Member
 
Total Posts:  26
Joined:  2008-08-20
 
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!

I can offer a slight improvement to the above code.  The most sensible default behaviour would be DESC when ordered by newest (giving newest first), but ASC when ordered by Name or Price (although you may prefer most expensive first, depending on the situation).  To achieve this, edit the getCurrentDirection() function as below:

public function getCurrentDirection()
    
{
        
if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) {
            $dir 
strtolower($dir);
            if (
in_array($dir, array('asc''desc'))) {
                
return $dir;
            
}
        }
        
// CHANGE:  This code causes the default order for Newest to be descending (newest first)
        
if ($this->getCurrentOrder() == 'entity_id'{
            
return 'desc';
        
}
        
return 'asc';
    
}

Cheers,

Bungle

 
Magento Community Magento Community
Magento Community
Magento Community
 
yamushk
Jr. Member
 
Total Posts:  5
Joined:  2008-08-12
 
Moshe - 25 October 2007 07:57 AM

@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

Some stores, especially those dealing with design / artistic / aesthetic products would like to have the items listed by default according to how their pictures look (as default). The price, best value etc - are much less interesting.

Do you plan on adding a possibility to sort the products on the admin level (I want this product no. 1, this no. 2 etc) - and let me choose it by my will and not by “objective” data (price or name or date or random)?

Thank you - without it - the page looks messy and unatractive.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LaneB
Jr. Member
 
Total Posts:  4
Joined:  2008-11-06
Brisbane, Australia
 

Hi,

In the “Sort By:” box I want to remove the option of sorting by “Best Value”, as I’m not quite sure what that actually means. I like to think all my products are good value… wink

It looks like the method for doing this, by editing the toolbar.php file, has been well-explained in the preceding posts.

However, when I went to edit this file, I noticed it said:

* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.

Presumably, any edits you make to the toolbar.php file will be overwritten and lost every time you upgrade to a new version of Magento.

Is this correct?  If so, is there any workaround for this, like having some control over the “Search By” options through the admin interface?

 
Magento Community Magento Community
Magento Community
Magento Community
 
BungleFeet
Jr. Member
 
Total Posts:  26
Joined:  2008-08-20
 
LaneB - 06 November 2008 01:54 PM

Presumably, any edits you make to the toolbar.php file will be overwritten and lost every time you upgrade to a new version of Magento.

Is this correct?  If so, is there any workaround for this, like having some control over the “Search By” options through the admin interface?

Yes, if you want upgrades to your Magento install to go smoothly, it is important not to edit any of the core files.  Fortunately, it is possible to override the functionality of the core files in Magento.  In your case, to modify Toolbar.php in order to remove the “Best Value” option, create a new file Toolbar.php in the directory app/code/local/MyCompany/Catalog/Block/Product/List.  Put the following code in the file:

<?php
class MyCompany_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{
    
protected function _construct()
    
{
        parent
::_construct();
        
$this->_availableOrder = array(       /* BEST VALUE option removed */
            
'name'      => $this->__('Name'),
            
'price'     => $this->__('Price')
        );

        switch (
Mage::getStoreConfig('catalog/frontend/list_mode')) {
            
case 'grid':
                
$this->_availableMode = array('grid' => $this->__('Grid'));
                break;

            case 
'list':
                
$this->_availableMode = array('list' => $this->__('List'));
                break;

            case 
'grid-list':
                
$this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'));
                break;

            case 
'list-grid':
                
$this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'));
                break;
        
}
        $this
->setTemplate('catalog/product/list/toolbar.phtml');
    
}
?>

Now edit app/etc/local.xml, adding the following code inside the global tag:

<blocks>
    <
catalog>
        <
rewrite>
            <
product_list_toolbar>MyCompany_Catalog_Block_Product_List_Toolbar</product_list_toolbar>
        </
rewrite>
     </
catalog>
</
blocks>

This will cause Magento to load your custom code, overriding the core functionality.

Cheers,

Bungle

 
Magento Community Magento Community
Magento Community
Magento Community
 
LaneB
Jr. Member
 
Total Posts:  4
Joined:  2008-11-06
Brisbane, Australia
 

Thanks Bungle - that’s really helpful.  I’ll give it a try.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chatlumo
Guru
 
Total Posts:  301
Joined:  2008-02-20
Paris
 
BungleFeet - 06 November 2008 11:25 PM


Yes, if you want upgrades to your Magento install to go smoothly, it is important not to edit any of the core files.  Fortunately, it is possible to override the functionality of the core files in Magento.  In your case, to modify Toolbar.php in order to remove the “Best Value” option, create a new file Toolbar.php in the directory app/code/local/MyCompany/Catalog/Block/Product/List.  Put the following code in the file:

I use this possibility to keep the Magento core cleen.
So, my store is in French but now, the Toolbar is shown in english, do you know why ?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
elfling
Enthusiast
 
Avatar
Total Posts:  901
Joined:  2008-10-21
 

Just been looking to see what I would need to do to sort by sub category.

I’ve tried

'category_ID'  => $this->__('Category')
as well as
'category'  => $this->__('Category') ,

but with no resolve.

Is it going to be painfully simple that i’ve just overlooked?

 
Magento Community Magento Community
Magento Community
Magento Community
 
magnet0
Jr. Member
 
Total Posts:  29
Joined:  2007-10-23
Heraklion, Crete
 

So

If all we need to do, is change the default store ordering into “SKU” instead, where we have to do that?

- I do not need to change the drop down options. They are ok for me.
- And I do not want to add the product sku as a new option value there (I know it is working. I checked out allready).

Please help
Yiannis

 
Magento Community Magento Community
Magento Community
Magento Community
 
tsifra
Member
 
Total Posts:  57
Joined:  2008-09-14
 
chatlumo - 08 November 2008 06:10 AM

BungleFeet - 06 November 2008 11:25 PM


Yes, if you want upgrades to your Magento install to go smoothly, it is important not to edit any of the core files.  Fortunately, it is possible to override the functionality of the core files in Magento.  In your case, to modify Toolbar.php in order to remove the “Best Value” option, create a new file Toolbar.php in the directory app/code/local/MyCompany/Catalog/Block/Product/List.  Put the following code in the file:

I use this possibility to keep the Magento core cleen.
So, my store is in French but now, the Toolbar is shown in english, do you know why ?

Thanks.

Add this to your custom config.xml file with rewrites

<config>
  <global>
..
  </global>
  <
frontend>
    <
translate>
      <
modules>
        <
Mynamespace_Catalog>
          <
files>
            <default>
Mage_Catalog.csv</default>
          </
files>
        </
Mynamespace_Catalog>
      </
modules>
    </
translate>
  </
frontend>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
tsifra
Member
 
Total Posts:  57
Joined:  2008-09-14
 

Solution in previous message is buggy.

May be bug in magento.

To reproduce:

- Insert custom translate tags in config.xml as in my previous post.
- Then go to one of catalog pages.
- Take a look at compare box.
- Text in in it is independent of locale. “You have no items to compare.”

Maybe something somewhere else.

UPDATED:
Created bug report http://www.magentocommerce.com/bug-tracking/issue?issue=4196

 
Magento Community Magento Community
Magento Community
Magento Community
 
tsifra
Member
 
Total Posts:  57
Joined:  2008-09-14
 

If this bug is important for someone else please leave comments in my bug report.

Changing sources of core/mage because of translation is not good idea.

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