Developer forum

Forum » Ecommerce - Standard features » Changing currency inside shop

Changing currency inside shop

Kasper Jensen
Reply
Hey,

Is it possible to make a kind of dropdown, where the customers of a webshop can choose his/her desired currency?

// Kasper


Replies

 
Kristian Kirkholt
Reply
Hi Kasper

Not as standard. But this was done with heavy template building and some custom code on www.skovlarsen.dk
Normally you chose languge and are transferred to the correct currency on a specific language layer.
 
Casper Stendal
Reply

Nice solution exactly what we need.

It would be even more fantastic, if you would share the template with the dropdown?  :)

Best regards
 
Casper Stendal
Reply

Should someone else have a solution for this problem, please drop a line...

It no problem to make the dropdown:
<select onchange="document.location='?currencycode=' + this.value;">
    <option value="USD">USD: US Dollar</option>
    <option value="EUR">EUR: EU Euro</option>
    <option value="DKK">DKK: Danke Kroner</option>
</select>

But how to get the current selected currency inside the template? So we can keep the right selection in the dropdown?
 
Casper Stendal
Reply
This post has been marked as an answer
Working solution:
<select id="selCurrency" onchange="updateCurrency(this.value)">
    <option value="USD">USD: US Dollar</option>
    <option value="EUR">EUR: EU Euro</option>
    <option value="DKK">DKK: Danke Kroner</option>
</select>
<script type="text/javascript">
    var selCurrency = document.getElementById('selCurrency');
    for (var i = 0; i < selCurrency.options.length; i++) {
        if (selCurrency.options[i].value == getCookie('currencycode'))
            selCurrency.options[i].selected = true;
    }

    function updateCurrency(currency) {
        var url = document.location.href.replace(/&currencycode=.{3}/, '').replace(/\?currencycode=.{3}&/, '?').replace(/\?currencycode=.{3}/, '');
        setCookie('currencycode', currency, 14);
        var parm = "?";
        if (url.indexOf('?') >= 0)
            parm = "&";
        document.location = url + parm + 'currencycode=' + currency;
    }

    function getCookie(c_name) {
        var i, x, y, ARRcookies = document.cookie.split(";");
        for (i = 0; i < ARRcookies.length; i++) {
            x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
            y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == c_name) {
                return unescape(y);
            }
        }
    }

    function setCookie(c_name, value, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
        document.cookie = c_name + "=" + c_value;
    }
</script>
Votes for this answer: 1

 

You must be logged in to post in the forum