How to change the product display order in magento
Solution 1
You'll need to extend the Mage_Catalog_Block_Product_List
block to provide your own functionality for the getProductCollection()
method. Probably something along the lines of:
class ... extends Mage_Catalog_Block_Product_List {
function getProductCollection() {
parent::getProductCollection()->addAttributeToSort('display_order', 'ASC')
}
}
Then, of course, you'll have to update you layout xml file on your, presumably, custom controller (unless you want all of the product listing screens to act like this) to use your new block instead of the Magento default of catalog/product_list
.
Solution 2
Why don't you use the Magento sorting thing ?
In your category, under Category Product you have the possibility to choose the sorting order in the last column. To do it through php, just make a custom script that you'll need to launch once.
$collection = 'Your product collection';
$result = array();
foreach ($collection as $product) {
$sort = 'Your way of calculating the desired sorting';
$result[$product->getId()]=$sort;
}
Mage::getModel('catalog/category')->load('your category id')->setPostedProducts($result)->save();
And that's it :)
Elamurugan
Magento Certified + Web and API Developer with PHPStack, MEAN stack
Updated on June 04, 2022Comments
-
Elamurugan almost 2 years
How can I change the product display order in the front end (grid or list) by setting some preferences from back-end? I guess it should be other than best value and name from the default Magento display order property.
I tried by creating a new attribute called display_order, and each product holds a value based on its value the product needs to shown in front end. However, it is not working. Please help me fix this.
-
Elamurugan about 13 yearsHi, Sorry just yesterday i could able to work on it. Instead of extending the product_list cant i add the same sorting condition to production collection query as like this. $this->_productCollection = $layer->getProductCollection()->addAttributeToSelect('product_display_order')->addAttributeToSort('product_display_order', 'ASC'); But its not working, I want to apply this sorting in particular category alone.