Jump to content

[Solved] rounded discount % on specific price


toitoine

Recommended Posts

Hi

I've prestashop 8 and when I'm doing a specific price, I've to  write a discount pourcentage like -21,83% but it doesn't look nice.

Is it possible to change it with a rounded number, in example -22%

Let me know please, I'm using the template Warehouse child theme from Iqit commerce

https://iqit-commerce.com/warehouse-1-7-style-selector/

Capture d’écran 2024-07-10 à 10.49.07.png

Edited by toitoine (see edit history)
Link to comment
Share on other sites

Hello

You need to edit the tpl file of your theme like below

Go to /themes/YOUR_THEME/templates/catalog/_partials/product-prices.tpl

and replace this part of the code with the code given below

{if $product.has_discount}
            {if $product.discount_type === 'percentage'}
              {assign var="discount_value" value=$product.discount_percentage_absolute|replace:"%":""}
              {math equation="ceil(x)" x=$discount_value assign="rounded_discount"}
              <span
                class="discount discount-percentage">{l s='Save %percentage%%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => $rounded_discount]}</span>
            {else}
              <span class="discount discount-amount">
                {l s='Save %amount%' d='Shop.Theme.Catalog' sprintf=['%amount%' => $product.discount_to_display]}
              </span>
            {/if}
          {/if}

 

  • Like 1
Link to comment
Share on other sites

Hello

I understand. You are not using the absolute value. In that case use the code below.

{if $product.has_discount}
            {if $product.discount_type === 'percentage'}
              {assign var="discount_value" value=$product.discount_percentage|replace:"%":""}
              {math equation="ceil(x)" x=$discount_value assign="rounded_discount"}
              <span
                class="discount discount-percentage">{l s='Save %percentage%%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => $rounded_discount]}</span>
            {else}
              <span class="discount discount-amount">
                {l s='Save %amount%' d='Shop.Theme.Catalog' sprintf=['%amount%' => $product.discount_to_display]}
              </span>
            {/if}
          {/if}

The code is the same. I just changed the discount_percentage_absolute with discount_percentage. 

If it does not work then you can give me site access in a private message. I will fix it for you.

Thanks

Link to comment
Share on other sites

Hello @toitoine

Let me give you the global solution for this. You just need to edit one file in this case. 

Go to "/src/Adapter/Presenter/Product/ProductLazyArray.php" and find the code below on the function addPriceInformation  

$this->product['discount_percentage'] = Tools::displayNumber($presNegativeReduction) . '%';
$this->product['discount_percentage_absolute'] = Tools::displayNumber($presAbsoluteReduction) . '%';

Now add the code below before the given code

$presAbsoluteReduction = ceil($presAbsoluteReduction);
$presNegativeReduction = floor($presNegativeReduction);

That will do.

Thanks

  • Like 1
Link to comment
Share on other sites

  • toitoine changed the title to [Solved] rounded discount % on specific price

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...