Programmatically set default currency
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 2
- Joined: 18 Nov 2021, 14:41
Programmatically set default currency
Good day,
We are working on creating an extension.
The extension supposed to be able handle
1. Checking user IP and use 3rd party API to detect country + currency code (done)
2. Customize Admin Panel to handle VAT in each product by different country/currencies (done)
3. Implement VAT rule + calculation (done, using https://aimeos.org/docs/latest/provider ... figuration)
4. Match user local currency to product object (stuck, need help)
So we need help on step 4.
Our idea to inject through product object (see code below)
In the controller, we can do something like this to override currency in the manager instance and automatically adjust the price according to the currency variable value.
However when I tried to do same logic on the apply method, it's not working as expected.
Can you advise how can we do this properly?
Any advice would be appreciated
Thanks
We are working on creating an extension.
The extension supposed to be able handle
1. Checking user IP and use 3rd party API to detect country + currency code (done)
2. Customize Admin Panel to handle VAT in each product by different country/currencies (done)
3. Implement VAT rule + calculation (done, using https://aimeos.org/docs/latest/provider ... figuration)
4. Match user local currency to product object (stuck, need help)
So we need help on step 4.
Our idea to inject through product object (see code below)
Code: Select all
public function apply( \Aimeos\MShop\Product\Item\Iface $product ) <------- this product object
{
}
Code: Select all
$context = app('aimeos.context')->get();
$context->getLocale()->setCurrencyId('AUD')
$manager = MShop::create( $context, 'catalog' );
$category = $manager->get($id, ['text', 'media', 'product']);
Can you advise how can we do this properly?
Any advice would be appreciated
Thanks
Re: Programmatically set default currency
The way to want to do it is not going to work. Using a rule provider is a good idea to e.g. change the tax rate depending on the country which you've stored in the session after querying the 3rd party API but not for changing the currency.
First of all, you need a multi-currency setup with the available site/language/currency combinations in the Locale > Locale panel and the currency must be part of the URL. After you've done resolving the country and currency, you have to redirect the browser to the correct URL containing the currency so the right locale combination will be used. Then, you can use the rule provider to change the tax rate according to the country setting.
First of all, you need a multi-currency setup with the available site/language/currency combinations in the Locale > Locale panel and the currency must be part of the URL. After you've done resolving the country and currency, you have to redirect the browser to the correct URL containing the currency so the right locale combination will be used. Then, you can use the rule provider to change the tax rate according to the country setting.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 2
- Joined: 18 Nov 2021, 14:41
Re: Programmatically set default currency
Thanks for quick response and explanation
how can I achieve this programmatically in aimeos?
where I should put/call my code so it can persists currency value through entire session without user needed to change it manually through selector?
I already finished on country & currency retrieval through 3rd party API , I just need to inject those values to browser URL.you have to redirect the browser to the correct URL containing the currency so the right locale combination will be used
how can I achieve this programmatically in aimeos?
where I should put/call my code so it can persists currency value through entire session without user needed to change it manually through selector?