Skip to content

Commit

Permalink
3.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Ingram committed Aug 10, 2021
1 parent d8e15aa commit 4d1e7d4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function _request() {

if (typeof window !== 'undefined') {
window.swell = {
version: '3.10.0'
version: '3.10.1'
};
}

Expand Down
37 changes: 36 additions & 1 deletion dist/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function methods(request, opt) {

if ((type === 'display' || params.rate) && typeof formatAmount === 'number' && typeof formatRate === 'number') {
// Convert the price currency into the display currency
formatAmount = amount * formatRate;
formatAmount = this.applyRounding(amount * formatRate, state);
}

var formatter;
Expand All @@ -145,6 +145,41 @@ function methods(request, opt) {
}

return String(amount);
},
applyRounding: function applyRounding(value, config) {
if (!config || !config.round) {
return value;
}

var scale = config.decimals;
var fraction = config.round_interval === 'fraction' ? config.round_fraction || 0 : 0;
var roundValue = ~~value;
var decimalValue = this.round(value, scale);

if (decimalValue === fraction) {
return roundValue + decimalValue;
}

var diff = this.round(decimalValue - fraction, 1);
var direction = config.round === 'nearest' ? diff > 0 ? diff >= 0.5 ? 'up' : 'down' : diff <= -0.5 ? 'down' : 'up' : config.round;

switch (direction) {
case 'down':
roundValue = roundValue + fraction - (decimalValue > fraction ? 0 : 1);
break;

case 'up':
default:
roundValue = roundValue + fraction + (decimalValue > fraction ? 1 : 0);
break;
}

return this.round(roundValue, scale);
},
round: function round(value) {
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
// TODO: this is unrealiable (but only used for display)
return Number(Number(value).toFixed(scale));
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion dist/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function calculateVariation(input, options) {
variation.orig_price = variant.orig_price || product.orig_price;
variation.stock_status = variant.stock_status;
variation.stock_level = variant.stock_level || 0;
variation.images = variant.images && variant.images.length ? variant.images : product.images;
variation.images = (variant.images && variant.images.length ? variant.images : product.images) || [];
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swell-js",
"version": "3.10.0",
"version": "3.10.1",
"description": "Swell JS library for client-side stores",
"repository": {
"type": "git",
Expand Down

0 comments on commit 4d1e7d4

Please sign in to comment.