2011-02-25 93 views
0

我有一個自定義頁面,我已經放在一起,基本上顯示出售的產品。有人問我是否可以按最高比例的折扣對產品進行分類。Magento排序百分比折扣

所以我想知道是否有可能根據潛水其他兩個屬性的數學結果一起設置產品的順序。

回答

2

我想我想通了。 Alan Storm先前幫助我解決了一個類似的問題,那就是我以任意方式分類產品。

Magento get a product collection in an arbitrary order

使用我想出了下面的代碼相同的想法,使這項工作:

$products = Mage::getModel('catalog/category')->load($category_id) 
->getProductCollection() 
->addAttributeToSelect('name') 
->addAttributeToSelect('price') 
->addAttributeToSelect('small_image') 
->addAttributeToFilter('status', 1) 
->addAttributeToFilter('visibility', 4) 
->addAttributeToFilter('special_price', array('neq' => "")) 
->addAttributeToFilter('discontinued', array('neq' => 1)) 
->setPageSize($results_per_page) 
->setCurPage($current_page) 
; 

$產品 - > getSelect() - >訂單('(e .special_price/eprice)','DESC');

信用應該去這個Alan Storm。

+0

這是什麼意思e.special_price或e.price – 2011-06-18 10:26:00

+0

如果你做了一個回聲「$ products-> getSelect()」,你會看到正在運行的查詢。您從SQL中選擇的主表稱爲e。 – 2011-06-22 15:00:28

0

使用: $產品 - > getSelect() - >序( '1 - (price_index.final_price/e.price)', 'DESC');

所以即使你有一些規則促銷活動有考慮。

2

看一看Smart Sorting Extension for Magento

它可以讓您在您的商店的目錄客戶sort products在9點新的方式:

現在心願(實時),在車(實時)

現在,

最大$ Saving,

Bigg EST%節能

顧客選擇

討論最多

最欣賞

最近

摩斯t看過

0

D. Militos答案對我來說是正確的,有輕微的修正:

$產品 - > getSelect() - >序(「1 - (price_index.final_price/price_index。價格)','DESC');