Skip to content

Commit

Permalink
Merge pull request #3218 from reactioncommerce/kennedy-fix-failed-to-…
Browse files Browse the repository at this point in the history
…get-currency-exchange-rates-error-3103

Fix "Failed to get currency exchange rates" error in server
  • Loading branch information
spencern committed Nov 9, 2017
2 parents d94d39e + a29b0a4 commit 426e5f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 8 additions & 0 deletions lib/api/helpers.js
Expand Up @@ -37,6 +37,14 @@ export function getPrimaryShopId() {
return Core.Reaction.getPrimaryShopId();
}

/**
* getShopSettings
* @return {Object} returns current shop settings
*/
export function getShopSettings() {
return Core.Reaction.getShopSettings();
}

/**
* @name getShopName
* @method
Expand Down
15 changes: 10 additions & 5 deletions server/methods/core/shop.js
Expand Up @@ -224,12 +224,17 @@ Meteor.methods({
// only fetch rates if locale and shop currency are not equal
// if shop.currency = locale currency the rate is 1
if (shop.currency !== currency) {
exchangeRate = Meteor.call("shop/getCurrencyRates", currency);
const settings = Reaction.getShopSettings();
const exchangeConfig = settings.openexchangerates || {};

if (typeof exchangeRate === "number") {
result.currency.exchangeRate = exchangeRate;
} else {
Logger.warn("Failed to get currency exchange rates.");
if (exchangeConfig.appId) {
exchangeRate = Meteor.call("shop/getCurrencyRates", currency);

if (typeof exchangeRate === "number") {
result.currency.exchangeRate = exchangeRate;
} else {
Logger.warn("Failed to get currency exchange rates.");
}
}
}
}
Expand Down

0 comments on commit 426e5f1

Please sign in to comment.