Magento currently does not sort category products and any product listing for that matter by Newest (highest entity_id). Since my store works best when showing fresh products we felt it necessary to have our Magento installation sort by newest product first (descending) so that just by clicking through categories, users would be seeing the latest and greatest products. Now, Magento does allow you to manually rank per product from the Catalog -> Manage Categories -> Category Products screen, but changing our product listings to show latest products first was our goal.
* Note: Those of you now using Magento version 1.4.* can and should avoid editing the core files and now simply make the change by editing you’re theme’s xml layout files. You can read about this here:
I was able to change my Magento product listings to show newest items first by following the comments in this post within the Magento Forum:
The two important pieces are here:
We need things sorted by product entered date since my industry is very front-line driven. So I wen and changed things to this:
1 2 3 4 5 $this->_availableOrder = array( entity_id => $this->__(Newest), name => $this->__(Name), price => $this->__(Price) );
And here:
Figured it out: in the same toolbar.php file, around lines 101-110, change this:
1 2 3 4 5 6 7 8 9 10 public function getCurrentDirection() { if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) { $dir = strtolower($dir); if (in_array($dir, array(desc, asc))) { return $dir; } } return <strong>asc</strong>; }To this:
1 2 3 4 5 6 7 8 9 10 public function getCurrentDirection() { if ($dir = (string) $this->getRequest()->getParam($this->getDirectionVarName())) { $dir = strtolower($dir); if (in_array($dir, array(desc, asc))) { return $dir; } } return <strong>desc</strong>; }Along with your newest entity_id it works like a charm!
That allowed me to have my Magento store sort by newest product first.
Now, there will be an issue when updating so hopefully they’ll be able to add default sort ordering to the administrative suite in the upcoming versions.
Incoming search terms:
- magento sort by newest
- magento product sort order
- magento sort by date
- magento sort by
- magento sort products by date
- magento Product Listing Sort by
- magento product order
- Magento Sort Order
- magento sort by stock
- magento sort products
No related posts.

very good! thanks a lot!!
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
For Magento version 1.3.2.3
The file you need to look at is: /app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php
Since we’ll modify it, make a copy to /app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php
Near Line 98 search for
protected $_direction = ‘asc’;
Change to
protected $_direction = ‘desc’;
i was just looking for this! will try out!
Can’t find anywhere the code for:
$this->_availableOrder = array(
entity_id => $this->__(Newest),
name => $this->__(Name),
price => $this->__(Price)
);
Daniel, the file would be here:
/app/code/core/Mage/Catalog/Block/Product/List.php
Could not find any of these lines in mine either 2 files.
$this->_availableOrder = array(
entity_id => $this->__(Newest),
name => $this->__(Name),
price => $this->__(Price)
);
Magento ver. 1.3.2.3
Skully, I’m running the same version and the file for this is still on the Product List.php template:
/app/code/core/Mage/Catalog/Block/Product/List.php
This discussion assumes “entity_id” means the same as “newest”.
Not so, for many who imported and updated some batches of products when we converted to Magento.
I’d really like to sort by “date added”. Sigh.
I want to sort order by their availability in the stock, if its “out of stock” it should be displayed at the end.
You are a genius …..Thanks lots
hello to all, do you know maybe how to do it in magento 1.4? adding new attribute doesn’t work – it listing with known only to itself way and in different way each time… so, i would like to hack code or even change position option for entity_id or something. i would be very thankful for your help!
For Magento 1.4 Change line 119 to:
protected $_direction = ‘desc’;
Thanx! This is awesome!!
Even easier yet. Just add this to custom layout for the categories you want to reverse the order of.
desc
thnx a lot
nice thanks…
1.5.1
I had to add code in toolbar.php because the “available order array” was not there. I was looking to add “rating summary” to the array.
This is from several other posters, not my code, perhaps is more clear in my summary (hopefully helpful to someone )as this was in pieces in several posts over different forums. Thanks to posters!
——–
Toolbar.php
Line 233
public function setCollection($collection)
{
parent::setCollection($collection);
if ($this->getCurrentOrder()) {
—————
// Begin new Code
$this->getCollection()->joinField(‘rating’,
‘review/review_aggregate’,
‘rating_summary’,
‘entity_pk_value=entity_id’,
‘{{table}}.store_id=1′,
‘left’);
// End new Code
—————–
$this->getCollection()->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
return $this;
}
———-
Line 422 ( after adding lines at 233)
public function getAvailableOrders()
{
// Add rating to “Sort by”
$_availableOrder = $this->_availableOrder;
$_availableOrder['rating'] = ‘Rating’;
return $_availableOrder;
$this->_availableOrder = array(
‘entity_id’ => Mage::helper(’catalog’)->__(’Newest’),
‘name’ => Mage::helper(’catalog’)->__(’Name’),
‘price’ => Mage::helper(’catalog’)->__(’Price’),
‘rating_summary’ => Mage::helper(’catalog’)->__(’Rating’)
);
return $this->_availableOrder;
}
________
This works but displays:
Position
Name
Price
Rating
I was expecting it to display
Newest
Name
Price
Rating
I do not think Position is equal to Newest?
And I changed line 119 to
protected $_direction = ‘desc’;
but does not seem to have any effect.
I am wanting to display
Reviews: descending
Newest: descending
Price: ascending
and not show Position.
Thanks for any help or pointers.
Bryan.
very helpful and nice trick! Thank you!
Great article, but the tough part that I’m looking for is sorting via a custom order. It’s tricky because you’ll need to create a custom attribute for that and then change the product sort by adding a module to override the list.phtml template in Magento 1.5.1. Maybe I’ll post an article about it and link it to this.