How to Display Discounted Products at the Top of the Directory in Prestashop

Photo of Aliaksandr Simanchyk
Aliaksandr Simanchyk
Lead Full Stack Developer
Mar 11, 2014 991 Updated: July 1, 2025 8:42
How to Display Discounted Products at the Top of the Directory in Prestashop

Today let’s talk about the methods which can help us draw customers attention  to discounted products. We suggest placing them at the top of the directory and not changing their place even if a customer applies any kind of sorting, which will attract additional visitors’ attention.

So, for example, we have a directory with 2 discounted items:

1Discounted Products 850x558

In order to aply additional type of sorting we will need to rewrite the Category class, that is to modify the file classes/category.php by adding the method “reduсedCmp” and modify the method Category::getPrоduсts()

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


Now the directory page looks like this:

2Discounted Products 850x531

If you want to apply this sorting only when the default sorting is used, you need to replace the line:


to this line


If you are using the module Blосklаyered, then you need to further edit the function BlосkLаyered::getPrоduсts()  in the  file modules/blосklаyered/blосklаyered.php by adding this line at the end:


development_prestashop

PrestaShop Development

Take your online store to the next level with BelVG PrestaShop Development

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

6 Comments

  1. When I activate the Debug mode I have an error :

    Strict Standards: usort() expects parameter 2 to be a valid callback, non-static method Category::reducedCmp() should not be called statically, assuming $this from compatible context Category in /home/my_website_com/override/classes/Category.php on line 669

    It correspond to the usort line :

    //* Modify SQL result */
    //return Product::getProductsProperties($id_lang, $result); //sorting the collectiong of products
    $product_collection = Product::getProductsProperties($id_lang, $result);
    usort($product_collection, array(“Category”, “reducedCmp”)); //sorting by the parameter ‘reduction’
    return $product_collection; // returning the modified result
    }

  2. It look like nice now tks a lot.

    Before, by default I had the new products in 1st. With this modification I have the Discounted products in 1st, but how add the new products just after the discounted now plz ?

  3. error Found ! ^^

    this is the good code :

    protected function showPriceFilter()
    {
    return Group::getCurrent()->show_prices;
    usort($product_collection, array(“Category”, “reducedCmp”));
    }
    }

  4. On Category.php I have now it :

    $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
    if ($order_by == ‘orderprice’)
    Tools::orderbyPrice($result, $order_way);

    if (!$result)
    return array();

    //* Modify SQL result */
    //return Product::getProductsProperties($id_lang, $result); //sorting the collectiong of products
    $product_collection = Product::getProductsProperties($id_lang, $result);
    usort($product_collection, array(“Category”, “reducedCmp”)); //sorting by the parameter ‘reduction’
    return $product_collection; // returning the modified result
    }

    public function reducedCmp($a, $b) {
    if ($a[‘reduction’] == $b[‘reduction’]) {
    return 0;
    }
    return ($a[‘reduction’] > $b[‘reduction’]) ? -1 : 1;
    }

    /**
    * Return main categories

    And in blocklayered.php :

    protected function showPriceFilter()
    {
    return Group::getCurrent()->show_prices;
    }
    }

    usort($product_collection, array(“Category”, “reducedCmp”));

    But nothing new at the screen now….

Post a new comment