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.
23 Responses to “Magento Default Products Sort Order Newest”
narina
very good! thanks a lot!!
Einstein9
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
SonicE
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’;
y
i was just looking for this! will try out!
Daniel
Can’t find anywhere the code for:
$this->_availableOrder = array(
entity_id => $this->__(Newest),
name => $this->__(Name),
price => $this->__(Price)
);
ed
Daniel, the file would be here:
/app/code/core/Mage/Catalog/Block/Product/List.php
Skully
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
ed
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
steward
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.
Prashant
I want to sort order by their availability in the stock, if its “out of stock” it should be displayed at the end.
Me
You are a genius …..Thanks lots
artur
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!
ANDiTKO
For Magento 1.4 Change line 119 to:
protected $_direction = ‘desc’;
Sacha
Thanx! This is awesome!!
scott
Even easier yet. Just add this to custom layout for the categories you want to reverse the order of.
desc
vipinss316
thnx a lot
Prashant
nice thanks…
Bryan
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.
tuba
very helpful and nice trick! Thank you!
A Tucson Web Designer
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.
Jim
Thank you for sharing the post.
Nowadays right sorting options can help online shop to attract customers and create better condition to product buying.
I use http://amasty.com/improved-sorting.html extension for my web shop and i can tell that it works perfect.
Paul Simmons
Thank you for share a great post here with all.
I have recently came across with an alternative extension that improves product sorting options in Magento.
Let me know how do you see this module? http://www.fmeaddons.com/magento/improve-catalog-sorting-products-extension.html
HM Hasan
I have a problem.
it is working my site it show new to old.But if I change sort by then, when I return Newest it do not work, it show old to new. please help me.