2016-11-17 70 views
0

我想在目錄產品列表頁面上用多個屬性對Magento產品集合排序。我使用這個代碼帶有多個屬性的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

其實效F國家統計局也爲

價格

它也正在文件 顯示,他們是我準確的結果。但我想用它們結合。 在價格我有產品價格在price_plus_shipping我有一個像

A,B,字母Ç等

回答

1

我已經在你的方法工作,並獲得滿意的結果。 我已經創建了一個文本類型屬性「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'); 

我希望這會幫助你。

+0

@OBAID 您是否檢查了此解決方案? –

0

在Magento 1.9中,似乎有一個setOrder和多列的錯誤。我可以像這樣工作:

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