0

I want to show all my products by default from newest to oldest. I saw this links:

First solution

Second solution

And also this one. All of them show same solution, but always for Frontend.

What I want is to set by default on System->Configuration->Catalog->Product Listing sort by and set it by default to Created at, and I want also to set the order (desc or asc).

Any ideas on how to customize that?

Community
  • 1
  • 1
Sonhja
  • 8,230
  • 20
  • 73
  • 131

3 Answers3

3

I'm sorry I didn't answer your question.

The grid is ordered by entity_id:

// app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php:41
$this->setDefaultSort('entity_id');
$this->setDefaultDir('DESC');

This means, your wanted behaviour should be default.

Fabian Blechschmidt
  • 4,113
  • 22
  • 39
2

You can install GridControl and write an extension and add this to an grid.xml which you created in the module

<?xml version="1.0"?>
<gridcontrol>
    <grids>
        <product.grid>
            <add>
                <header>Created at</header>
                <type>int</type>
                <index>created_at</index>
          </add>        
        </product.grid>
    </grids>
</gridcontrol>

This solution is not tested.

Fabian Blechschmidt
  • 4,113
  • 22
  • 39
  • GridControl is an extension to easily add new columns to grids. With the above code, you can add the created_at column. I just saw, that you can not order by this column with the extenion. so you have two ways: extend the extension to change the default order or write your own extension to change it. – Fabian Blechschmidt Dec 28 '12 at 09:42
0

The best way to go about it without changing any core files is to copy the Toolbar.php file located:

/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

then create a new directory path (if you haven't created one) under:

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

Now replace the following from line 232:

    if ($this->getCurrentOrder()) {
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }

to

if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){ //defines the sort option
//sort by position (ascending) and entity_id (descending)
$this->_collection->addAttributeToSort('position','asc')->addAttributeToSort('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

Lastly, reindex and refresh cache on your Magento backend and your ready to go.

pasujemito
  • 312
  • 4
  • 16