Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion can be incorrect within the ajaxify cart drawer (Timber v2.0.1) #8

Open
ghost opened this issue May 4, 2016 · 1 comment · May be fixed by #9
Open

Conversion can be incorrect within the ajaxify cart drawer (Timber v2.0.1) #8

ghost opened this issue May 4, 2016 · 1 comment · May be fixed by #9

Comments

@ghost
Copy link

ghost commented May 4, 2016

When used in conjunction with the currencies.liquid snippet and the ajaxify cart drawer in Timber v2.0.1, I've found that conversions can be incorrect in certain circumstances.

Here's an example of steps to recreate:
Assume the shop's default currency is USD.

  1. User selects "JPY" currency from the dropdown - Currency.convertAll("USD", "JPY") is called.
  2. User opens the cart drawer - new currency elements are added to the DOM.
  3. User selects "EUR" currency (not the shop currency nor a previously selected currency) from the dropdown - Currency.convertAll("JPY", "EUR") is called.
  4. The function rightly assumes any new DOM elements from 2) are being converted for the first time, but incorrectly assumes they are in the oldCurrency ("JPY") format. They are actually in the shop currency ("USD");
  5. Incorrect conversion occurs and the currency elements show different prices. Further conversion can make it worse.

Essentially, a lack of the "data-currency" attribute does not always mean that oldCurrency is actually the current currency for that element. (If the data-currency is present however, we should be able to trust that oldCurrency is the current currency for that element as it should be kept in sync).

@ghost
Copy link
Author

ghost commented May 4, 2016

It seems this was not being triggered correctly after the cart drawer opened in ajaxify.js:

$('body').on('ajaxCart.afterCartLoad', function() {
  Currency.convertAll(shopCurrency, jQuery('[name=currencies]').val());
  jQuery('.selected-currency').text(Currency.currentCurrency);
});

Triggering this 'ajaxCart.afterCartLoad' event properly in ajaxify.js fixes the issue without any of the suggested changes.

Although it's an edge case, I hope there's still something to think about here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0 participants