Magento:对产品系列进行排序

Iva*_*var 6 php sorting magento

我正在创建一个模板以在主页上显示特色产品,我想控制产品的顺序.

这就是我目前使用的基于类别获取产品集合的方法:

<?php
    $_productCollection = $this->getLoadedProductCollection();
?>
Run Code Online (Sandbox Code Playgroud)

没有具体的排序.

当我要对产品进行分类时,我希望这可以工作:

<?php
    $_productCollection = $this->getLoadedProductCollection()->addAttributeToSort('name', 'ASC');
?>
Run Code Online (Sandbox Code Playgroud)

但是根本没有区别.我究竟做错了什么?

先感谢您!

Raj*_*odi 8

使用这个我用同样的方式尝试它.

$collection = Mage::getModel('catalog/product')
             ->getCollection()
             ->addAttributeToSort('name', Varien_Data_Collection::SORT_ORDER_ASC);
Run Code Online (Sandbox Code Playgroud)

降序排列:

$collection = Mage::getModel('catalog/product')
              ->getCollection()
              ->addAttributeToSort('name', Varien_Data_Collection::SORT_ORDER_DESC);
Run Code Online (Sandbox Code Playgroud)

对于其类别的产品:

$collection = Mage::getModel('catalog/category')->load($categoryId)
             ->getProductCollection()
             ->addAttributeToSort('name', Varien_Data_Collection::SORT_ORDER_ASC);
Run Code Online (Sandbox Code Playgroud)

或者你可以在magento wiki上找到更多帮助.