1> First need to create discount attribute for products.
2> After creation that copy app/code/core/Mage/Catalog/Mo del/Resource/Product/collection.php in local folder app/code/local/Mage/Catalog/Mo del/Resource/Product/collection.php
open the file find below bit of code around 1572
if ($attribute == 'price' && $storeId != 0) {
$this->addPriceData();
$this->getSelect()->order("price_index.min_price {$dir}");
return $this;
}
after that Add below code
2> After creation that copy app/code/core/Mage/Catalog/Mo
open the file find below bit of code around 1572
if ($attribute == 'price' && $storeId != 0) {
$this->addPriceData();
$this->getSelect()->order("price_index.min_price {$dir}");
return $this;
}
after that Add below code
if ($attribute == 'discount') {
//determine the discount percent value
$this->addExpressionAttributeT oSelect('discount', '(({{price}} - special_price) / {{price}})', array('price'));
//sort by the discount percent value
$sortDir = $dir;
//in case you need to reverse the order so when you sort ascending you will see the most discounts first do this:
//if not then remove the if-else statement below.
if ($sortDir == self::SORT_ORDER_ASC) {
$sortDir = self::SORT_ORDER_DESC;
}
else {
$sortDir = self::SORT_ORDER_ASC;
}
$this->getSelect()->order(arra y('discount '.$sortDir));
return $this;
}
Comments
Post a Comment