获取集合排序顺序字段

时间:2013-05-27 14:20:35

标签: magento

有没有人知道从Magento产品系列中读取排序顺序数组的聪明方法?对象中有受保护的属性_orders。我可以通过

来达到目的

$collection->getSelect()->getPart('order')

然后我必须进行字符串解析。 我希望有一种公共方法可以从产品集合中获取排序顺序信息吗?

2 个答案:

答案 0 :(得分:1)

您可以使用Reflection

$property = new ReflectionProperty(get_class($collection), '_orders');
$property->setAccessible(true);
$orders = $property->getValue($collection);

但是你不会避免一些字符串解析,因为订单值存储在字符串中($field.' '.Varien_Data_Collection::SORT_ORDER_(ASC|DESC)

答案 1 :(得分:0)

对于带工具栏的产品集合,您可以向工具栏询问当前的排序顺序:

Mage::getBlockSingleton('catalog/product_list_toolbar')->getCurrentOrder()