I want to add a new filter Discount on category page. It's values will be something like

0-10 %
11-20 %
21-30 %

I do not want to import the values of discount attribute with product import which is a manual process. Instead I want to make it dynamic.

Example: If products base price is 100 and special price is 90, product should be shown in 0-10 % discount filter.

Can you please share your thoughts about how to achieve it?


1 Answer 1


I hope its useful to you, try with this code.

1) create one attribute of type "dropdown" as discount_percentage.

2) assign attribute to the product attribute set

3) now for calculation of the product discount you can try using observer called catalog_product_save_before with following code in observer.php

public function catalog_product_save_before($observer)
    $product = $observer->getProduct();
    $product_price = $product->getPrice();
    $product_sp_price = $product->getSpecialPrice();
    $discount_percentage = ($product_sp_price/$product_price)*100;

Note :- before discount is assiging to product the that option should be created previously.for example if the discount is 30% the discount option 30% should be their before or else you have to look how to create this options to dropdown attributes programmatically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.