' +
+ tableTemplate = '
|
';
list.push($(tableTemplate));
- tableTemplate = '
| Total | ' + this.formatCurrency(this.getTotal()) + ' |
';
+ tableTemplate = '
| Total | ' + this.formatCurrency(this.getTotal()) + ' |
';
list.push($(tableTemplate));
// Add the list to DOM
@@ -239,16 +239,34 @@ Cart.prototype.emptyList = function() {
$table.html('
| The cart is empty. |
');
}
-/* Get the currency symbol from an existing amount and use it with the new amount*/
+/* Get the currency symbol from an existing amount and use it with the new amount */
Cart.prototype.formatCurrency = function(amount, example) {
- var regex = /([0-9.]+)/gm;
+ var regex = /[0-9 .,]/gm,
+ curSign = '',
+ amt = '',
+ sep = '';
- // Get the first item's formated price
+ // Get the first item's format
if (typeof example == 'undefined' && typeof srvModel != 'undefined') {
example = srvModel.items[0].price.formatted;
}
- return example.replace(regex, amount.toFixed(2));
+ // Have the currency sign on a proper side (e.g. left for usd, right for eur)
+ curSign = example.replace(regex, ' ').replace(/\s\s+/g, 'n');
+ amt = curSign.replace('n', amount.toFixed(2));
+
+ if (example.indexOf('.') === -1) {
+ // Separate decimal by comma for EUR and other currencies
+ amt = amt.replace('.', ',');
+ sep = ' ';
+ } else {
+ sep = ',';
+ }
+
+ // Add thousands separator
+ amt = amt.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
+
+ return amt;
}
Cart.prototype.toCents = function(num) {
@@ -279,4 +297,5 @@ Cart.prototype.destroy = function() {
this.content = [];
this.items = 0;
this.totalAmount = 0;
+ this.tip = 0;
}
\ No newline at end of file