0

I'm running Magento CE 2.3.3 with Porto theme. I want to sort the products in the category overview by the date they were added without using an extra extension. By default products in category view/category pages can be sortet by either position, product name, size, price. The pre selected sorting attribut is position.

Although there is a way to define new attributes, there is no way to create an attribute that sorts by date resp. newest first.

What is the smartest way to add this feature to Magento without adding much new code? The question is related to the questions in these threads:Magento 2: Sort Product Collection by date added to category and Sort products by Date... Unfortunately I haven't figured it out yet.

0

All products have a created_at attribute containing the date the product was added. You can enable this as a frontend sort option in two ways.

If you have access to your database:

  • Find the created_at product attribute in DB table eav_attribute
    • set its column frontend_label to Created At(default is null).
  • Find the created_at product attribute in DB table catalog_eav_attribute
    • set its column used_for_sort_by to 1(default is 0).
  • Refresh caches

Created At will now be available as a frontend sort option which you can set as the default sort option in admin. The more conventional way to do this is via a module where you change the database fields using the setup methods.

You can find more information about both ways here:

Magento 2 How to add custom sort by option

I find using the created_at attribute to sort products very useful because if you want to push products to the top of the list you can always manually set the created_at attribute with something like

$product->setCreatedAt($now);

Needless to say you should test this on your dev shop and make sure you have a (working) backup before you change anything.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.