default currency depending on language

  • Posts: 70181
  • Thank you received: 10507
  • MODERATOR
7 years 11 months ago #62168

It's in the modules folder.

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
7 years 7 months ago #83663

I did what Nicolas suggested but put it directly in index.php

// Set the currency at the first visit, regarding of the page language

function set_currency($app)
{
  $used_languages = [
    [ "tag" => "en-us", "currency" => 2 ],
    [ "tag" => "ja-JP", "currency" => 3 ],
    [ "tag" => "en-GB", "currency" => 4 ],
    [ "tag" => "en-AU", "currency" => 6 ],
    [ "tag" => "zh-TW", "currency" => 111 ],
    [ "tag" => "ko-KR", "currency" => 145 ] ];

  $lang = JFactory::getLanguage();

  if(!$app->getUserState('com_hikashop.currency_id',0))
    {
      foreach($used_languages as $language)
	{
	  if ($language["tag"] == $lang->get('tag'))
	    {
	      $app->setUserState('com_hikashop.currency_id', $language["currency"]);
	      header('Location: '.$_SERVER['REQUEST_URI']);
	      exit(0);
	    }
	}
    }
}

and called the function here :
// Dispatch the application.
$app->dispatch();

set_currency($app);

// Mark afterDispatch in the profiler.
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;

I think this is the good way to do, you help the user the first time and after you let him free to choose which couple language/currency he wants.

Last edit: 7 years 7 months ago by Stéphane Corbé. Reason: Format
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
6 years 10 months ago #124416

Hello, please where should i put the code ?

When i put both into index.php / template.php i got blank page (i'm using yootheme template)

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
6 years 10 months ago #124445

Oh I forgot, i'm using joomla 3 language translations, not falang.

Please any suggestion ?

Last edit: 6 years 10 months ago by Karloz.

Please Log in or Create an account to join the conversation.

  • Posts: 24318
  • Thank you received: 3749
  • MODERATOR
6 years 10 months ago #124547

Hi,

It does not ask for Falang.
You have to put it in the Joomla index.php file, at the website root folder.

I don't understand why you put it in your "template.php" file.

If you got a blank page, it means that you wrote something wrong in PHP. Check your PHP log to have more details of the error.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
6 years 10 months ago #124559

Oh i see, i was putting it in the template file - index.php / template.php

Anyway it still doesn't work when i put the code in the root index.php, no currency changes, nothing in log
I changed the language tags and currency id's.

Is there something else what has to be done ? Like currency module visible or ... ?

Last edit: 6 years 10 months ago by Karloz.

Please Log in or Create an account to join the conversation.

  • Posts: 24318
  • Thank you received: 3749
  • MODERATOR
6 years 10 months ago #124565

Hi

// Set the currency at the first visit, regarding of the page language

If you are sure you made the right modifications, it should set the currency depending the langue on the first visit.
To test it, clean your cookies. You have to open the website like if you was the first time.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
6 years 10 months ago #124569

All the time I thought it will be changing the currency along with language switcher, doesn't it ?
Not just for the first visit, i thought for that is the geolocation plugin.

Please how could i be changing the currency together with joomla language switcher module ?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2319
  • MODERATOR
6 years 10 months ago #124678

Hi,

You can create a little system plugin which will be called at each page load to change the currency depending on the language.
The code in a previous post can be used and adapted for your needs.
It require php knowledge.

Please Log in or Create an account to join the conversation.

  • Posts: 45
  • Thank you received: 0
6 years 10 months ago #124724

Well i guess it would be better to integrate the changes into language switcher to be able to alternate the currency via currency switcher then as well.

Its also because we are using Joomla articles to display products, where the currency module doesn't affect displayed price.
And currency switcher is displayed just on the checkout page.

Anyway thank you very much.

Please Log in or Create an account to join the conversation.

  • Posts: 15
  • Thank you received: 0
6 years 10 months ago #124758

integrate the changes into language switcher


I would be interested in this solution too, if possible.

Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 126
  • Thank you received: 7
4 years 2 months ago #242417

I came across this requirement for my Swiss website where I needed to change the currency depending on de-DE (German German) or de-CH (German Swiss). If German prices to be shown in Euros, if Swiss prices to be shown in Swiss Francs (CHF).

Fortunately, I found this thread! Anyway, I've created a small plug-in called: CurrencyFollowsLanguage which simply maps a system language tag to a hikashop currency ID. You can set up these maps (up to 10, easily extended), in the plugin backend.

Zip file of the plug-in attached.

Attachments:
The following user(s) said Thank You: dyvel

Please Log in or Create an account to join the conversation.

Time to create page: 0.103 seconds
Powered by Kunena Forum