Skip to content

Commit 610ff49

Browse files
b-sharpebojanz
authored andcommitted
Issue #2842274: Price Amount should be allowed to be negative (for adjustments) (#612)
1 parent 04e2e17 commit 610ff49

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

modules/order/src/Plugin/Field/FieldWidget/AdjustmentDefaultWidget.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
7878
'#type' => 'commerce_price',
7979
'#title' => t('Amount'),
8080
'#default_value' => ($adjustment) ? $adjustment->getAmount()->toArray() : NULL,
81+
'#allow_negative' => TRUE,
8182
'#states' => [
8283
'optional' => [
8384
'select[name="' . $states_selector_name . '"]' => ['value' => '_none'],

modules/price/src/Element/Price.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* '#type' => 'commerce_price',
1515
* '#title' => $this->t('Amount'),
1616
* '#default_value' => ['number' => '99.99', 'currency_code' => 'USD'],
17+
* '#allow_negative' => FALSE,
1718
* '#size' => 60,
1819
* '#maxlength' => 128,
1920
* '#required' => TRUE,
@@ -33,6 +34,7 @@ public function getInfo() {
3334
'#size' => 10,
3435
'#maxlength' => 128,
3536
'#default_value' => NULL,
37+
'#allow_negative' => FALSE,
3638
'#attached' => [
3739
'library' => ['commerce_price/admin'],
3840
],
@@ -99,6 +101,7 @@ public static function processElement(array $element, FormStateInterface $form_s
99101
'#min_fraction_digits' => min($fraction_digits),
100102
// '6' is the field storage maximum.
101103
'#max_fraction_digits' => 6,
104+
'#min' => $element['#allow_negative'] ? NULL : 0,
102105
];
103106
unset($element['#size']);
104107
unset($element['#maxlength']);

0 commit comments

Comments
 (0)