1

I am using Magento 1.7.0.2

I would like to have several the products for several of my categories to be automatically sorted by date added. Currently, in the 'Display Settings' tab for any one of my categories, I am not offered this option in the 'Default Product Listing Sort By" dropdown.

I know 1) how to add this option to the frontend user and I also know 2) how to overwrite a core file to set all categories to sort by entity ID (in descending order) which essentially the same as 'date added'.

However, I want to be able to configure this option for individual categories through the backend. Is there any way to have the 'date added' or 'entity id' added to the 'Default Product Listing Sort By" dropdown in the backend?

5

you cannot modify the attribute created_at in the backend.
So you need to create a module that just activates the created_at attribute for sorting.

For this you will need the following files:

app/etc/modules/[Namespace]_[Module].xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <[Namespace]_[Module]>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Catalog />
            </depends>
        </[Namespace]_[Module]>
    </modules>
</config>

app/code/local/[Namespace]/[Module]/etc/config.xml - the configuration file

<?xml version="1.0"?>
<config>
    <modules>
        <[Namespace]_[Module]>
            <version>1.0.0</version>
        </[Namespace]_[Module]>
    </modules>
    <global>
        <resources>
            <[namespace]_[module]_setup>
                <setup>
                    <module>[Namespace]_[Module]</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class> <!-- Make sure you use this class for setup -->
                </setup>
            </[namespace]_[module]_setup>
        </resources>
    </global>
</config>

app/code/local/[Namespace]/[Module]/sql/[namespace]_[module]_setup/install-1.0.0.php - the install script

<?php
$this->updateAttribute('catalog_product', 'created_at', 'frontend_label', 'Date Added'); //Set a label to the attribute because by default it does not have one
$this->updateAttribute('catalog_product', 'created_at', 'used_for_sort_by', '1'); //mark the attribute as used for sorting.

Clear the cache and refresh any page. Now you should have the Date Added (created_at) attribute available for sorting in any category.

  • Also I think you need to set default sort order as DESC for this attribute as Magento will sort is from older to newest otherwise. – Amasty Jul 28 '14 at 9:32

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.