Jump to content

Force decimals do disappear on percentage discounts


Higino

Recommended Posts

So I followed the instructions on this topic: 

 

Problem is, it only works when there are no decimals. In this case the discount is 25,15%, but my client insists the decimals must be hidden.

I was wondering if I could manage this without having to debate whether hiding decimals is ethically wrong. But anyway, is there a variation of string_format I can use to specify decimals should be hidden even when they're not zero?

Thanks!

Link to comment
Share on other sites

3 hours ago, Mediacom87 said:

Hi,

The solution proposed by the topic you quote is perfect.

Maybe you don't apply the fix in the right place.

https://www.smarty.net/docsv2/en/language.modifier.string.format.tpl

{$number|string_format:"%d"}

 

Hi! Maybe, I'm sure this is the right file because I followed just the directory path they mentioned. So maybe It's on the wrong place inside the file. Let me give you the piece I edited:

 {hook h='displayProductPriceBlock' product=$product type='weight'}
               {if $product.discount_type === 'percentage'}
                  <span class="discount-percentage discount-product">{$product.discount_percentage|string_format:"%d"}</span> 

This should be it, right? Let me say again that the decimals do disappear when the percentage is an integer. Not so when It's a real number. So it should be doing something, right?

 

4 hours ago, ndiaga said:

Hi,

You  can  parse  Int  them  in  the  template like  this  :

{$my_variable|intval}

 

Sorry I'm not yet very experienced in php. Could you just confirm, to apply this, I'd have to write it where you see "string_format", right? In my example above.

Or do I have to use the variable somewhere else?

Link to comment
Share on other sites

44 minutes ago, ndiaga said:

Yes,  where you have    "string_format"  .

It  is  the same.

I hate to say it but I don't think I'm grasping the idea. Here's what I've tried:

 {hook h='displayProductPriceBlock' product=$product type='weight'}
               {if $product.discount_type === 'percentage'}
                  <span class="discount-percentage discount-product">{$product.discount_percentage|intval}</span> 

and

{hook h='displayProductPriceBlock' product=$product type='weight'}
               {if $product.discount_type === 'percentage'}
                  <span class="discount-percentage discount-product">{$product.discount_percentage|intval()}</span>

and

{hook h='displayProductPriceBlock' product=$product type='weight'}
               {if $product.discount_type === 'percentage'}
                  <span class="discount-percentage discount-product">{$product.discount_percentage|intval(string_format:"%d")}</span>

I've cleared the cache as well.

Here's the file path: public_html/themes/metromarket/templates/catalog/_partials/miniatures/product.tpl

Line 106.

Prestashop version 1.7.7.2. 

PHP version 7.2.

I'm using Opera.

Thanks again!

Link to comment
Share on other sites

Hey guys, sorry for the double post, could I ask you to give it a second look? Maybe something might occur to you but I've still to figure out how to solve this because I really can't suspect what might be the problem. The solution seems incredibly simple but after triple checking I seem to be doing exactly as asked and the problem continues. 

I can only suspect maybe it has to do with this version of Prestashop in particular or the theme I'm using. 

Link to comment
Share on other sites

Hey, update. I deleted all the contents on public_html/themes/metromarket/templates/catalog/_partials/miniatures/product.tpl file, saved the file, deleted the cache, CTRL + F5 on a product page with 25,15% discount and nothing changed. So I'm guessing this is the wrong file. I've been trying different files but there are a lot of them.

Any ideas which one it could be?

Link to comment
Share on other sites

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...