Page 1 of 1

Change Currency Via URL? [SOLVED]

Posted: Wed Feb 14, 2018 12:14 am
by testie
I used to be able to change currency through URL.

Example: http://opencart/?currency=USD

But it seems like this was removed in an update? I would greatly appreciate if there was an fix for this :) I found one extension for this but it's for an older version of Opencart.

My site is: http://bersau.se

Running Version 3.0.2.0

Re: Change Currency Via URL?

Posted: Wed Feb 21, 2018 9:39 pm
by testie
Bump ;)

Re: Change Currency Via URL?

Posted: Wed Feb 21, 2018 10:17 pm
by uksitebuilder
Not an option in OC default unless you have or had an extension that did this for you.

Re: Change Currency Via URL?

Posted: Sun Mar 11, 2018 7:16 am
by testie
Hm I'm pretty sure I have all extensions that I used on previous version of OC. And I find a lot of posts on the forum when people are suggesting the /?currency= trick. And I can't find any extension for it for 3.0.2.0

I found a post where you uploaded a .xml fix for this but I can't install it, probably because it's and old version :)?
viewtopic.php?t=181974

Re: Change Currency Via URL? [SOLVED]

Posted: Wed Mar 14, 2018 7:18 am
by testie
This was a total shot in the dark but it worked, can't tell you how happy I am :P

Found this post how to change language via URL:
viewtopic.php?f=190&t=143696#p556676

And just switched the lang & language attributes to "currency" and it worked!

So here is the solution for you who might stumble upon this post if you need to solve this problem:

Insert code below after the line 4 in the file catalog\controller\common\language.php

Code: Select all

if (isset($this->request->get['currency'])) {
 
    $this->session->data['currency'] = $this->request->get['currency'];
 
    $this->response->redirect($this->url->link('common/home'));
}

Re: Change Currency Via URL? [SOLVED]

Posted: Wed Mar 14, 2018 11:48 am
by IP_CAM
Well done, and it saved me from looking around for this again,
after I've installed it in a TestShop, but many Moon's ago...
I now installed both Routines, because one never know's,
it may one day be of use ... ;)
Thanks, Ernie
---
Image

Re: Change Currency Via URL? [SOLVED]

Posted: Wed Sep 18, 2019 2:05 am
by Jassi123
This solution works great but right now it redirects all links with "?currency=" in the end to "index.php?route=common/home" after the currency is changed.
If I wanted to redirect the link in this way,
home.xyz/category-seo-link/product-seo-link/?currency=USD
to change the currency to USD and then go to
home.xyz/category-seo-link/product-seo-link/ how would I go about doing that?
I'm guessing i'd have to change the line

Code: Select all

$this->response->redirect($this->url->link('common/home'));
but to what?

Re: Change Currency Via URL? [SOLVED]

Posted: Wed Sep 18, 2019 10:02 am
by letxobnav
Just add this:

Code: Select all

		if (isset($this->request->get['currency']) && array_key_exists($this->request->get['currency'],$currencies)) {
			$code = $this->request->get['currency'];
			$this->session->data['currency'] = $code;
		}

before this:

Code: Select all

		if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
			setcookie('currency', $code, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
		}		

in catalog/controller/startup/startup.php

no need for redirections.

Re: Change Currency Via URL? [SOLVED]

Posted: Wed Sep 25, 2019 3:26 am
by Jassi123
This worked even better than the change to the language file.
Is it possible to combine this method with something else, like also changing the country that is chosen by default in the cart during shipping estimation (changing the country_id, zone_id, iso_code_3, or something else), so that the currency and the delivery country can be changed together?
letxobnav wrote:
Wed Sep 18, 2019 10:02 am
Just add this:

Code: Select all

		if (isset($this->request->get['currency']) && array_key_exists($this->request->get['currency'],$currencies)) {
			$code = $this->request->get['currency'];
			$this->session->data['currency'] = $code;
		}
before this:

Code: Select all

		if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
			setcookie('currency', $code, time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
		}		
in catalog/controller/startup/startup.php