Jump to content

3 Decimal Currencies


Recommended Posts

no theme is, that is because Prestashop itself assumes 2 decimal currency and rounds anything past that to 2 decimals, even the default theme is hardcoded for this

 

I replied to an old forum topic which outlines the changes required on PS v1.5 to support 3 decimals.  You would have to search for it but should not be too hard to find. 

Link to comment
Share on other sites

Look at the /themes/default/product.tpl file. There is $priceDisplayPrecision variable which can be set in code, and its default value is 2.

did the changes but nothing. still the same

 

{if !isset($priceDisplayPrecision)}

    {assign var='priceDisplayPrecision' value=3}

{/if}

{if !$priceDisplay || $priceDisplay == 2}

    {assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision)}

    {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL)}

{elseif $priceDisplay == 1}

    {assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, $priceDisplayPrecision)}

    {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL)}

{/if}

 

 

var productPriceWithoutReduction = '{$productPriceWithoutReduction}';

var productPrice = '{$productPrice}';

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

This is pretty sad the way its been implemented, but here is how you support 3 decimal places in Prestashop v1.5. Keep in mind, this is a global site change, so it will impact currencies that are only 2 decimal places. All Prices will be shown with 3 decimals if you make this change.

To summarize, you would need to make the following changes to use a 3 decimal place price. Read below for more details
1) Change the config/defines.inc.php

define('_PS_PRICE_DISPLAY_PRECISION_', 3);
2) Override Tools::ps_round so the precision is switched globally from 2 to 3
3) Search for the usage of string_format, and ensure 3f is used instead of 2f. I only get 2 hits when I search, which is prices.tpl and AdminRangePriceController.php

The detailed explanation
1. Change the config/defines.inc.php
There is a config file named defines.inc.php, which has a setting _PS_PRICE_DISPLAY_PRECISION_
define('_PS_PRICE_DISPLAY_PRECISION_', 2);
This is used by the Tools::displayPrice function in conjunction with the currency format to show the price on a majority of the site. I changed the 2 to a 3 on a local test site and it seems to be working 90%.

2. Override Tools::ps_round
There are still some places where only 2 decimals are showing, and that is because of functions like Product::getPriceStatic and Product::priceCalculation also do decimal formatting, and instead of using the above setting, they hard coded 2. So in the AdminProductsController, where the product price is entered, rounds the price to 2 decimal
Product::getPriceStatic($this->_list[$i]['id_product'], true, null, 2, null, false, true, 1, true);

Those functions just pass the decimal value to Tools::ps_round, so a simple override of the ps_round function, you could do
if ($precision==2) $precision=3
3. Search for the usage of string_format
The last thing I could find is within the actual smarty templates, there is also price formatting. For example, in prices.tpl (which is used to show the admin product price), they are using string_format:'%.2f'
This is taking the 3 decimal price, and formatting it to 2 decimal, so changing it to string_format:'%.3f' fixes that display issue.
I suppose you could just remove the string_format entirely, but that will result in showing the full 6 decimal places

 

is this the one u mean?

Link to comment
Share on other sites

thanks, it did the job

Change the config/defines.inc.php
There is a config file named defines.inc.php, which has a setting _PS_PRICE_DISPLAY_PRECISION_
define('_PS_PRICE_DISPLAY_PRECISION_', 2);
This is used by the Tools::displayPrice function in conjunction with the currency format to show the price on a majority of the site. I changed the 2 to a 3 on a local test site and it seems to be working 90%.

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