Magento - 非eav集合排序顺序

时间:2012-07-05 20:31:13

标签: magento

在Magento中,使用非eav集合时,添加排序顺序的最佳方法是什么?

使用eav集合我相信有方便的方法可以做到这一点,但非eav似乎没有相同的设施。

4 个答案:

答案 0 :(得分:10)

Magento集合超类(Mage_Core_Model_Resource_Db_Collection_AbstractMage_Eav_Model_Entity_Collection_Abstract)都从集合超类Varien_Data_Collection_Db继承了三种公共便捷方法:

EAV集合超类提供了另一种方法addAttributeToSort(),它确保将属性连接到集合以进行排序。

由于Vinaipointed out on his tumblr,因此需要考虑这些方法的行为方式和时间。

答案 1 :(得分:4)

对我来说,排序自定义模块集合(平面集合)的唯一方法是使用:

$sortField = 'field-goes-here';
$direction = 'ASC'; //or 'DESC'
$collection->getSelect()->order($sortField , $direction);

希望这有帮助。

答案 2 :(得分:2)

试试这个

$_productCollection=Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($_category)->setOrder('field-goes-here', 'DESC');

答案 3 :(得分:0)

$collection->getSelect()->order($sortField , $direction);

替换为:

$collection->getSelect()->order($sortField . $direction);

命令期望1个参数