Claudio Posted September 30, 2018 Share Posted September 30, 2018 (edited) Hi guys, I'm hoping that someone might be able to help me with this one, if at all possible. My shop's default currency is USD (I need it to be in USD) and my main target market is from South Africa so most visitors require ZAR currency which is set up and configured. What I'd like to achieve without having to use a module for this purpose is for the website to automatically load ZAR currency for first-time visitors even though the default currency is USD and not ZAR. Is this possible by maybe changing some code? Customers that do not require ZAR currency can of course change the currency to USD if they prefer, that option remains available via the currency selector. The reason why I'd prefer not using a module for this purpose is that I have tried this before with 3 modules form the addon store and either they don't work correctly or end up slowing down the website when loading it for the first time for a new cuso5tmer. I need the website to quickly load ZAR currency by default even though the actual default currency set in Prestashop is USD. Please tell me this is possible? Thanks! Edited October 1, 2018 by Claudio (see edit history) Link to comment Share on other sites More sharing options...
Claudio Posted October 1, 2018 Author Share Posted October 1, 2018 Anyone? Link to comment Share on other sites More sharing options...
rozhawni Posted October 6, 2018 Share Posted October 6, 2018 (edited) Hello Claudio. while I can't tell you how to set ZAR as preferred currency in front office, I can tell you how to Force ZAR as your only currency in front office while having USD in back office. **please make a backup before making any changes** In this file , classes/Tools.php, search and edit the following lines and before we begin, please take note of your current ZAR currency ID found in the database under PREFIX_currency (example ps_currency) inside id_currency and if it differs from the one I've written below, which is 2, please change the number 2 to your ZAR currency ID: From: $currency = Currency::getCurrencyInstance((int)$id_currency); To; $currency = Currency::getCurrencyInstance((int)$id_currency=2); From: $currency = Currency::getCurrencyInstance((int)$cookie->id_currency); To: $currency = Currency::getCurrencyInstance(2); From: $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); To: $currency = Currency::getCurrencyInstance(Configuration::get('id_currency')); From: return Currency::getCurrencyInstance((int)$cookie->id_currency); To: return Currency::getCurrencyInstance(2); Save and refresh your homepage. the only problem with this solution is that is forces ZAR to be the default currency in your front office and your customers can not change it to USD, even though it might show in the currency block that USD is avaliable. Back office is unaffected though. I use this code to force SEK in my front office while having EUR in backoffice because my supplier provides me with euro prices and my customers buy in SEK. Im working on another solution which loads the page with the preferred currency and writes it to a cookie file but I have not figured out yet how to do it. I will come back when I do, until then, have a great time. Edited October 6, 2018 by rozhawni (see edit history) 1 Link to comment Share on other sites More sharing options...
El Patron Posted October 6, 2018 Share Posted October 6, 2018 (edited) https://www.prestaheroes.com/en-us/modules/front-office-default-currency Cheers, el Edited October 25, 2018 by El Patron (see edit history) Link to comment Share on other sites More sharing options...
num47 Posted February 24, 2021 Share Posted February 24, 2021 On 10/1/2018 at 10:36 PM, Claudio said: Anyone? I myself need this as well. My product supplier gives me rate of products in foreign currency. So, i want to add my price in that currency so that i do not have to change the final price if the currency conversion rate changes and it actually changes very often. And, it gets tougher to deal with the situation with the growing of your store. Have you managed any solution so far? Other than buying any module. Buying a module is okay. But, not a viable option of a new store or a store that doesn’t make much revenue out of it. Link to comment Share on other sites More sharing options...
Michal Sjatkovsky Posted March 18, 2021 Share Posted March 18, 2021 On 10/6/2018 at 3:46 PM, rozhawni said: Hello Claudio. while I can't tell you how to set ZAR as preferred currency in front office, I can tell you how to Force ZAR as your only currency in front office while having USD in back office. **please make a backup before making any changes** In this file , classes/Tools.php, search and edit the following lines and before we begin, please take note of your current ZAR currency ID found in the database under PREFIX_currency (example ps_currency) inside id_currency and if it differs from the one I've written below, which is 2, please change the number 2 to your ZAR currency ID: From: $currency = Currency::getCurrencyInstance((int)$id_currency); To; $currency = Currency::getCurrencyInstance((int)$id_currency=2); From: $currency = Currency::getCurrencyInstance((int)$cookie->id_currency); To: $currency = Currency::getCurrencyInstance(2); From: $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); To: $currency = Currency::getCurrencyInstance(Configuration::get('id_currency')); From: return Currency::getCurrencyInstance((int)$cookie->id_currency); To: return Currency::getCurrencyInstance(2); Save and refresh your homepage. the only problem with this solution is that is forces ZAR to be the default currency in your front office and your customers can not change it to USD, even though it might show in the currency block that USD is avaliable. Back office is unaffected though. I use this code to force SEK in my front office while having EUR in backoffice because my supplier provides me with euro prices and my customers buy in SEK. Im working on another solution which loads the page with the preferred currency and writes it to a cookie file but I have not figured out yet how to do it. I will come back when I do, until then, have a great time. Hello, does this work also for the multistore? I need to show only one currency different from default currency in one of the shops. Thank you very much Michal Link to comment Share on other sites More sharing options...
Claudio Posted March 18, 2021 Author Share Posted March 18, 2021 If anyone needs a solution to this problem and is willing to pay a small fee for a developer to implement the solution which is what I ended up having to do, then feel free to try this developer that I found on Freelancer which I used for this and some other mods. I can personally highly recommend their services; https://www.freelancer.com/u/technovation1?ref_project_id=17876202 Link to comment Share on other sites More sharing options...
caovillanueva Posted October 21, 2021 Share Posted October 21, 2021 (edited) Its works for me: Override Tools.php \override\classes\Tools.php With this i can use CAD only in frontend and USD for backend. Used in Prestashop 1.7.7.4 Not conflict detected. Just need replace 2 lines. In my case i used 1 as id currency for CAD <?php class Tools extends ToolsCore { /** * Set cookie currency from POST or default currency. * * @return Currency object */ 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);//befoore $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend. } if (!Validate::isLoadedObject($currency) || (bool) $currency->deleted || !(bool) $currency->active) { //$currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));//before $currency = Currency::getCurrencyInstance(1);//Force CAD for frontend. } $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; } } Edited October 21, 2021 by caovillanueva (see edit history) 1 Link to comment Share on other sites More sharing options...
Coach G Posted November 8, 2023 Share Posted November 8, 2023 I created a free module for this if someone is interested prioritycurrency.zip 1 Link to comment Share on other sites More sharing options...
BZZYBI Posted April 10, 2024 Share Posted April 10, 2024 On 11/8/2023 at 8:50 PM, Coach G said: I created a free module for this if someone is interested prioritycurrency.zip 1.53 kB · 10 downloads Works really well. Thank you very much for sharing Link to comment Share on other sites More sharing options...
leonardomarinio Posted July 30, 2024 Share Posted July 30, 2024 On 11/8/2023 at 8:50 AM, Coach G said: I created a free module for this if someone is interested prioritycurrency.zip 1.53 kB · 18 downloads Hi, its compatible with ps 8.1? Link to comment Share on other sites More sharing options...
Andrei H Posted August 3, 2024 Share Posted August 3, 2024 Hi @leonardomarinio, I just gave it a try and it does seem to work as expected. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now