Post by virtualgadjo » Mon Jan 15, 2018 12:11 am

Hi all,
i'm running into a funny little problem....
working on a french shop i'd like to localize prices too, of course, only on the front side as every calculation has to be done the international way
honestly, it's quite simple to acheive with php number_format function

Code: Select all

number_format($number, 2, ',', ' ')
//or
number_format($number, 2, ',', ' .')
//would format 1,200.00 into 1 200,00 or 1.200,00
but i can't find out where to add this, be it with vqmod ou directly in core files... depending on the displayed language
this is a bit curious as, except from this, the multilanguage seems to work quite well, it's simply lacking a number formatting option either in the localisation/language page or in the country one like there is an address formatting option
beleive me guys, french people will find 1,200.00 price tag really weird :)

thanks a lot for any insight on this subject
have a great day

Newbie

Posts

Joined
Wed Dec 13, 2017 4:45 pm

Post by straightlight » Mon Jan 15, 2018 1:46 am

No OC version posted. system/library/cart/currency.php file.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by virtualgadjo » Mon Jan 15, 2018 6:33 pm

Hi Straightlight,

and once more, thanks a lot for taking time to answer

i'm using opencart 3 but i think this is a problem concerning every version and, unfortunately, not only the cart but every price displayed in lists, grids or single products pages
(there is another problem with the admin/model/localisation/currency.that sends a division by zero line 141 solved by changing

Code: Select all

// line 140
if ((float)$value < 1 && isset($line[$i + 1]) )
// into
if ((float)$value < 1 && isset($line[$i + 1]) && $line[$i + 1] != 0 )
but "today" the problem is quite different)

so far, i solve this using javascript

Code: Select all

$(document).ready(function(){
	var lgg = $("html").attr("lang");
	if ( lgg == 'fr') {
		$('div.price, li.product-price').each(function(i,el){
			var prix = $(el).html();
			prix     = prix.replace(/,/g, "");
			prix     = parseFloat(prix);
			var frp  = new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(prix);

			$(el).html(frp);
		});
	}
});
and it works fine even if honestly it's a bit savage and it's really strange that this is not a standard option coming with the country management as not every customer happens to be at their ease with different number notations :)

fortunately, for this shop i won't have to use a price modification by option module even if, well, i would simply have to add a function to do this on "div.price update", just a little more savage :D

thanks again for your help
have a great day
chris

Newbie

Posts

Joined
Wed Dec 13, 2017 4:45 pm

Post by straightlight » Tue Jan 16, 2018 6:14 am

Take note that this method can also create issues with cached currencies, however.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by virtualgadjo » Tue Jan 16, 2018 4:59 pm

Hi Straightlight,

and thanks again for your answer

i'm aware this method is not ideal at all, that's why i think opencart should offer a native way to display prices depending on the country/language, that would greatly help its spreading in different language countries to my mind

coming to this cache thing, as this js works on the front side, whichever price is displayed, it will be the fr way as it's changed on the fly
now the problem will occur when for any reason you will have to update the price, options, quantities, and so on, not impossible to achieve at all but it would need to tweak each situation one by one...

i'm probably going to post a few things in the suggestion forum if there is one
as you may have seen i'm a oc newbie coming from, don't hit me :) prestashop..., i won't go back but if oc really wants to compete there are little things like this one that should be taken into account particularly when they are pretty simple in an mvc environment...

have a great day

PS another little bug, a forum one, the notify me checkbox is checked and i don't receive any notification (not in my spam folders either and my mail is the right one)

Newbie

Posts

Joined
Wed Dec 13, 2017 4:45 pm

Post by virtualgadjo » Tue Jan 16, 2018 6:03 pm

Hi again,

just a word to say that, coming to french prices, once more, the guys behing journal gave me a far better solution...
catalog/language/your-language/your-language.php
and change the decimal and thousand points... done and it works perfectly
this doesn't solve every country price displaying issue like japanase that need the yen symbol before the price itself but at least, it allows to format numbers

(i've worked on a 9 language website, including chinese, japanese and russian that made me a little aware of various displaying things, dates, prices... issues :))

have a great day

Newbie

Posts

Joined
Wed Dec 13, 2017 4:45 pm
Who is online

Users browsing this forum: No registered users and 74 guests