price number format

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
agatqapp
Posts: 13
Joined: 15 Jan 2022, 07:02

price number format

Post by agatqapp » 07 Jul 2022, 08:21

Hello sir

I use laravel aimeos version
aimeos/aimeos-core 2021.07.*
php ~7.1||~8.0

I want to show product price for all currencies with 2 digit decimal like rigtnow
but for IRR currency without decimal number only integer
like if price is 100.65 USD which are equal to 4262527.50 IRR
so in usd it should be 100.65 but for IRR it should be 4262527

I found a artical
mshop/price/manager/precision => 0
but this will convert price as integer for all currencies
but i need for only one currency

Thanks

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: price number format

Post by aimeos » 07 Jul 2022, 11:43

Interesting question :-)

The number format is generated by the PHP Intl extension and based on the locale (=language) that's used, not on the currency:
https://www.php.net/manual/en/class.numberformatter.php

You can see the code for formatting numbers here:
https://github.com/aimeos/aimeos-base/b ... Locale.php

The PHP number formatter class has a lot of constants that can be used. Maybe you can find a combination the works and post it here so we can add it to the Aimeos view helper.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

agatqapp
Posts: 13
Joined: 15 Jan 2022, 07:02

Re: price number format

Post by agatqapp » 08 Jul 2022, 09:04

Hello

I changed a code line in a file
vendor\aimeos\aimeos-core\lib\mshoplib\src\MShop\Price\Manager\Standard.php

$this->precision = $context->getConfig()->get( 'mshop/price/precision', 2 );

to

$locale = $this->getContext()->getLocale();
if($locale->getCurrencyId() !== null && $locale->getCurrencyId() == 'IRR'){
$this->precision = '0';
}else{
$this->precision = $context->getConfig()->get( 'mshop/price/precision', 2 );
}

it is working according to our requirement.
for IRR price integer and for other currencies with decimal number,
is it ok?

Thanks

User avatar
aimeos
Administrator
Posts: 8636
Joined: 01 Jan 1970, 00:00

Re: price number format

Post by aimeos » 08 Jul 2022, 09:09

It may work for you if you overwrite the price manager class in your own extension (don't change the core files!) but it's not a common solution. Configuring the PHP NumberFormatter class correctly is the only solution we can integrate into the Aimeos core.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply