From 32f5bb25de8e5a3bce9b7b49cab06047e4f74235 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Wed, 16 May 2012 08:49:35 +0000 Subject: [PATCH] // Blocklayered : Adaptation for the 1.4 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@15325 b9a71923-0436-4b27-9f14-aed3839534dd --- modules/blocklayered/blocklayered.js | 54 +++++++++++++++++++++++++-- modules/blocklayered/blocklayered.tpl | 4 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/modules/blocklayered/blocklayered.js b/modules/blocklayered/blocklayered.js index 146dbe845..919094343 100644 --- a/modules/blocklayered/blocklayered.js +++ b/modules/blocklayered/blocklayered.js @@ -187,15 +187,14 @@ function initSliders() var from = ''; var to = ''; - console.log(slider); switch (slider['format']) { case 1: case 2: case 3: case 4: - from = formatCurrency($('#layered_'+slider['type']+'_slider').slider('values', 0), slider['format'], slider['unit']); - to = formatCurrency($('#layered_'+slider['type']+'_slider').slider('values', 1), slider['format'], slider['unit']); + from = blocklayeredFormatCurrency($('#layered_'+slider['type']+'_slider').slider('values', 0), slider['format'], slider['unit']); + to = blocklayeredFormatCurrency($('#layered_'+slider['type']+'_slider').slider('values', 1), slider['format'], slider['unit']); break; case 5: from = $('#layered_'+slider['type']+'_slider').slider('values', 0)+slider['unit'] @@ -530,6 +529,8 @@ function updateProductUrl() }); } } + + /** * Copy of the php function utf8_decode() */ @@ -558,4 +559,51 @@ function utf8_decode (utfstr) { } } return res; +} + + +/** + * Return a formatted price + * Copy from tools.js + */ +function blocklayeredFormatCurrency(price, currencyFormat, currencySign, currencyBlank) +{ + // if you modified this function, don't forget to modify the PHP function displayPrice (in the Tools.php class) + blank = ''; + price = parseFloat(price.toFixed(6)); + price = ps_round(price, priceDisplayPrecision); + if (currencyBlank > 0) + blank = ' '; + if (currencyFormat == 1) + return currencySign + blank + blocklayeredFormatNumber(price, priceDisplayPrecision, ',', '.'); + if (currencyFormat == 2) + return (blocklayeredFormatNumber(price, priceDisplayPrecision, ' ', ',') + blank + currencySign); + if (currencyFormat == 3) + return (currencySign + blank + blocklayeredFormatNumber(price, priceDisplayPrecision, '.', ',')); + if (currencyFormat == 4) + return (blocklayeredFormatNumber(price, priceDisplayPrecision, ',', '.') + blank + currencySign); + return price; +} + + +/** + * Return a formatted number + * Copy from tools.js + */ +function blocklayeredFormatNumber(value, numberOfDecimal, thousenSeparator, virgule) +{ + value = value.toFixed(numberOfDecimal); + var val_string = value+''; + var tmp = val_string.split('.'); + var abs_val_string = (tmp.length == 2) ? tmp[0] : val_string; + var deci_string = ('0.' + (tmp.length == 2 ? tmp[1] : 0)).substr(2); + var nb = abs_val_string.length; + + for (var i = 1 ; i < 4; i++) + if (value >= Math.pow(10, (3 * i))) + abs_val_string = abs_val_string.substring(0, nb - (3 * i)) + thousenSeparator + abs_val_string.substring(nb - (3 * i)); + + if (parseInt(numberOfDecimal) == 0) + return abs_val_string; + return abs_val_string + virgule + (deci_string > 0 ? deci_string : '00'); } \ No newline at end of file diff --git a/modules/blocklayered/blocklayered.tpl b/modules/blocklayered/blocklayered.tpl index 086d74d0d..1471ca343 100644 --- a/modules/blocklayered/blocklayered.tpl +++ b/modules/blocklayered/blocklayered.tpl @@ -167,8 +167,8 @@ param_product_url = ''; {/literal} {if $filter.format < 5} {literal} - from = formatCurrency(ui.values[0], {/literal}{$filter.format}{literal}, '{/literal}{$filter.unit}{literal}'); - to = formatCurrency(ui.values[1], {/literal}{$filter.format}{literal}, '{/literal}{$filter.unit}{literal}'); + from = blocklayeredFormatCurrency(ui.values[0], {/literal}{$filter.format}{literal}, '{/literal}{$filter.unit}{literal}'); + to = blocklayeredFormatCurrency(ui.values[1], {/literal}{$filter.format}{literal}, '{/literal}{$filter.unit}{literal}'); {/literal} {else} {literal}