@@ -14,18 +14,31 @@ abstract class PercentageOffBase extends PromotionOfferBase {
1414 */
1515 public function defaultConfiguration () {
1616 return [
17- 'amount ' => '0 ' ,
17+ 'percentage ' => '0 ' ,
1818 ] + parent ::defaultConfiguration ();
1919 }
2020
21+ /**
22+ * {@inheritdoc}
23+ */
24+ public function setConfiguration (array $ configuration ) {
25+ parent ::setConfiguration ($ configuration );
26+
27+ if (isset ($ this ->configuration ['amount ' ])) {
28+ // The 'amount' key was renamed to 'percentage' in 2.0-rc2.
29+ $ this ->configuration ['percentage ' ] = $ this ->configuration ['amount ' ];
30+ unset($ this ->configuration ['amount ' ]);
31+ }
32+ }
33+
2134 /**
2235 * Gets the percentage.
2336 *
2437 * @return string
2538 * The percentage.
2639 */
2740 public function getPercentage () {
28- return (string ) $ this ->configuration ['amount ' ];
41+ return (string ) $ this ->configuration ['percentage ' ];
2942 }
3043
3144 /**
@@ -34,16 +47,16 @@ public function getPercentage() {
3447 public function buildConfigurationForm (array $ form , FormStateInterface $ form_state ) {
3548 $ form += parent ::buildConfigurationForm ($ form , $ form_state );
3649
37- $ form ['amount ' ] = [
50+ $ form ['percentage ' ] = [
3851 '#type ' => 'commerce_number ' ,
3952 '#title ' => $ this ->t ('Percentage ' ),
40- '#default_value ' => $ this ->configuration ['amount ' ] * 100 ,
53+ '#default_value ' => $ this ->configuration ['percentage ' ] * 100 ,
4154 '#maxlength ' => 255 ,
42- '#required ' => TRUE ,
4355 '#min ' => 0 ,
4456 '#max ' => 100 ,
4557 '#size ' => 4 ,
4658 '#field_suffix ' => $ this ->t ('% ' ),
59+ '#required ' => TRUE ,
4760 ];
4861
4962 return $ form ;
@@ -54,8 +67,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
5467 */
5568 public function validateConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
5669 $ values = $ form_state ->getValue ($ form ['#parents ' ]);
57- if (empty ($ values ['amount ' ])) {
58- $ form_state ->setError ($ form , $ this ->t ('Percentage amount cannot be empty . ' ));
70+ if (empty ($ values ['percentage ' ])) {
71+ $ form_state ->setError ($ form , $ this ->t ('Percentage must be a positive number . ' ));
5972 }
6073 }
6174
@@ -66,7 +79,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
6679 parent ::submitConfigurationForm ($ form , $ form_state );
6780
6881 $ values = $ form_state ->getValue ($ form ['#parents ' ]);
69- $ this ->configuration ['amount ' ] = (string ) ($ values ['amount ' ] / 100 );
82+ $ this ->configuration ['percentage ' ] = (string ) ($ values ['percentage ' ] / 100 );
7083 }
7184
7285}
0 commit comments