Radu Posted April 20, 2010 Share Posted April 20, 2010 in classes/Tools.phpfor a quick fix just replace switchLanguage function with this one, making sure you edit the id's bellow with your own needs: static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... $cookie->id_currency = 2; //change the currency too, the currency that has the id 2 self::setCurrency(); break; case 2: //and so on .... $cookie->id_currency = 1; self::setCurrency(); break; case 3: $cookie->id_currency = 1; self::setCurrency(); break; case 4: $cookie->id_currency = 4; self::setCurrency(); break; } } } Link to comment Share on other sites More sharing options...
uddhava Posted April 20, 2010 Share Posted April 20, 2010 I hope you posted this also in the Tracker..?If not, then please do. Link to comment Share on other sites More sharing options...
ugur onur Posted June 27, 2010 Share Posted June 27, 2010 Thanks Radu, You are the best... :-) Link to comment Share on other sites More sharing options...
chris2407 Posted September 24, 2010 Share Posted September 24, 2010 Can somebody please help me? i tried this but always get following error: Parse error: syntax error, unexpected T_PUBLIC, expecting T_VARIABLE in /kunden/286138_22145/webseiten/classes/Tools.php on line 208this i did put into the tools.php static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... $cookie->id_currency = 3; //change the currency too, the currency that has the id 2 self::setCurrency(); break; case 2: //and so on .... $cookie->id_currency = 1; self::setCurrency(); break; case 3: $cookie->id_currency = 1; self::setCurrency(); break; case 4: $cookie->id_currency = 1; self::setCurrency(); break; case 5: $cookie->id_currency = 1; self::setCurrency(); break; } } } Link to comment Share on other sites More sharing options...
Son Phan Posted January 17, 2011 Share Posted January 17, 2011 Hi chris2407, You should check the id from the language and set the currency related to this language also. Try it again and let me know the result. Cheers, Son Phan Link to comment Share on other sites More sharing options...
Caleydon Posted April 13, 2011 Share Posted April 13, 2011 ... but if you want to change currency in the Bankwire payment, the currency can't be changed. Link to comment Share on other sites More sharing options...
weit Posted June 26, 2011 Share Posted June 26, 2011 Many thanks for a simple solution! Link to comment Share on other sites More sharing options...
outlet.ee Posted August 7, 2011 Share Posted August 7, 2011 Thank you, it is a simple solution but it actually forces the currency to match with the language. so if the user wants to change to another currency, there is no way of doing it? Link to comment Share on other sites More sharing options...
Olórin Posted September 10, 2011 Share Posted September 10, 2011 Why it's not possible to change currency after? I would like to let the possibily to change currency after, not to "force" to this currency... Thank you for you help! Link to comment Share on other sites More sharing options...
dragon123 Posted December 7, 2011 Share Posted December 7, 2011 ... but if you want to change currency in the Bankwire payment, the currency can't be changed. I would like to know how to change it also, I want to process all my payments in Default currency, and I don't seem to be able to find the information in the forum. Link to comment Share on other sites More sharing options...
Rolige Posted December 16, 2011 Share Posted December 16, 2011 ... but if you want to change currency in the Bankwire payment, the currency can't be changed. Hello, anyone could make this possible? Link to comment Share on other sites More sharing options...
dragon123 Posted December 16, 2011 Share Posted December 16, 2011 This is what I did in my moneris credit card payment processing that I am writting: // check currency of payment and force to Canadian dollar*********************** if ($currency_order->id != 4) { $cookie->id_currency = 4; $cart->id_currency = 4; $cart->update(); } All credit card payments have to be processed in Canadian $ in my case, so I am forcing the currency to 4 (Cdn$). I hope this helps. Link to comment Share on other sites More sharing options...
tomerg3 Posted December 16, 2011 Share Posted December 16, 2011 We have a module "Location Detection" (http://www.prestashop.com/forums/index.php?/topic/35119-module-location-detection-detect-the-location-of-a-visitor-using-their-ip-address-and-automatically-redirect-them-to-the-matching-language/) that opens up the shop in the customer's language (based on their IP or browser language), and also has the ability to link a flag to a currency. You can still change the currency, as it only "links" them when you click on the language flag Link to comment Share on other sites More sharing options...
Rolige Posted December 17, 2011 Share Posted December 17, 2011 Thats module is very good, i donwloaded one but dont work on ps 1.4, i see than ps 1.4 compatible have a little cost, im starter with this o hope buy this soon, thanks tomerg3 Link to comment Share on other sites More sharing options...
devein Posted August 26, 2012 Share Posted August 26, 2012 (edited) Why it's not possible to change currency after? I would like to let the possibily to change currency after, not to "force" to this currency... Thank you for you help! yes, I have seen this problem as well. description: before chris2407 's hack - changing language - currency does not change - changing currency - language does not change after chris2407 's hack - changing language - currency changes - changing currency - PROBLEM - currency does not change (PS 1.4) I dont know PS always calls switchLanguage() and setCookieLanguage() on every page load. Clicking on currency calls changecurrency.php via AJAX call which then changes cookie value of id_currency I have resolved the problem using additional cookie value in changecurrency.php, so the moment of changing currency can be detected :> my complete solution (based on chris2407 mod) changecurrency.php (added lines in bold) $cookie->id_currency = (int)($currency->id); $cookie->id_currency_changed = 1; die('1'); Tools.php (complete functions, I have added second function) static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... self::switchCurrencyLinked(3); break; case 6: //and so on .... self::switchCurrencyLinked(4); break; } } } static public function switchCurrencyLinked($cookieLanguage) { global $cookie; if (! (int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; self::setCurrency(); } else { $cookie->id_currency_changed = 0; } } good luck! PS debug problems in prestashop by enabling errors in config.inc.php : @ini_set('display_errors', 'on'); and then in any php file print variables using trigger_error trigger_error("variable dump".print_r($var)); Edited May 30, 2013 by devein (see edit history) 3 Link to comment Share on other sites More sharing options...
Trip Posted August 27, 2012 Share Posted August 27, 2012 In general I hope the way prestashop handles currencies should be enhanced. I did not check the behaviour in 1.5. so far but it would be much better to not store currencies in a cookie(ot at least not only). There should be a least the possibility to attach a default currency per country/language/store view. As search engine do not accept cookies there are problems with the current behaviour. For example if I enable geolocation module the google bot will be determined as USA based therefore the prices are served in $US. As google uses currencies as a signal to taget the audience of the site I might loose some seo points for my others "views" Best behaviour in my opinion would be: bot crawls www.mysite.com/us/... -> $us would be triggered www.mysite.com/au/... -> $AUS would be triggered www.mysite.com/de/... -> € would be triggered www.mysite.com/uk/... -> pound would be triggered This structure would also protect protect duplicate content issiues as google bot can clearly see the target country. It should not be a problem to serve the same content under diffenrent countries as it is clear different countries are targeted. Sorry, maybe a little bit of topic but I think every one running an international site should be aware of such problems. I already posted that on the but tracker http://forge.prestashop.com/browse/PSCFI-6155 and related to the issue http://forge.prestashop.com/browse/PSCFI-2951 Regards, trip 1 Link to comment Share on other sites More sharing options...
thomaskramer Posted October 4, 2012 Share Posted October 4, 2012 I cant get it to work in prestashop 1.5 ? Everything ends up in a big mess.. Can anyone helt? 1 Link to comment Share on other sites More sharing options...
pepperr Posted October 27, 2012 Share Posted October 27, 2012 Thank you that works perfect on 1.4.8.2 yes, I have seen this problem as well. description: before chris2407 's hack - changing language - currency does not change - changing currency - language does not change after chris2407 's hack - changing language - currency changes - changing currency - PROBLEM - currency does not change (PS 1.4.8.2) I dont know PS always calls switchLanguage() and setCookieLanguage() on every page load. Clicking on currency calls changecurrency.php via AJAX call which then changes cookie value of id_currency I have resolved the problem using additional cookie value in changecurrency.php, so the moment of changing currency can be detected :> my complete solution (based on chris2407 mod) changecurrency.php (added lines in bold) $cookie->id_currency = (int)($currency->id); $cookie->id_currency_changed = 1; die('1'); Tools.php (complete functions, I have added second function) static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... self::switchCurrencyLinked(3); break; case 6: //and so on .... self::switchCurrencyLinked(4); break; } } } static public function switchCurrencyLinked($cookieLanguage) { global $cookie; if (! (int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; self::setCurrency(); } else { $cookie->id_currency_changed = 0; } } good luck! PS debug problems in prestashop by enabling errors in config.inc.php : @ini_set('display_errors', 'on'); and then in any php file print variables using trigger_error trigger_error("variable dump".print_r($var)); Link to comment Share on other sites More sharing options...
antonpetr Posted December 7, 2012 Share Posted December 7, 2012 This is working perfectly on 1.4.8.2! Superb job! Thank you devein! yes, I have seen this problem as well. description: before chris2407 's hack - changing language - currency does not change - changing currency - language does not change after chris2407 's hack - changing language - currency changes - changing currency - PROBLEM - currency does not change (PS 1.4.8.2) I dont know PS always calls switchLanguage() and setCookieLanguage() on every page load. Clicking on currency calls changecurrency.php via AJAX call which then changes cookie value of id_currency I have resolved the problem using additional cookie value in changecurrency.php, so the moment of changing currency can be detected :> my complete solution (based on chris2407 mod) changecurrency.php (added lines in bold) $cookie->id_currency = (int)($currency->id); $cookie->id_currency_changed = 1; die('1'); Tools.php (complete functions, I have added second function) static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... self::switchCurrencyLinked(3); break; case 6: //and so on .... self::switchCurrencyLinked(4); break; } } } static public function switchCurrencyLinked($cookieLanguage) { global $cookie; if (! (int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; self::setCurrency(); } else { $cookie->id_currency_changed = 0; } } good luck! PS debug problems in prestashop by enabling errors in config.inc.php : @ini_set('display_errors', 'on'); and then in any php file print variables using trigger_error trigger_error("variable dump".print_r($var)); Link to comment Share on other sites More sharing options...
cyjambo Posted March 30, 2013 Share Posted March 30, 2013 Hi there, Has anyone solved this for 1.5.3.1? thanks a lot! 1 Link to comment Share on other sites More sharing options...
Carl.Tedford Posted June 10, 2013 Share Posted June 10, 2013 Hello, Any solution for ver. 1.5.3.1 ?! Thanks .. Link to comment Share on other sites More sharing options...
ka8ooi Posted August 26, 2013 Share Posted August 26, 2013 Maybe I solve this for prestashop 1.5.2 -> thx to devein´s and chris2407´s guides bold I added in 1.5.2. -> controllers/front/ChangeCurrencyController.php class ChangeCurrencyControllerCore extends FrontController { /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { $currency = new Currency((int)Tools::getValue('id_currency')); if (Validate::isLoadedObject($currency) && !$currency->deleted) { $this->context->cookie->id_currency = (int)$currency->id; [b] $this->context->cookie->id_currency_changed = 1;[/b] die('1'); } die('0'); } } in classes/Tools.php /** * Set cookie id_lang */ public static function switchLanguage(Context $context = null) { . ...some original code here.... . if (Configuration::get('PS_REWRITING_SETTINGS') || !Language::isMultiLanguageActivated()) unset($params['id_lang']); [b]switch($id_lang) { case 7: //if lang_id that's changed to is = 1 than... self::switchCurrencyLinked(1); break; case 9: //and so on .... self::switchCurrencyLinked(3); break; case 10: //and so on .... self::switchCurrencyLinked(3); break; } [/b] } } [b] /** * New functions by devein * */ static public function switchCurrencyLinked($cookieLanguage) { global $cookie; if (! (int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; self::setCurrency(); } else { $cookie->id_currency_changed = 0; } }[/b] It works for me well 1 Link to comment Share on other sites More sharing options...
varadipeter Posted December 15, 2013 Share Posted December 15, 2013 (edited) Unfortunately the above code is not working on 1.5.6.1 if the language ID is 1. So far I was unable to figure out why Edited December 15, 2013 by varadipeter (see edit history) Link to comment Share on other sites More sharing options...
[email protected] Posted February 3, 2014 Share Posted February 3, 2014 (edited) Works partly for me on 1.5.6.0.Make sure to modify the contents of the Switch to your currency and language id's. So check your id's in the admin / Localisation. To make it work FULLY I actually also moved the switch outside it's container "IF" to make sure it also was default set. Now it works perfectly. The solution is however very hardcoded/ugly, It should be possible to make a solution that only needs a boolean setting to make it happen. Edited February 3, 2014 by [email protected] (see edit history) 1 Link to comment Share on other sites More sharing options...
PEteam Posted June 9, 2014 Share Posted June 9, 2014 (edited) replace with built-in switchLanguage function tested in prestashop 1.5.6 /** * Set cookie id_lang */ public static function switchLanguage(Context $context = null) { if (!$context) $context = Context::getContext(); // Install call the dispatcher and so the switchLanguage // Stop this method by checking the cookie if (!isset($context->cookie)) return; if (($iso = Tools::getValue('isolang')) && Validate::isLanguageIsoCode($iso) && ($id_lang = (int)Language::getIdByIso($iso))) $_GET['id_lang'] = $id_lang; // update language only if new id is different from old id // or if default language changed $cookie_id_lang = $context->cookie->id_lang; $configuration_id_lang = Configuration::get('PS_LANG_DEFAULT'); if ((($id_lang = (int)Tools::getValue('id_lang')) && Validate::isUnsignedId($id_lang) && $cookie_id_lang != (int)$id_lang) || (($id_lang == $configuration_id_lang) && Validate::isUnsignedId($id_lang) && $id_lang != $cookie_id_lang)) { $context->cookie->id_lang = $id_lang; $language = new Language($id_lang); if (Validate::isLoadedObject($language) && $language->active) $context->language = $language; $params = $_GET; if (Configuration::get('PS_REWRITING_SETTINGS') || !Language::isMultiLanguageActivated()) unset($params['id_lang']); switch($id_lang) { case 1: $cookie->id_currency = 1; self::switchCurrencyLinked(1); break; case 4: $cookie->id_currency = 2; self::switchCurrencyLinked(2); break; case 5: $cookie->id_currency = 4; self::switchCurrencyLinked(4); break; } } } public static function switchCurrencyLinked($cookieLanguage) { global $cookie; if (!(int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; self::setCurrency(); } else { $cookie->id_currency_changed = 0; } } Edited June 9, 2014 by PEteam (see edit history) Link to comment Share on other sites More sharing options...
cossamus Posted September 15, 2014 Share Posted September 15, 2014 Hi guys i'm trying to have this workaround working on my 1.6 prestashop but so far coud not get it working. Anyone tested it on 1.6 ? Thanks Link to comment Share on other sites More sharing options...
El Patron Posted September 15, 2014 Share Posted September 15, 2014 with this module http://www.prestashop.com/forums/topic/349727-module-advanced-visitor-language-currency-localization-ietf/ once installed bo-->localization-->countries-->edit country (set default currency that country) then it matches visitor language based on quality factor in http_accept_languages, sets cookies language, then set's currency based on ietf country. This post not so much that I want your to buy module, I'm just like to show my work in this area. , this takes guess work out of localization, as guessing = poor visitor experience. Link to comment Share on other sites More sharing options...
El Patron Posted September 15, 2014 Share Posted September 15, 2014 and on a personal note, changing currency based on language is not advise, my two cents. Link to comment Share on other sites More sharing options...
cossamus Posted September 16, 2014 Share Posted September 16, 2014 Hi, i checked your module before when i was researching this subject. It seems to be perfect for what i want! But i promised myself i wouldn't spend more money on the site until i get some sales and on a personal note, changing currency based on language is not advise, my two cents. Why is that? Can you explain please, i sont see any downside... Link to comment Share on other sites More sharing options...
El Patron Posted September 16, 2014 Share Posted September 16, 2014 Hi, i checked your module before when i was researching this subject. It seems to be perfect for what i want! But i promised myself i wouldn't spend more money on the site until i get some sales Why is that? Can you explain please, i sont see any downside... this is my first 'advanced module' so I am having difficult time explaining (more doc coming soon). Basically you install module, edit each country and assign default currency (using native prestashop) and sleep easier at night. remember, visitor and search engine localization is not about guessing. Link to comment Share on other sites More sharing options...
janoo Posted October 16, 2014 Share Posted October 16, 2014 Hi guys i'm trying to have this workaround working on my 1.6 prestashop but so far coud not get it working. Anyone tested it on 1.6 ? Thanks You can make it work on 1.6 too. I´d started from post #15 in this topic, where Devein modified Chris2407 's first hack hack: http://www.prestashop.com/forums/topic/52019-change-currency-automatically-when-switching-from-one-language-to-another/?do=findComment&comment=910944 Full change to this modification maded for PS 1.5 is now applied to PS 1.6 ( I have 1.6.0.9 but it should work from 1.6.0.0 too ) 1. Make copy of ChangeCurrencyController.php to /override/controllers/front/ChangeCurrencyController.php find: $this->context->cookie->id_currency = (int)$currency->id; change to: $this->context->cookie->id_currency = (int)$currency->id; $this->context->cookie->id_currency_changed = 1; 2. Make copy of Tools.php to /override/classes/Tools.php in public static function switchLanguage find: $language = new Language($id_lang); change to: $language = new Language($id_lang); // added for hard currency linked switch switch($id_lang) { case 1: //if lang_id that's changed to currency id = 1 than... Tools::switchCurrencyLinked(1); break; case 2: Tools::switchCurrencyLinked(2); break; case 3: //and so on .... Tools::switchCurrencyLinked(3); break; } // Immediately after end of function public static function switchLanguage insert new function: /** * Change cookie currency with Language when hard currency linked switch - janoo * */ static public function switchCurrencyLinked($cookieLanguage) { global $cookie; if (! (int)$cookie->id_currency_changed) { $cookie->id_currency = $cookieLanguage; Tools::setCurrency($cookie); } else { $cookie->id_currency_changed = 0; } } Credits goes to Devein and Chris2407. I´d just modified idea to PS 1.6 But don´t forget: make second/third/... currency active! And parse id of language with id of currency precisely. I´d tested it correctly and it worked also in bankwire and similar payments. In bankwire is also currency changer built-in when more currencies are activated. 2 Link to comment Share on other sites More sharing options...
varadipeter Posted November 14, 2014 Share Posted November 14, 2014 $this->context->cookie->id_currency_changed = 1; <<=== change the one to zero and it will work when a) the language_id in the db is "1" the currency_id in the db is "1" c) you manually change the currency in the store Link to comment Share on other sites More sharing options...
Fertechpl Posted June 18, 2015 Share Posted June 18, 2015 (edited) Hello!I'm using prestashop in version 1.6.0.14. I have problem like others is this topic. I want to force change currency when client is changing language. I must tell You that I tried solutions from this and others topics, but without any resoult. Maybe You know solution for that problem? EDIT: SOLVED! Don't know why, but I tried one more time with devein solution and it's working now, but don't know why... I have only strange bug that lang is not changing on first time, only after second click on it. (currency is changing on first click, lol ) Greetings! Edited June 19, 2015 by Fertechpl (see edit history) Link to comment Share on other sites More sharing options...
geotargetplus Posted October 12, 2015 Share Posted October 12, 2015 Working in 1.6.1.1 janoo and mod varadipeter 1 Link to comment Share on other sites More sharing options...
Shashikant N Sharma Posted October 22, 2015 Share Posted October 22, 2015 (edited) This is done simply by placing a simple note on the site to switch currency while paying in Dollar. It is working.. Great module. Thanks for sharing Edited October 22, 2015 by razaro (see edit history) Link to comment Share on other sites More sharing options...
vmiroslava Posted May 5, 2016 Share Posted May 5, 2016 Hi, I have the same problem with the currency how to make it be changed when you change the language, I have several languages Turkish, Italian, English and Romanian? I would be very grateful if you help me! Link to comment Share on other sites More sharing options...
El Patron Posted May 5, 2016 Share Posted May 5, 2016 changing the currency when visitor changes language is really in my opinion, a horrible idea, and should not be done. i do however champion matching currency detect when cookie-->currency not set, i.e. on initial visit. my two cents Link to comment Share on other sites More sharing options...
vmiroslava Posted May 25, 2016 Share Posted May 25, 2016 in classes/Tools.php for a quick fix just replace switchLanguage function with this one, making sure you edit the id's bellow with your own needs: static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... $cookie->id_currency = 2; //change the currency too, the currency that has the id 2 self::setCurrency(); break; case 2: //and so on .... $cookie->id_currency = 1; self::setCurrency(); break; case 3: $cookie->id_currency = 1; self::setCurrency(); break; case 4: $cookie->id_currency = 4; self::setCurrency(); break; } } } Hi there, Has anyone solved this for v1.6.1.5? thanks a lot! 1 Link to comment Share on other sites More sharing options...
mexis Posted February 11, 2017 Share Posted February 11, 2017 For 1.6.1.x open /classes/Tools.php find this code: $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); replace for this $currency = Currency::getCurrencyInstance(1); number 1 = currency id Link to comment Share on other sites More sharing options...
lovemyseo Posted March 9, 2017 Share Posted March 9, 2017 in classes/Tools.php for a quick fix just replace switchLanguage function with this one, making sure you edit the id's bellow with your own needs: static public function switchLanguage() { global $cookie; if ($id_lang = intval(self::getValue('id_lang')) AND Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; switch($id_lang) { case 1: //if lang_id that's changed to is = 1 than... $cookie->id_currency = 2; //change the currency too, the currency that has the id 2 self::setCurrency(); break; case 2: //and so on .... $cookie->id_currency = 1; self::setCurrency(); break; case 3: $cookie->id_currency = 1; self::setCurrency(); break; case 4: $cookie->id_currency = 4; self::setCurrency(); break; } } } and how to change language automatically when default currency being set to mexican dollar prestashop 1.6.1.11 multishop with effecting shop URL i,s .en and /sp Link to comment Share on other sites More sharing options...
El Patron Posted March 10, 2017 Share Posted March 10, 2017 this is still not how IETF described currency localization, this should be done based on country.....link currency to language breaks the www lol I'm sure I said this in this topic elsewhere..... Link to comment Share on other sites More sharing options...
pcsk Posted March 3, 2018 Share Posted March 3, 2018 For users which came from google to your localized site it's possible to set currency like this by edit function setCurrency($cookie) in /classes/Tools.php this set currency for unkown people Example if some guest came to 1) www.yoursite.com/cs/ = CZK currency 2) www.yoursite.com/pl/ = PLN currency 3) other will have default currency public static function setCurrency($cookie) { if (Tools::isSubmit('SubmitCurrency') && ($id_currency = Tools::getValue('id_currency'))) { /** @var Currency $currency */ $currency = Currency::getCurrencyInstance((int)$id_currency); if (is_object($currency) && $currency->id && !$currency->deleted && $currency->isAssociatedToShop()) { $cookie->id_currency = (int)$currency->id; } } $currency = null; if ((int)$cookie->id_currency) { $currency = Currency::getCurrencyInstance((int)$cookie->id_currency); } if (!Validate::isLoadedObject($currency) || (bool)$currency->deleted || !(bool)$currency->active) { if ((int)$cookie->id_lang) { $currency_by_lang_id = Language::getIsoById((int)$cookie->id_lang); switch ($currency_by_lang_id){ case 'cs': $currency_by_lang_iso_code = Currency::getIdByIsoCode('CZK'); $currency = Currency::getCurrencyInstance((int)$currency_by_lang_iso_code); break; case 'pl': $currency_by_lang_iso_code = Currency::getIdByIsoCode('PLN'); $currency = Currency::getCurrencyInstance((int)$currency_by_lang_iso_code); break; default: $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); } } else{ $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); } } $cookie->id_currency = (int)$currency->id; if ($currency->isAssociatedToShop()) { return $currency; } else { // get currency from context $currency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true); if (isset($currency[0]) && $currency[0]['id_currency']) { $cookie->id_currency = $currency[0]['id_currency']; return Currency::getCurrencyInstance((int)$cookie->id_currency); } } return $currency; } Tested on Prestashop 1.6.17 & Working Link to comment Share on other sites More sharing options...
Pitis Livia Posted May 6, 2021 Share Posted May 6, 2021 Hi! On prestashop 1.7.7.2 it doesn't work... Do you have a more current variant? Link to comment Share on other sites More sharing options...
senso321 Posted February 9, 2022 Share Posted February 9, 2022 (edited) On PrestaShop version: 1.7.8.0, this is how you would more or like to achieve the goal based on the original answer 👇 Keep in mind that you should take advantage of overrides when overriding default behaviors. Hence the code would go to overrides/classes/Tools.php /** * If necessary change cookie language ID and context language. * * @param Context|null $context * * @throws PrestaShopDatabaseException * @throws PrestaShopException */ public static function switchLanguage(Context $context = null) { if (null === $context) { $context = Context::getContext(); } // On PrestaShop installations Dispatcher::__construct() gets called (and so Tools::switchLanguage()) // Stop in this case by checking the cookie if (!isset($context->cookie)) { return; } if ( ($iso = Tools::getValue('isolang')) && Validate::isLanguageIsoCode($iso) && ($id_lang = (int) Language::getIdByIso($iso)) ) { $_GET['id_lang'] = $id_lang; } // Only switch if new ID is different from old ID $newLanguageId = (int) Tools::getValue('id_lang'); if ( Validate::isUnsignedId($newLanguageId) && $newLanguageId !== 0 && $context->cookie->id_lang !== $newLanguageId ) { $context->cookie->id_lang = $newLanguageId; $language = new Language($newLanguageId); if (Validate::isLoadedObject($language) && $language->active && $language->isAssociatedToShop()) { $context->language = $language; } } /** This is the switch we added to match language ID to a desired currency ID */ switch($newLanguageId) { case 1: //if lang_id that's changed to is = 1 than... $context->cookie->id_currency = 2; //change the currency too, the currency that has the id 2 break; case 2: //and so on .... $context->cookie->id_currency = 1; break; case 3: $context->cookie->id_currency = 1; break; case 4: $context->cookie->id_currency = 4; break; default: $context->cookie->id_currency = 1; } Tools::setCookieLanguage($context->cookie); /** This is the function that actually sets the currency */ Tools::setCurrency($context->cookie); } Edited February 9, 2022 by senso321 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts