简体   繁体   中英

Opencart change languge with currency change options

I am just a newbie to opencart . I have made an ecommerce wesite with it. In that website there is the feature for multilingual with multi currency converter option. Now I want that when a user clicks on his language it should also convert the currency to his language as well. So is it possible to do this with Opencart . Can someone share any codes or any reference link so that I can do that. Any help and suggestions will be highly appreciable. Thanks.

There is a currency option in the opencart admin panel , the path is something like this :

system > localisation > currencies

there you can change and add currency options related to a particular language.

if ($currency && $this->has($currency)) {
            $symbol_left   = $this->currencies[$currency]['symbol_left'];
            $symbol_right  = $this->currencies[$currency]['symbol_right'];
            $decimal_place = $this->currencies[$currency]['decimal_place'];
        } else {
            if($_SESSION['language']=="es"):

                $symbol_right  = $this->currencies[$this->code]['symbol_right'];
                else:
    $from="USD";
    $to="MXN";
    $path = "http://www.google.com/ig/calculator?hl=en&q=1".$from."=?".$to;
    $rawdata = file_get_contents($path);
    $data = explode('"', $rawdata);
    $data = explode(' ', $data['3']);
    $var = $data['0'];
    $e=round($var,3);
    if ($e):
        $number=$number / $e;
    else:
        $default_dollar=12.863;
        $number=$number / $default_dollar;                    
    endif;    
        $symbol_right=" USD";
    endif;
            $symbol_left   = $this->currencies[$this->code]['symbol_left'];

            $decimal_place = $this->currencies[$this->code]['decimal_place'];

            $currency = $this->code;
        }

There is a function at :\\system\\library\\currency.php

    public function format($number, $currency = '', $value = '', $format = true) {
    if ($currency && $this->has($currency)) {
        $symbol_left   = $this->currencies[$currency]['symbol_left'];

        $symbol_right  = $this->currencies[$currency]['symbol_right'];
        $decimal_place = $this->currencies[$currency]['decimal_place'];
    } else {            
        $symbol_left   = $this->currencies[$this->code]['symbol_left'];
        $symbol_right  = $this->currencies[$this->code]['symbol_right'];
        $decimal_place = $this->currencies[$this->code]['decimal_place'];           
        $currency = $this->code;
    }

if you look carefully you can change the currency here as per the language or you can use jquery to send an ajax request for the currency change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM