From a3147c35d46d20b62219ad35c95515121d8d386f Mon Sep 17 00:00:00 2001 From: Anselm Christophersen Date: Wed, 28 Sep 2016 14:43:13 +0200 Subject: [PATCH] FEATURE: append symbol setting for European style currencies --- code/model/fieldtypes/ShopCurrency.php | 11 +++++++++-- example_config.yml | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/model/fieldtypes/ShopCurrency.php b/code/model/fieldtypes/ShopCurrency.php index 3db462b12..e100d1be2 100644 --- a/code/model/fieldtypes/ShopCurrency.php +++ b/code/model/fieldtypes/ShopCurrency.php @@ -11,17 +11,24 @@ class ShopCurrency extends Currency private static $thousand_delimiter = ','; + private static $append_symbol = false; + private static $negative_value_format = "(%s)"; public function Nice() { - $val = $this->config()->currency_symbol . - number_format( + $symbol = $this->config()->currency_symbol; + $val = number_format( abs($this->value), 2, self::config()->decimal_delimiter, self::config()->thousand_delimiter ); + if ($this->config()->append_symbol) { + $val = $val . ' ' . $symbol; + } else { + $val = $symbol . $val; + } if ($this->value < 0) { return sprintf(self::config()->negative_value_format, $val); } diff --git a/example_config.yml b/example_config.yml index 7bc12a032..475cc9d1d 100644 --- a/example_config.yml +++ b/example_config.yml @@ -78,6 +78,8 @@ ShopConfig: ShopCurrency: decimal_delimiter: '.' thousand_delimiter: ',' + # european style currencies, e.g. 45,00 € instead of €45,00 + append_symbol: true ShoppingCart_Controller: # Redirect to the cart page after manipulating the shopping cart