简体   繁体   中英

How to display promotions first in Magento catalog page?

I want to make a functionality to display on the category page, promotion products first (special_price > 0).

I've tried multiple things but none seems to be working.

I was thinking to add

if((price_index.final_price - price_index.price) > 0 ? 0 : 1

as a field and the AS promoP , and then order by promoP but I cannot manage to make this in collection.

$this->_productCollection->getSelect()->columns(array(new Zend_Db_Expr('promoP') => '(if((price_index.final_price - price_index.price) > 0 ? 0 : 1))'));

Solved by doing this

$this->_productCollection->getSelect()->columns(array('promoP' => new Zend_Db_Expr('IF(price_index.final_price < price_index.price, "0", "1")')));

$this->_productCollection->getSelect()->order('promosP asc');

This is going to display all the promotions first and then rest of the products. I creating an plugin from it so it is going to help in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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