Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: append symbol setting for European style currencies #549

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions code/model/fieldtypes/ShopCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ class ShopCurrency extends Currency

private static $thousand_delimiter = ',';

private static $append_symbol = false;

private static $negative_value_format = "<span class=\"negative\">(%s)</span>";

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);
}
Expand Down
2 changes: 2 additions & 0 deletions example_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down