From c2292b75d490c6cdec4fe7823e7de97fbd0693c1 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 5 Dec 2013 18:46:35 +0100 Subject: [PATCH] Fixed issue #123. Introduced NumberFormat::formatStandardNumber() --- .../Controller/Admin/ProductController.php | 11 ++++++----- core/lib/Thelia/Tools/NumberFormat.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index d415317c0..eca9849e3 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -1201,10 +1201,10 @@ class ProductController extends AbstractCrudController } return new JsonResponse(array( - 'price_with_tax' => NumberFormat::getInstance($this->getRequest())->format($price_with_tax, null, '.'), - 'price_without_tax' => NumberFormat::getInstance($this->getRequest())->format($price_without_tax, null, '.'), - 'sale_price_with_tax' => NumberFormat::getInstance($this->getRequest())->format($sale_price_with_tax, null, '.'), - 'sale_price_without_tax' => NumberFormat::getInstance($this->getRequest())->format($sale_price_without_tax, null, '.') + 'price_with_tax' => NumberFormat::getInstance($this->getRequest())->formatStandardNumber($price_with_tax), + 'price_without_tax' => NumberFormat::getInstance($this->getRequest())->formatStandardNumber($price_without_tax), + 'sale_price_with_tax' => NumberFormat::getInstance($this->getRequest())->formatStandardNumber($sale_price_with_tax), + 'sale_price_without_tax' => NumberFormat::getInstance($this->getRequest())->formatStandardNumber($sale_price_without_tax) )); } @@ -1236,7 +1236,8 @@ class ProductController extends AbstractCrudController if ($convert != 0) { $return_price = $prix * Currency::getDefaultCurrency()->getRate(); } + // Format the number using '.', to perform further calculation - return NumberFormat::getInstance($this->getRequest())->format($return_price, null, '.'); + return NumberFormat::getInstance($this->getRequest())->formatStandardNumber($return_price); } } diff --git a/core/lib/Thelia/Tools/NumberFormat.php b/core/lib/Thelia/Tools/NumberFormat.php index ae25404d7..f3e69129b 100644 --- a/core/lib/Thelia/Tools/NumberFormat.php +++ b/core/lib/Thelia/Tools/NumberFormat.php @@ -39,6 +39,22 @@ class NumberFormat return new NumberFormat($request); } + /** + * Get a standard number, with '.' as decimal point and no thousands separator + * so that this number can be used to perform calculations. + * + * @param float $number the number + * @param string $decimals number of decimal figures + */ + public function formatStandardNumber($number, $decimals = null) { + + $lang = $this->request->getSession()->getLang(); + + if ($decimals == null) $decimals = $lang->getDecimals(); + + return number_format($number, $decimals, '.', ''); + } + public function format($number, $decimals = null, $decPoint = null, $thousandsSep = null) { $lang = $this->request->getSession()->getLang();