Skip to content

Commit 6571386

Browse files
committed
Issue #2900722: Rename TaxRateAmount to TaxRatePercentage
1 parent cb8af81 commit 6571386

File tree

14 files changed

+373
-338
lines changed

14 files changed

+373
-338
lines changed

modules/tax/config/schema/commerce_tax.schema.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ commerce_tax.commerce_tax_type.plugin.custom:
5353
label:
5454
type: label
5555
label: 'Label'
56-
amount:
56+
percentage:
5757
type: string
58-
label: 'Amount'
58+
label: 'Percentage'
5959
territories:
6060
type: sequence
6161
label: 'Territories'

modules/tax/src/Plugin/Commerce/TaxType/CanadianSalesTax.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function buildZones() {
7979
[
8080
'id' => 'gst',
8181
'label' => $this->t('GST'),
82-
'amounts' => [
83-
['amount' => '0.05', 'start_date' => '2008-01-01'],
82+
'percentages' => [
83+
['number' => '0.05', 'start_date' => '2008-01-01'],
8484
],
8585
'default' => TRUE,
8686
],
@@ -97,8 +97,8 @@ public function buildZones() {
9797
[
9898
'id' => 'pst',
9999
'label' => $this->t('PST'),
100-
'amounts' => [
101-
['amount' => '0.07', 'start_date' => '2013-04-01'],
100+
'percentages' => [
101+
['number' => '0.07', 'start_date' => '2013-04-01'],
102102
],
103103
],
104104
],
@@ -114,8 +114,8 @@ public function buildZones() {
114114
[
115115
'id' => 'pst',
116116
'label' => $this->t('PST'),
117-
'amounts' => [
118-
['amount' => '0.08', 'start_date' => '2013-07-01', 'end_date' => '2023-06-30'],
117+
'percentages' => [
118+
['number' => '0.08', 'start_date' => '2013-07-01', 'end_date' => '2023-06-30'],
119119
],
120120
],
121121
],
@@ -131,8 +131,8 @@ public function buildZones() {
131131
[
132132
'id' => 'hst',
133133
'label' => $this->t('HST'),
134-
'amounts' => [
135-
['amount' => '0.15', 'start_date' => '2016-07-01'],
134+
'percentages' => [
135+
['number' => '0.15', 'start_date' => '2016-07-01'],
136136
],
137137
],
138138
],
@@ -148,8 +148,8 @@ public function buildZones() {
148148
[
149149
'id' => 'hst',
150150
'label' => $this->t('HST'),
151-
'amounts' => [
152-
['amount' => '0.15', 'start_date' => '2016-07-01'],
151+
'percentages' => [
152+
['number' => '0.15', 'start_date' => '2016-07-01'],
153153
],
154154
],
155155
],
@@ -165,8 +165,8 @@ public function buildZones() {
165165
[
166166
'id' => 'hst',
167167
'label' => $this->t('HST'),
168-
'amounts' => [
169-
['amount' => '0.15', 'start_date' => '2010-07-01'],
168+
'percentages' => [
169+
['number' => '0.15', 'start_date' => '2010-07-01'],
170170
],
171171
],
172172
],
@@ -182,8 +182,8 @@ public function buildZones() {
182182
[
183183
'id' => 'hst',
184184
'label' => $this->t('HST'),
185-
'amounts' => [
186-
['amount' => '0.13', 'start_date' => '2010-07-01'],
185+
'percentages' => [
186+
['number' => '0.13', 'start_date' => '2010-07-01'],
187187
],
188188
],
189189
],
@@ -199,8 +199,8 @@ public function buildZones() {
199199
[
200200
'id' => 'hst',
201201
'label' => $this->t('HST'),
202-
'amounts' => [
203-
['amount' => '0.14', 'start_date' => '2013-04-01'],
202+
'percentages' => [
203+
['number' => '0.14', 'start_date' => '2013-04-01'],
204204
],
205205
],
206206
],
@@ -216,8 +216,8 @@ public function buildZones() {
216216
[
217217
'id' => 'qst',
218218
'label' => $this->t('QST'),
219-
'amounts' => [
220-
['amount' => '0.09975', 'start_date' => '2013-01-01'],
219+
'percentages' => [
220+
['number' => '0.09975', 'start_date' => '2013-01-01'],
221221
],
222222
],
223223
],

modules/tax/src/Plugin/Commerce/TaxType/Custom.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ public function defaultConfiguration() {
8383
] + parent::defaultConfiguration();
8484
}
8585

86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function setConfiguration(array $configuration) {
90+
parent::setConfiguration($configuration);
91+
92+
foreach ($this->configuration['rates'] as &$rate) {
93+
if (isset($rate['amount'])) {
94+
// The 'amount' property was renamed to 'percentage' in 2.0-rc2.
95+
$rate['percentage'] = $rate['amount'];
96+
unset($rate['amount']);
97+
}
98+
}
99+
}
100+
86101
/**
87102
* {@inheritdoc}
88103
*/
@@ -123,7 +138,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
123138
'#type' => 'table',
124139
'#header' => [
125140
$this->t('Tax rate'),
126-
$this->t('Amount'),
141+
$this->t('Percentage'),
127142
$this->t('Operations'),
128143
],
129144
'#input' => FALSE,
@@ -141,10 +156,10 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
141156
'#maxlength' => 255,
142157
'#required' => TRUE,
143158
];
144-
$rate_form['amount'] = [
159+
$rate_form['percentage'] = [
145160
'#type' => 'commerce_number',
146-
'#title' => $this->t('Amount'),
147-
'#default_value' => $rate ? $rate['amount'] * 100 : 0,
161+
'#title' => $this->t('Percentage'),
162+
'#default_value' => $rate ? $rate['percentage'] * 100 : 0,
148163
'#field_suffix' => $this->t('%'),
149164
'#min' => 0,
150165
'#max' => 100,
@@ -306,7 +321,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
306321
$this->configuration['rates'][] = [
307322
'id' => $rate['rate']['id'],
308323
'label' => $rate['rate']['label'],
309-
'amount' => $rate['amount'] / 100,
324+
'percentage' => $rate['percentage'] / 100,
310325
];
311326
}
312327
$this->configuration['territories'] = [];
@@ -363,14 +378,14 @@ public function shouldRound() {
363378
*/
364379
public function buildZones() {
365380
$rates = $this->configuration['rates'];
366-
// The plugin doesn't support defining multiple amounts with own
381+
// The plugin doesn't support defining multiple percentages with own
367382
// start/end dates for UX reasons, so a start date is invented here.
368383
foreach ($rates as &$rate) {
369-
$rate['amounts'][] = [
370-
'amount' => $rate['amount'],
384+
$rate['percentages'][] = [
385+
'number' => $rate['percentage'],
371386
'start_date' => '2000-01-01',
372387
];
373-
unset($rate['amount']);
388+
unset($rate['percentage']);
374389
}
375390
// The first defined rate is assumed to be the default.
376391
$rates[0]['default'] = TRUE;

0 commit comments

Comments
 (0)