2011-02-25 102 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');