What I am trying to achieve is this, I have configurable products I want to display the percentage of the discount as a label on the image maybe in the top right corner. I've managed to display it by using this code:

         $item = $block->getSaleableItem();
         $_savePercent = 100 - round(((float)$priceModel->getAmount()->getValue() / (float)$finalPriceModel->getAmount()->getValue()) * 100);
         echo '<b style="color:#008000">'.$_savePercent . '% off </b>';

This edit is placed in my final_price.phtml file. However with this I am displaying the % Discount in my product page as well. Because I will have different stylings for both the pages I want to display it seperatly once in the catalog and once on the product page. Is there a way to do it? I do not want to use extensions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.