开发者

How to change the product display order in magento

开发者 https://www.devze.com 2023-02-06 14:37 出处:网络
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 displ

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 开发者_C百科based on its value the product needs to shown in front end. However, it is not working. Please help me fix this.


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.


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 :)


To change the display order , first you need to set the default sort by option to position.This can be done from the magento admin configuration.After that you need to set position for all the products starting with the value 1.

I come across the following module which will make this task very easy, just by drag and drop the products from the manage categories itself.Please check the following extension

http://www.blackqubers.com/extensions/product-sorting-drag-and-drop.html

Hope this will helps you

0

精彩评论

暂无评论...
验证码 换一张
取 消