Magento Sort Products by Newest In

post image
IMAGE: Blueclaw

So a request we get time and time again is to add to the sort options in a Magento store the ability to sort by the latest products. This is something that can actually be sorted with just two database queries.

This is due to the hidden product attribute called “created_at”, you can’t access this from the normal manage attributes screen, but you can amend it within the database so that like with other attributes it can be used for sorting the products on category pages.

UPDATE `catalog_eav_attribute`
SET `used_for_sort_by` = 1
WHERE attribute_id = (
SELECT * FROM `eav_attribute` WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") AND `attribute_code` = "created_at");

The Next query then just adds a front end label which is used as the text in the sort by drop down. replace Newest with whatever text you want to use.

UPDATE `eav_attribute`
SET frontend_label = "Newest"
WHERE `entity_type_id` = (SELECT  `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") and `attribute_code` = "created_at");

And now if you load a category page you should see the new sort method. You can even now set this to be the default sort order in the standard Magento configuration

about the author: "Blueclaw's Senior Technical SEO likes canonical tags, URL parameters and long walks on the beach (alright, site migrations). Can typically be found tinkering with the innards of the nearest eCommerce site."
filed under: eCommerce / Magento Tips | tags: / / /