cricket-hockey Posted March 13, 2020 Share Posted March 13, 2020 Hi, I'd like to change the product flag discount text from a percentage to an amount. Is this possible? So in this example, it would say "Save £3.60" rather than "-30%" Can someone point me to the right file to do this? Thanks Link to comment Share on other sites More sharing options...
cricket-hockey Posted March 14, 2020 Author Share Posted March 14, 2020 Sorry, I probably should have said that I am using Prestashop 1.7.6.4 Link to comment Share on other sites More sharing options...
cricket-hockey Posted March 17, 2020 Author Share Posted March 17, 2020 I've finally worked this out incase anyone else needs to know. I changed the following in /src/Adapter/Presenter/Product/ProductLazyArray.php from if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], to if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_amount_to_display'], Ideally I would like to remove the minus sign infront of the price and add the word "SAVE" before it. Does anyone know how I can do this please? 1 1 Link to comment Share on other sites More sharing options...
JBW Posted March 18, 2020 Share Posted March 18, 2020 Actually you can simply controll it directly on the product setting: Link to comment Share on other sites More sharing options...
cricket-hockey Posted March 18, 2020 Author Share Posted March 18, 2020 Thanks, but I wanted to keep that as a percentage on the backend, because it is a lot easier to set prices that way. If I want to do a 30% sale, I can just set all products to 30% off, rather than having to adjust every price. But on the front end I prefer to show the amount saved. Now I just need to find out how to remove the minus sign on the flag. Does anyone know? Link to comment Share on other sites More sharing options...
Luis C Posted March 18, 2020 Share Posted March 18, 2020 Try something like this on the template: {$your_variable|substr:1} Link to comment Share on other sites More sharing options...
Travel the World Posted May 26, 2020 Share Posted May 26, 2020 Hi I'd like to do this the other way around. I would like to convert amount to percentage only. I configured my products to be amount discounted but would like to display percent. However when I tried to change the code: if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], ); } elseif ($this->product['discount_type'] === 'amount') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], ); } else { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->translator->trans('Reduced price', array(), 'Shop.Theme.Catalog'), ); } } It gives me this: Link to comment Share on other sites More sharing options...
Luis C Posted May 26, 2020 Share Posted May 26, 2020 1 hour ago, Travel the World said: Hi I'd like to do this the other way around. I would like to convert amount to percentage only. I configured my products to be amount discounted but would like to display percent. However when I tried to change the code: if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], ); } elseif ($this->product['discount_type'] === 'amount') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], ); } else { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->translator->trans('Reduced price', array(), 'Shop.Theme.Catalog'), ); } } It gives me this: That's because Prestashop WON'T do the math to switch from ₽1,720 to the actual discount percentage. It uses the input value and outputs formatting it with a % symbol. You should try making the math yourself, then passing the variable to the array. Just use the correct variables. You need numeric variables, it will probably crash if you use string type variables, but give it a try. (can't try this one myself right now, and will probably not work) } elseif ($this->product['discount_type'] === 'amount') { $productDiscountperc = $this->product['discount_amount_to_display']/$this->product['price']*100; $flags['discount'] = array( 'type' => 'discount', 'label' => '-'.$productDiscountperc.'%', ); } else { 1 Link to comment Share on other sites More sharing options...
Travel the World Posted May 26, 2020 Share Posted May 26, 2020 I think I did it! 5 hours ago, Luis C said: That's because Prestashop WON'T do the math to switch from ₽1,720 to the actual discount percentage. It uses the input value and outputs formatting it with a % symbol. You should try making the math yourself, then passing the variable to the array. Just use the correct variables. You need numeric variables, it will probably crash if you use string type variables, but give it a try. (can't try this one myself right now, and will probably not work) } elseif ($this->product['discount_type'] === 'amount') { $productDiscountperc = $this->product['discount_amount_to_display']/$this->product['price']*100; $flags['discount'] = array( 'type' => 'discount', 'label' => '-'.$productDiscountperc.'%', ); } else { Thank you! I managed with this: elseif ($this->product['discount_type'] === 'amount') { $productDiscountperc = round($this->product['reduction']/$this->product['price_without_reduction']*100, 0); $flags['discount'] = array( 'type' => 'discount', 'label' => '-'.$productDiscountperc.'%', ); } else { $flags Link to comment Share on other sites More sharing options...
Luis C Posted May 26, 2020 Share Posted May 26, 2020 1 minute ago, Travel the World said: I think I did it! Thank you! I managed with this: elseif ($this->product['discount_type'] === 'amount') { $productDiscountperc = round($this->product['reduction']/$this->product['price_without_reduction']*100, 0); $flags['discount'] = array( 'type' => 'discount', 'label' => '-'.$productDiscountperc.'%', ); } else { $flags Awesome! I'm glad I wasn't "too" wrong 😜 1 Link to comment Share on other sites More sharing options...
cricket-hockey Posted May 26, 2020 Author Share Posted May 26, 2020 I'd still like to be able to remove the minus sign from before the discounted percent or amount. Does anyone know how to do that? So it shows "save £50" instead of "save -£50" etc Link to comment Share on other sites More sharing options...
Luis C Posted May 26, 2020 Share Posted May 26, 2020 24 minutes ago, cricket-hockey said: I'd still like to be able to remove the minus sign from before the discounted percent or amount. Does anyone know how to do that? So it shows "save £50" instead of "save -£50" etc What you want to do, as I stated previously, can be done via template (and I'd say it's the best practice since it doesn't involve changing core or overriding anything) You need to locate in your template file (product template or product miniature template depending on where you want to apply the change) the code where you output your discount. AFAIK, flags should be output using {$flag.label} so if yours got the text "save -XX" you should be able to find something like {l s='save'.........} {$flag.label}. If that's the case you can just do the following: {if $flag.type == 'discount'}{$flag.label|substr:1}{else}{$flag.label}{/if} However, if your string is formed elsewhere, you should do the substr there. Link to comment Share on other sites More sharing options...
cricket-hockey Posted May 26, 2020 Author Share Posted May 26, 2020 I see now! Worked a treat - thanks! 1 Link to comment Share on other sites More sharing options...
M R Hidayatulloh Posted December 28, 2020 Share Posted December 28, 2020 Try this Quote {l s='Save %percentage%' d='Shop.Theme.Catalog' sprintf=['%percentage%' => $product.discount_percentage_absolute]} Link to comment Share on other sites More sharing options...
Interlumen Posted December 27, 2021 Share Posted December 27, 2021 Dnia 17.03.2020 o 6:03 PM, cricket-hockey napisał: I've finally worked this out incase anyone else needs to know. I changed the following in /src/Adapter/Presenter/Product/ProductLazyArray.php from if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_percentage'], to if ($show_price && $this->product['reduction']) { if ($this->product['discount_type'] === 'percentage') { $flags['discount'] = array( 'type' => 'discount', 'label' => $this->product['discount_amount_to_display'], Ideally I would like to remove the minus sign infront of the price and add the word "SAVE" before it. Does anyone know how I can do this please? And how to make the cart the same as in the product card? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now