Jump to content

Base price rounded in 3 decimal places


Recommended Posts

and you would like to display three decimal places for your products?

 

My understanding is that native PS does not display three decimal places without modification.

 

However when you input your euro retail price, let's say 9.446 and save, PS will round the price to 9.45 (in the back office), which is then reflected in the front office.

Link to comment
Share on other sites

  • 5 months later...

Anita,

My solution in post #9 gives a solution for (category-) product lists, individual products, and summary when checking out:

edit file /config/defines.inc.php:

define('_PS_PRICE_DISPLAY_PRECISION_', 3); <-- change 2 into 3 here

 

and save the file.

 

 

I noticed however that the Home Featured Products and best sellers - lists still keep 2 decimals...

 

To solve this:

- Home featured/specials products:

Edit file themes/<your theme folder>/modules/homefeatured/homefeatured.tpl (Make backup!)

find (using Ctrl-F): $product.price

 

<a class="lnk_more" href="{$product.link|escape:'html'}" title="{l s='View' mod='homefeatured'}">{l s='View' mod='homefeatured'}</a>
{if $product.show_price AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p class="price_container">
<span class="price">{if !$priceDisplay}{displayPrice price={convertPrice price=$product.price}}{else}{displayPrice price={convertPrice price=$product.price_tax_exc}}{/if}</span></p>{else}<div style="height:21px;"></div>{/if}
 
Add the red code. (Don't forget the closing '}'  )

 

save the file

 

for bestsellers:

Edit file themes/<your theme folder>/modules/blockbestsellers/blockbestsellers.tpl (Make backup!)

find (using Ctrl-F): $product.price

 
<p>
<a href="{$product.link|escape:'html'}" title="{$product.legend|escape:'htmlall':'UTF-8'}">
{$product.name|strip_tags:'UTF-8'|escape:'htmlall':'UTF-8'}<br />
<span class="price">{displayPrice price={convertPrice price=$product.price}}</span>
</a></p>
 
Add the red code. (Don't forget the closing '}'  )

 

save the file

 
See if it works.
 
Hope it does, let me know.
pascal.
Link to comment
Share on other sites

Thanks, Pascal. But.. when I only make that single change, I can indeed enter the price in 3 decimals, but on save it dissapears and is rounded back to 2 decimals again?

Strange thing is, that in the prod. list it does stay in 3 decimals btw..

 

Now, IF it would calculate anyway with the entered 3 decimals, it would be fine, but it doesnt, I tested it.

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

Hmm, yes, it rounds off when getting the value (in the database, the 3 decimals are there, but getting the value corrupts it...

 

May take some time to find out where this goes wrong...

Will be hopefully tomorrow (It's 2:13 AM here, so I quit for today) that I have some time for it.

 

For now, checking out,

pascal.

Link to comment
Share on other sites

Hi Anita,

after 2 hours trying to change files, I think I have "found the light" (oh well, a "quick fix" I mean)

 

Can you try the following:

 

Edit file classes/Tools.php   (Make backup!)

 

In there, there is a function:

	public static function ps_round($value, $precision = 0)
	{
		static $method = null;

		if ($method == null)
			$method = (int)Configuration::get('PS_PRICE_ROUND_MODE');

		if ($method == PS_ROUND_UP)
			return Tools::ceilf($value, $precision);
		elseif ($method == PS_ROUND_DOWN)
			return Tools::floorf($value, $precision);
		return round($value, $precision);
	}

please add the red code, inside this function:

	public static function ps_round($value, $precision = 0)
	{
		static $method = null;
                if ($precision == 2)  /* !!!Pas, quick fix for 2 decimals to variable decimals */
                        $precision = _PS_PRICE_DISPLAY_PRECISION_;
		if ($method == null)
			$method = (int)Configuration::get('PS_PRICE_ROUND_MODE');

		if ($method == PS_ROUND_UP)
			return Tools::ceilf($value, $precision);
		elseif ($method == PS_ROUND_DOWN)
			return Tools::floorf($value, $precision);
		return round($value, $precision);
	}

Please try if this works for you!

I did change other things as well, but I think only for 'display' on a few places, not calculate (i.e. show only 2 decimals -> changed to more decimals). I wrote down my changes, so if it's not working yet, let me know, then I can try to tell you what else to change.

 

 

Let me know,

pascal

Link to comment
Share on other sites

Hi Pascal,

 

What I did was:

- check if the products accept the 3 decimals,

-- in the item itself (screen prices) it rounds. But, in the list of products its correct with the entered 3 decimals

- enter an order trough the BO

-- works correct and displays correct

- enter an order trough the FO

-- ditto

- print a standard invoice

-- all ok

- print an invoice trough M4PDF

-- unfortunality that is not 100% correct'in the row with the product (item detail) it rounds off, displaying the 3th decimal as a "0":. but then in the taxes row it does calculate and display correctly. I asume I will have to drop this at the programmer of this module?

 

Is it possible to have totals with only 2 digits?

 

But; sofar, its 200% better then what I saw in any other topic at the forums, many thanks sofar, you are brilliant!

Link to comment
Share on other sites

I've worked some with currencies, smart pricing, and have been lurking on this thread since you posted.  Mostly as I find currencies interesting.  I've seen others that have tried this but this is the first I've seen that seems to be working or getting close.

 

pascaIVG...is a rock star!

Link to comment
Share on other sites

Hi Anita,

I can have a quick look at the module. Please Private Message (PM) me the zipped module and I have a quick look at it. (I'll throw away the files afterwards :-)   )

Or Email me: [email protected]

 

Not fully clear to me from your comment if there is now still a problem in what you said here:

 in the item itself (screen prices) it rounds.

 

Does it round IN-correctly here? If there's still a problem here, please let me know where exactly. (Maybe add screenshot)

 

 

Please tell me which page(s) you would like to have only 2 decimals. Then we can try to fix this.

 

 

pascal

Link to comment
Share on other sites

Pascal, I have to agree with El Patron... There have bene several others who tried to fix this, and then one had to do a ton of changes and the result was nopt atleast correct. You really came further then all the others! Or, as a mather a fact, basically you fixed it, only some minor details would be nice to be changed:-)

 

About the roundingd; yes.. it rounds correct!

 

I think it should only give 2 decimals, correctly rounded in the total rows, and on the output. So,

-output for invoices/credits (and other docs that use that, I dont use more)

- shopping cart summery 2 decimals in total on the rows and grand total (FRONT OFFICE)

- when entering an order in the backoffice, it only gives 2 decimals during order entry (correct roundings) but at the end, in the totals, it gives 3 decimals again. Would be nice to have 2 decimals there also, but to me thats not so important. As long as the output has 2.

 

Pascal, have to say, even if you cant change these total decimals, I am happy anyway!!

 

I will send the module to you by mail.

Link to comment
Share on other sites

Hi Anita,

a few questions:

- Do you use the PDF invoices, or plain text ones?

- is your 'credit' the same as PrestaShop's "Order Return"?

- Do you use 5 step checkout, or 1 step checkout?

- Do you use shipping, and if so, does this one need to be 2 decimals as well in the checkout summary?

- You talk about adding an Order in the Back Office, and then "at the end, in totals, it gives 3 decimals again". Can you add some screenshot where exactly this is?

 

 

pascal. 

Link to comment
Share on other sites

Hi Pascal,

 

- I use the PDF invoices from the module we spoke about

- right now we dont have credits.. I can imagen in the future it will be needed, but as there wont be any stock return (as the goods sold are consumables, herbs) it will be a credit, not a return. Also, again, printed trough this M4PDF module.

- 5 step checkout

- yes, thats cosmetically wise the best:)

- see http://www.sunbeam-raceworld.nl/pics%20presta.html

(no clue how else to upload pics here!)

1st pic; order entry screen BO before entering a qty to a product, price gives 3 decimals

2nd pic; qty of 10 added, decimals=2, rounded correctly

3th pic; confirming the order, succenly everywhere 3 decimals showing

4th; overview orders trough BO

(

 

Hope this helps:)

 

Anita

Link to comment
Share on other sites

  • 10 months later...

How many decimals do you want it to be??

 

N.B!!!  Be careful with rounding off BTN, as their value is (at the moment of writing) pretty high, so decimals are pretty significant:

0.21 BTN = 261.43 Zl

0.2160 BTM = 268.90 Zl   (difference of about 3%)

rounded off:

0.22 BTN: = 273.88 Zl (difference 0.01 BTN in this case can be up to 4.7%! Product almost 5% more expensive!)

 

pascal

Link to comment
Share on other sites

Really thank you for reply!

I want price rounded in 4 or 5 (it's not that important) decimal places.

As i said, the problem is price on card product with attributes - display decimals work fine but rounding not.



I know about bitcoin value :D


edit.

OK! I know how change it ! :D

Here themes > default > js > product.js  I change all "2" on "5" :P

TA DA!!!

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

×
×
  • Create New...