var shopCurrency = 'CRC';
/* Sometimes merchants change their shop currency, let's tell our JavaScript file */
Currency.money_with_currency_format[shopCurrency] = "₡ {{amount_with_comma_separator}} CRC";
Currency.money_format[shopCurrency] = "₡ {{amount_with_comma_separator}}";
/* Default currency */
var defaultCurrency = 'EUR' || shopCurrency;
/* Currency selector */
var $currencySelector = $("[data-currency-converter]");
/* Cookie currency */
var cookieCurrency = Currency.cookie.read();
/* Fix for customer account pages */
$('span.money span.money').each(function() {
$(this).parents('span.money').removeClass('money');
});
/* Saving the current price */
$('span.money').each(function() {
$(this).attr('data-currency-CRC', $(this).html());
});
// If there's no cookie.
if (cookieCurrency == null) {
if (shopCurrency !== defaultCurrency) {
Currency.convertAll(shopCurrency, defaultCurrency);
$('.selected-currency').text(Currency.currentCurrency);
}
else {
Currency.currentCurrency = defaultCurrency;
}
}
// If the cookie value does not correspond to any value in the currency dropdown.
else if ($currencySelector.length && $currencySelector.find('option[value=' + cookieCurrency + ']').length === 0) {
Currency.currentCurrency = shopCurrency;
Currency.cookie.write(shopCurrency);
}
else if (cookieCurrency === shopCurrency) {
Currency.currentCurrency = shopCurrency;
}
else {
Currency.convertAll(shopCurrency, cookieCurrency);
$('.selected-currency').text(Currency.currentCurrency);
}
$currencySelector.val(Currency.currentCurrency).change(function() {
var newCurrency = $(this).val();
Currency.convertAll(Currency.currentCurrency, newCurrency);
$('.selected-currency').text(Currency.currentCurrency);
});
var original_selectCallback = window.selectCallback;
var selectCallback = function(variant, selector) {
original_selectCallback(variant, selector);
Currency.convertAll(shopCurrency, $currencySelector.val());
$('.selected-currency').text(Currency.currentCurrency);
};
function convertCurrencies() {
if($currencySelector.val() && $currencySelector.val() != $currencySelector.data('default-shop-currency')) {
Currency.convertAll($currencySelector.data('default-shop-currency'), $currencySelector.val());
$('.selected-currency').text(Currency.currentCurrency);
}
}