@@ -14,18 +14,31 @@ abstract class PercentageOffBase extends PromotionOfferBase {
14
14
*/
15
15
public function defaultConfiguration () {
16
16
return [
17
- 'amount ' => '0 ' ,
17
+ 'percentage ' => '0 ' ,
18
18
] + parent ::defaultConfiguration ();
19
19
}
20
20
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
+
21
34
/**
22
35
* Gets the percentage.
23
36
*
24
37
* @return string
25
38
* The percentage.
26
39
*/
27
40
public function getPercentage () {
28
- return (string ) $ this ->configuration ['amount ' ];
41
+ return (string ) $ this ->configuration ['percentage ' ];
29
42
}
30
43
31
44
/**
@@ -34,16 +47,16 @@ public function getPercentage() {
34
47
public function buildConfigurationForm (array $ form , FormStateInterface $ form_state ) {
35
48
$ form += parent ::buildConfigurationForm ($ form , $ form_state );
36
49
37
- $ form ['amount ' ] = [
50
+ $ form ['percentage ' ] = [
38
51
'#type ' => 'commerce_number ' ,
39
52
'#title ' => $ this ->t ('Percentage ' ),
40
- '#default_value ' => $ this ->configuration ['amount ' ] * 100 ,
53
+ '#default_value ' => $ this ->configuration ['percentage ' ] * 100 ,
41
54
'#maxlength ' => 255 ,
42
- '#required ' => TRUE ,
43
55
'#min ' => 0 ,
44
56
'#max ' => 100 ,
45
57
'#size ' => 4 ,
46
58
'#field_suffix ' => $ this ->t ('% ' ),
59
+ '#required ' => TRUE ,
47
60
];
48
61
49
62
return $ form ;
@@ -54,8 +67,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
54
67
*/
55
68
public function validateConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
56
69
$ 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 . ' ));
59
72
}
60
73
}
61
74
@@ -66,7 +79,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
66
79
parent ::submitConfigurationForm ($ form , $ form_state );
67
80
68
81
$ values = $ form_state ->getValue ($ form ['#parents ' ]);
69
- $ this ->configuration ['amount ' ] = (string ) ($ values ['amount ' ] / 100 );
82
+ $ this ->configuration ['percentage ' ] = (string ) ($ values ['percentage ' ] / 100 );
70
83
}
71
84
72
85
}
0 commit comments