Post by MattL » Sat Jan 07, 2012 3:38 am

Hi,

I'm trying to setup my store so that when you select your language, it also applies the currency used in your country.

I've replaced the default language code from my templates header.tpl to the following:

Code: Select all

<form name="language" action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
			<div id="language">
				<img src="image/flags/se.png" alt="Svenska" title="Svenska" onclick="$('input[name=\'language_code\']').attr('value', 'se'); $('input[name=\'currency_code\']').attr('value', 'SEK'); $(this).parent().parent().submit();" />
				<img src="image/flags/dk.png" alt="Danish" title="Danish" onclick="$('input[name=\'language_code\']').attr('value', 'da').submit(); $(this).parent().parent().submit();" />
				<img src="image/flags/gb.png" alt="English" title="English" onclick="$('input[name=\'language_code\']').attr('value', 'en').submit(); $('input[name=\'currency_code\']').attr('value', 'GBP').submit(); $(this).parent().parent().submit();" />
				<input type="hidden" name="language_code" value="" />
				<input type="hidden" name="currency_code" value="" />
				<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
			</div>
		</form>
The currency currently does not change when you click the flags, but the language does. I've I remove the hidden langage code input field then the currency works...

I'm using opencart v1.5.1.3

Newbie

Posts

Joined
Sat Jan 07, 2012 3:32 am

Post by MattL » Sat Jan 07, 2012 7:01 am

I've got this working now.

For anyone else who may want to do this in the future.

In addition to the javascript in the code above add/edit the following in controller/common/header.php
(some where around line 130, I've edited my files so I don't have the exact line number).

Find:

Code: Select all

    	if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['language_code'])) {
			$this->session->data['language'] = $this->request->post['language_code'];
			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect($this->url->link('common/home'));
			}
    	}
Replace with:

Code: Select all

    	if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['language_code'])) {
			$this->session->data['language'] = $this->request->post['language_code'];
			$this->currency->set($this->request->post['currency_code']); 
			unset($this->session->data['shipping_methods']); 
			unset($this->session->data['shipping_method']); 
			if (isset($this->request->post['redirect'])) {
				$this->redirect($this->request->post['redirect']);
			} else {
				$this->redirect($this->url->link('common/home'));
			}
    	}	

Newbie

Posts

Joined
Sat Jan 07, 2012 3:32 am

Post by breakfest » Fri Jan 27, 2012 6:32 am

In my case an error occurs:

2012-01-26 23:20:21 - PHP Notice: Undefined index: currency_code in /www/webvol2/16/6i5dlz3h7y4xoi3/dual.rs/public_html/catalog/controller/common/header.php on line 135

Where is a problem and what to do next?

Newbie

Posts

Joined
Wed Dec 28, 2011 2:48 am

Post by aquaboy78 » Thu May 24, 2012 11:54 am

can it work on OCART 1.5.2.1???

Newbie

Posts

Joined
Sat May 19, 2012 12:41 am

Post by Mte90 » Sat Apr 20, 2013 4:46 pm

I have do it a vqmod for add the php code.
it's tested on opencart 1.5.5.1.
remeber to modify edit your language.tpl of your theme like this:

Code: Select all

<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
  <div id="language">
    <?php 
    foreach ($languages as $language) { 
		if($language['code'] == 'en') {
			$cur_ = 'GBP';
		} else {
			$cur_ = 'EUR';
		}
    ?>
    <img src="image/flags/<?php echo $language['image']; ?>" alt="<?php echo $language['name']; ?>" title="<?php echo $language['name']; ?>" onclick="$('input[name=\'language_code\']').attr('value', '<?php echo $language['code']; ?>');$('input[name=\'currency_code\']').attr('value', '<?php echo $cur_; ?>');  $(this).parent().parent().submit();" />
    <?php } ?>
    <input type="hidden" name="language_code" value="" />
    <input type="hidden" name="currency_code" value="" />
    <input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
  </div>
</form>

Newbie

Posts

Joined
Sat Apr 20, 2013 4:42 pm

Post by kekke » Tue Nov 12, 2013 1:39 am

I need this function too. I tried Mte90s solution but only got it to work for one language (I´m not a programmer). Is there a way to do it on 1.5.6?

Newbie

Posts

Joined
Tue Nov 12, 2013 1:36 am
Who is online

Users browsing this forum: No registered users and 19 guests