Please note that this Support article contains frontend customizations via modifying the legacy Algolia template files, which are deprecated and unsupported by the Algolia Support Team.
For more information, please review this Support article - "Why is modifying Algolia template files for customizations not supported?"
All Shopify stores expose a JavaScript object that contains Shopify’s conversion rates. To support multi-currency display, add the lines below to the algolia.formatMoney
method of algolia_init.js.liquid
file:
algolia.formatMoney = function formatMoney(cents) {
+ var priceInCents = cents;
+
+ /**
+ * Uncomment the following block to support Shopify multi-currency
+ * and convert prices from store currency to the currency selected by
+ * the user (aka "presentment" currency).
+ * Please note that this relies on the `Shopify.currency` object exposed
+ * by Shopify, which is an undocumented feature and can change at any time.
+ */
+ // if (
+ // typeof Shopify !== 'undefined' &&
+ // typeof Shopify.currency !== 'undefined' &&
+ // typeof Shopify.currency.rate !== 'undefined' &&
+ // typeof Shopify.currency.active !== 'undefined'
+ // ) {
+ // // Convert to "presentment" currency using the rate provided by Shopify
+ // priceInCents = priceInCents * Shopify.currency.rate;
+ // // Round up to the nearest whole number keeping in accordance with
+ // // the default rounding strategy of Shopify
+ // priceInCents = Math.ceil(priceInCents);
+ //
+ // /**
+ // * Shopify uses different rounding strategies for different currencies.
+ // * The logic below might need to be customised based on the active currencies.
+ // * Note: Please only include currencies other than your store currency.
+ // */
+ // // Round up to the 95th cent for EUR
+ // if (Shopify.currency.active === 'EUR') {
+ // priceInCents = parseInt(priceInCents / 100, 10) * 100 + 95;
+ // }
+ // // Round up to the 00th cent for GBP, USD, DKK
+ // else if (
+ // Shopify.currency.active === 'GBP' ||
+ // Shopify.currency.active === 'USD' ||
+ // Shopify.currency.active === 'DKK'
+ // ) {
+ // priceInCents = parseInt(priceInCents / 100, 10) * 100 + 100;
+ // }
+ // }
- var val = (cents / 100.0).toLocaleString(undefined, {
+ var val = (priceInCents / 100.0).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
var format = algolia.money_format;
// Not necessary, but allows for more risk tolerance if Shopify.formatMoney doesn't work as we want
var regexp = /^([^{}]*)\{\{amount\}\}([^{}]*)$/;
if (format.match(regexp)) {
return format.replace(regexp, '$1' + val + '$2');
}
WARNING:
Shopify does not document the Shopify.currency
object and their conversion rates are not publicly available. If Shopify decides to make their currency object private then this solution will break.