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.
You can do that writing directly to the database below is a working code that do that using an array of categories products
You have to create the array like this
$categoryPosition[] = array('product_id' => $mageProduct->getId(),
'category_id' => $categoryId,
'position' => $position);
an run this code
foreach ($categoryPosition as $position){
//print "Position: c=".$position['category_id']." prod=".$position['product_id']." pos=".$position['position'] . "\n";
$query = "UPDATE tn_catalog_category_product SET position = :position "
. "WHERE category_id = :category_id and product_id = :product_id";
$values = array('position' => $position['position'],
'category_id' => $position['category_id'],
'product_id' => $position['product_id']);
$writeConnection->query($query,$values);
}
and remember to run the indexer catalog_category_product
Thanks
Best Answer
I think you could either do it for each category or you could do it here as seen in the screenshot below
UPDATE Otherwise try this
In the toolbar block there is a method called disableParamsMemorizing. This should disable the storing of parameters in session. Try to add this in the toolbar block.
or you can override the Mage_Catalog_Block_Product_List class and make the getToolbarBlock method look like this: