diff --git a/sass/css/_shop.scss b/sass/css/_shop.scss index b37f340..23d77c1 100644 --- a/sass/css/_shop.scss +++ b/sass/css/_shop.scss @@ -160,7 +160,7 @@ button { font-size: .8rem; table { - max-width: 350px; + max-width: 450px; } .summary-remove-all { diff --git a/static/js/shop.jsx b/static/js/shop.jsx index c423af2..2b79fff 100644 --- a/static/js/shop.jsx +++ b/static/js/shop.jsx @@ -108,6 +108,24 @@ const nbrOccupiedSlotsInCrate = (items) => { }, 0); }; +function formatMoney(amount, decimalCount = 2, decimal = ".", thousands = ",") { + // https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-currency-string-in-javascript + // changes: return amount if error in order to avoid empty value + try { + decimalCount = Math.abs(decimalCount); + decimalCount = isNaN(decimalCount) ? 2 : decimalCount; + + const negativeSign = amount < 0 ? "-" : ""; + + let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString(); + let j = (i.length > 3) ? i.length % 3 : 0; + + return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : ""); + } catch (e) { + return amount; + } +}; + /** * Component that provides a base layout (aside/main) for the page. @@ -196,7 +214,7 @@ class ProductItem extends React.PureComponent {