Skip to content
This repository was archived by the owner on Aug 30, 2018. It is now read-only.

Commit f9dcb04

Browse files
committed
Merge pull request #13 from Shopify/currency-fix
Fix to currency problem when using Ajax
2 parents f30fb34 + f9b99d0 commit f9dcb04

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

assets/ajaxify.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
// JQUERY API (c) Copyright 2009 Jaded Pixel. Author: Caroline Schnapp. All Rights Reserved. Includes slight modifications to addItemFromForm
3535

3636
if ((typeof Shopify) === 'undefined') { Shopify = {}; }
37-
Shopify.money_format = '${{amount}}';
3837

3938
// -------------------------------------------------------------------------------------
4039
// API Helper Functions
@@ -272,7 +271,7 @@ var ajaxifyShopify = (function(module, $) {
272271

273272
// Default settings
274273
settings = {
275-
debug: true,
274+
debug: false,
276275
method: 'drawer', // Method options are drawer, modal, and flip. Default is drawer.
277276
formSelector: 'form[action="/cart/add"]',
278277
addToCartSelector: 'input[type="submit"]',
@@ -281,7 +280,8 @@ var ajaxifyShopify = (function(module, $) {
281280
toggleCartButton: null,
282281
btnClass: null,
283282
wrapperClass: null,
284-
useCartTemplate: false
283+
useCartTemplate: false,
284+
moneyFormat: '${{amount}}'
285285
};
286286

287287
// Override defaults with arguments
@@ -343,7 +343,7 @@ var ajaxifyShopify = (function(module, $) {
343343
$cartCountSelector.html(cart.item_count);
344344
}
345345
if ($cartCostSelector) {
346-
$cartCostSelector.html(Shopify.formatMoney(cart.total_price));
346+
$cartCostSelector.html(Shopify.formatMoney(cart.total_price, settings.moneyFormat));
347347
}
348348
};
349349

@@ -668,7 +668,7 @@ var ajaxifyShopify = (function(module, $) {
668668
itemAdd: itemAdd,
669669
itemMinus: itemMinus,
670670
itemQty: itemQty,
671-
price: Shopify.formatMoney(cartItem.price)
671+
price: Shopify.formatMoney(cartItem.price, settings.moneyFormat)
672672
};
673673

674674
items.push(item);
@@ -677,7 +677,7 @@ var ajaxifyShopify = (function(module, $) {
677677
// Gather all cart data and add to DOM
678678
data = {
679679
items: items,
680-
totalPrice: Shopify.formatMoney(cart.total_price),
680+
totalPrice: Shopify.formatMoney(cart.total_price, settings.moneyFormat),
681681
btnClass: $btnClass
682682
}
683683
$cartContainer.append(template(data));

layout/theme.liquid

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@
160160
cartCostSelector: '#cartCost', // Update the total cart cost when a product is added. Default is null.
161161
toggleCartButton: '#cartToggle', // To toggle drawer/modal cart, include the selector here. Default is null and will take you to /cart page.
162162
useCartTemplate: true, // True to use cart.liquid markup. Default is false and uses handlebars.js for template.
163-
btnClass: 'btn' // Your main button class for styling purposes if useCartTemplate is set to false. Default is null.
163+
btnClass: 'btn', // Your main button class for styling purposes if useCartTemplate is set to false. Default is null.
164+
moneyFormat: {{ shop.money_format | json }} // Your shop money format, defined in liquid.
164165
});
165166
});
166167
</script>

templates/product.liquid

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<div class="grid-item large--one-half">
2020

2121
{% comment %}
22-
If we only have one product, show a large version of it.
23-
If we have more than 1, show it and loop through the rest as thumbnails.
22+
If we only have one product image, show a large version of it.
23+
If we have more than 1, show it then loop through the rest as thumbnails.
2424
{% endcomment %}
2525
{% if product.images.size == 0 %}
2626

@@ -241,7 +241,10 @@ jQuery(function($) {
241241
// Add label if only one product option and it isn't 'Title'. Could be 'Size'.
242242
{% if product.options.size == 1 and product.options.first != 'Title' %}
243243
$('.selector-wrapper:eq(0)').prepend('<label>{{ product.options.first }}</label>');
244-
{% else %}
244+
{% endif %}
245+
246+
// Hide selectors if we only have 1 variant and its title contains 'Default'.
247+
{% if product.variants.size == 1 and product.variants.first.title contains 'Default' %}
245248
$('.selector-wrapper').hide();
246249
{% endif %}
247250

0 commit comments

Comments
 (0)