Skip to content

Commit 48a500b

Browse files
committed
Issue #2883280 by bojanz: Provide a way to format prices without a currency code or symbol
1 parent 1ee736e commit 48a500b

12 files changed

Lines changed: 65 additions & 41 deletions

modules/cart/config/install/views.view.commerce_cart_block.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ display:
266266
type: commerce_price_default
267267
settings:
268268
strip_trailing_zeroes: false
269-
display_currency_code: false
269+
currency_display: symbol
270270
group_column: ''
271271
group_columns: { }
272272
group_rows: true

modules/cart/config/install/views.view.commerce_cart_form.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ display:
199199
type: commerce_price_default
200200
settings:
201201
strip_trailing_zeroes: false
202-
display_currency_code: false
202+
currency_display: symbol
203203
group_column: ''
204204
group_columns: { }
205205
group_rows: true
@@ -366,7 +366,7 @@ display:
366366
type: commerce_price_default
367367
settings:
368368
strip_trailing_zeroes: false
369-
display_currency_code: false
369+
currency_display: symbol
370370
group_column: ''
371371
group_columns: { }
372372
group_rows: true

modules/cart/config/install/views.view.commerce_carts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ display:
512512
type: commerce_price_default
513513
settings:
514514
strip_trailing_zeroes: false
515-
display_currency_code: false
515+
currency_display: symbol
516516
group_column: ''
517517
group_columns: { }
518518
group_rows: true

modules/cart/tests/modules/commerce_cart_test/config/install/views.view.test_empty_cart_button_form.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ display:
199199
type: commerce_price_default
200200
settings:
201201
strip_trailing_zeroes: false
202-
display_currency_code: false
202+
currency_display: symbol
203203
group_column: ''
204204
group_columns: { }
205205
group_rows: true
@@ -366,7 +366,7 @@ display:
366366
type: commerce_price_default
367367
settings:
368368
strip_trailing_zeroes: false
369-
display_currency_code: false
369+
currency_display: symbol
370370
group_column: ''
371371
group_columns: { }
372372
group_rows: true

modules/checkout/config/install/views.view.commerce_checkout_order_summary.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ display:
267267
type: commerce_price_default
268268
settings:
269269
strip_trailing_zeroes: false
270-
display_currency_code: false
270+
currency_display: symbol
271271
group_column: ''
272272
group_columns: { }
273273
group_rows: true

modules/order/config/install/views.view.commerce_order_item_table.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ display:
219219
type: commerce_price_default
220220
settings:
221221
strip_trailing_zeroes: false
222-
display_currency_code: false
222+
currency_display: symbol
223223
group_column: ''
224224
group_columns: { }
225225
group_rows: true
@@ -353,7 +353,7 @@ display:
353353
type: commerce_price_default
354354
settings:
355355
strip_trailing_zeroes: false
356-
display_currency_code: false
356+
currency_display: symbol
357357
group_column: ''
358358
group_columns: { }
359359
group_rows: true

modules/order/config/install/views.view.commerce_orders.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ display:
723723
type: commerce_price_default
724724
settings:
725725
strip_trailing_zeroes: false
726-
display_currency_code: false
726+
currency_display: symbol
727727
group_column: ''
728728
group_columns: { }
729729
group_rows: true

modules/order/config/install/views.view.commerce_user_orders.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ display:
375375
type: commerce_price_default
376376
settings:
377377
strip_trailing_zeroes: false
378-
display_currency_code: false
378+
currency_display: symbol
379379
group_column: ''
380380
group_columns: { }
381381
group_rows: true

modules/price/config/schema/commerce_price.schema.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ field.formatter.settings.commerce_price_default:
4747
strip_trailing_zeroes:
4848
type: boolean
4949
label: 'Strip trailing zeroes after the decimal point'
50-
display_currency_code:
51-
type: boolean
52-
label: 'Display the currency code instead of the currency symbol'
50+
currency_display:
51+
type: string
52+
label: 'Currency display'
5353

5454
field.formatter.settings.commerce_price_calculated:
5555
type: mapping
@@ -58,9 +58,9 @@ field.formatter.settings.commerce_price_calculated:
5858
strip_trailing_zeroes:
5959
type: boolean
6060
label: 'Strip trailing zeroes after the decimal point'
61-
display_currency_code:
62-
type: boolean
63-
label: 'Display the currency code instead of the currency symbol'
61+
currency_display:
62+
type: string
63+
label: 'Currency display'
6464
# Needed by the commerce_order version of the formatter.
6565
adjustment_types:
6666
type: sequence

modules/price/src/Plugin/Field/FieldFormatter/PriceDefaultFormatter.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function create(ContainerInterface $container, array $configuratio
7979
public static function defaultSettings() {
8080
return [
8181
'strip_trailing_zeroes' => FALSE,
82-
'display_currency_code' => FALSE,
82+
'currency_display' => 'symbol',
8383
] + parent::defaultSettings();
8484
}
8585

@@ -93,10 +93,15 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
9393
'#title' => $this->t('Strip trailing zeroes after the decimal point.'),
9494
'#default_value' => $this->getSetting('strip_trailing_zeroes'),
9595
];
96-
$elements['display_currency_code'] = [
97-
'#type' => 'checkbox',
98-
'#title' => $this->t('Display the currency code instead of the currency symbol.'),
99-
'#default_value' => $this->getSetting('display_currency_code'),
96+
$elements['currency_display'] = [
97+
'#type' => 'radios',
98+
'#title' => $this->t('Currency display'),
99+
'#options' => [
100+
'symbol' => $this->t('Symbol (e.g. "$")'),
101+
'code' => $this->t('Currency code (e.g. "USD")'),
102+
'none' => $this->t('None'),
103+
],
104+
'#default_value' => $this->getSetting('currency_display'),
100105
];
101106

102107
return $elements;
@@ -113,12 +118,16 @@ public function settingsSummary() {
113118
else {
114119
$summary[] = $this->t('Do not strip trailing zeroes after the decimal point.');
115120
}
116-
if ($this->getSetting('display_currency_code')) {
117-
$summary[] = $this->t('Display the currency code instead of the currency symbol.');
118-
}
119-
else {
120-
$summary[] = $this->t('Display the currency symbol.');
121-
}
121+
122+
$currency_display = $this->getSetting('currency_display');
123+
$currency_display_options = [
124+
'symbol' => $this->t('Symbol (e.g. "$")'),
125+
'code' => $this->t('Currency code (e.g. "USD")'),
126+
'none' => $this->t('None'),
127+
];
128+
$summary[] = $this->t('Currency display: @currency_display.', [
129+
'@currency_display' => $currency_display_options[$currency_display],
130+
]);
122131

123132
return $summary;
124133
}
@@ -151,13 +160,12 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
151160
* The formatting options.
152161
*/
153162
protected function getFormattingOptions() {
154-
$options = [];
163+
$options = [
164+
'currency_display' => $this->getSetting('currency_display'),
165+
];
155166
if ($this->getSetting('strip_trailing_zeroes')) {
156167
$options['minimum_fraction_digits'] = 0;
157168
}
158-
if ($this->getSetting('display_currency_code')) {
159-
$options['currency_display'] = 'code';
160-
}
161169

162170
return $options;
163171
}

0 commit comments

Comments
 (0)