繁体   English   中英

Magento排序具有多个属性的集合

[英]Magento sort collection with multiple attributes

我想在目录产品列表页面上对具有多个属性的Magento产品集合进行排序。 我正在使用此代码

$this->_collection->setOrder('price', 'desc');
$this->_collection->setOrder('price_plus_shipping', 'desc');

我也尝试了这段代码

$this->_collection->setOrder(array('price', 'price_plus_shipping'),Varien_Data_Collection::SORT_ORDER_DESC);

当我将它们都排序时,它们并没有给我准确的结果,但是如果我分别使用它们就像我仅使用时一样

price_plus_shipping

它的工作也很好

价钱

它们的工作文件也向我显示了准确的结果。 但是我想结合使用它们。 价格中,我的产品价格在price_plus_shipping中,我有一些字母,例如

a,b,c等

我已经研究了您的方法并获得了结果。 我创建了一个文本类型属性“ price_plus_shipping ”。

Visible on Product View Page on Front-end => Yes
Used in Product Listing => Yes
Used for Sorting in Product Listing => Yes

现在在app\\design\\frontend\\[Package]\\[Theme]\\template\\catalog\\product\\list.phtml上进行以下更改

$_productCollection=$this->getLoadedProductCollection();
$_productCollection->clear();
$_productCollection=$_productCollection->addAttributeToSort('price', 'DESC');
$_productCollection=$_productCollection->addAttributeToSort('price_plus_shipping', 'ASC');
$_helper = $this->helper('catalog/output');

希望对您有帮助。

Magento 1.9中的setOrder和多列似乎存在一个错误。 我能够像下面这样工作:

$this->_collection->getSelect()->order(array('price desc', 'price_plus_shipping desc'));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM