Skip to content

Commit 34c0cd2

Browse files
authored
ENGCOM-3491: #14849: [Forwardport] In Sales Emails no translation using order.getStatusLabel(). #19182
2 parents cf80050 + 8a76c78 commit 34c0cd2

19 files changed

+115
-69
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Directory\Model\Currency;
99
use Magento\Framework\Api\AttributeValueFactory;
1010
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Framework\Locale\ResolverInterface;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
1314
use Magento\Sales\Api\Data\OrderInterface;
@@ -1040,10 +1041,21 @@ public function setState($state)
10401041
return $this->setData(self::STATE, $state);
10411042
}
10421043

1044+
/**
1045+
* Retrieve frontend label of order status
1046+
*
1047+
* @return string
1048+
*/
1049+
public function getFrontendStatusLabel()
1050+
{
1051+
return $this->getConfig()->getStatusFrontendLabel($this->getStatus());
1052+
}
1053+
10431054
/**
10441055
* Retrieve label of order status
10451056
*
10461057
* @return string
1058+
* @throws LocalizedException
10471059
*/
10481060
public function getStatusLabel()
10491061
{
@@ -1151,12 +1163,12 @@ public function place()
11511163
* Hold order
11521164
*
11531165
* @return $this
1154-
* @throws \Magento\Framework\Exception\LocalizedException
1166+
* @throws LocalizedException
11551167
*/
11561168
public function hold()
11571169
{
11581170
if (!$this->canHold()) {
1159-
throw new \Magento\Framework\Exception\LocalizedException(__('A hold action is not available.'));
1171+
throw new LocalizedException(__('A hold action is not available.'));
11601172
}
11611173
$this->setHoldBeforeState($this->getState());
11621174
$this->setHoldBeforeStatus($this->getStatus());
@@ -1169,12 +1181,12 @@ public function hold()
11691181
* Attempt to unhold the order
11701182
*
11711183
* @return $this
1172-
* @throws \Magento\Framework\Exception\LocalizedException
1184+
* @throws LocalizedException
11731185
*/
11741186
public function unhold()
11751187
{
11761188
if (!$this->canUnhold()) {
1177-
throw new \Magento\Framework\Exception\LocalizedException(__('You cannot remove the hold.'));
1189+
throw new LocalizedException(__('You cannot remove the hold.'));
11781190
}
11791191

11801192
$this->setState($this->getHoldBeforeState())
@@ -1218,7 +1230,7 @@ public function isFraudDetected()
12181230
* @param string $comment
12191231
* @param bool $graceful
12201232
* @return $this
1221-
* @throws \Magento\Framework\Exception\LocalizedException
1233+
* @throws LocalizedException
12221234
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
12231235
*/
12241236
public function registerCancellation($comment = '', $graceful = true)
@@ -1257,7 +1269,7 @@ public function registerCancellation($comment = '', $graceful = true)
12571269
$this->addStatusHistoryComment($comment, false);
12581270
}
12591271
} elseif (!$graceful) {
1260-
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot cancel this order.'));
1272+
throw new LocalizedException(__('We cannot cancel this order.'));
12611273
}
12621274
return $this;
12631275
}

app/code/Magento/Sales/Model/Order/Config.php

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Sales\Model\Order;
77

8+
use Magento\Framework\Exception\LocalizedException;
9+
810
/**
911
* Order configuration model
1012
*
@@ -73,6 +75,8 @@ public function __construct(
7375
}
7476

7577
/**
78+
* Get collection.
79+
*
7680
* @return \Magento\Sales\Model\ResourceModel\Order\Status\Collection
7781
*/
7882
protected function _getCollection()
@@ -84,8 +88,10 @@ protected function _getCollection()
8488
}
8589

8690
/**
91+
* Get state.
92+
*
8793
* @param string $state
88-
* @return Status|null
94+
* @return Status
8995
*/
9096
protected function _getState($state)
9197
{
@@ -101,9 +107,9 @@ protected function _getState($state)
101107
* Retrieve default status for state
102108
*
103109
* @param string $state
104-
* @return string
110+
* @return string|null
105111
*/
106-
public function getStateDefaultStatus($state)
112+
public function getStateDefaultStatus($state): ?string
107113
{
108114
$status = false;
109115
$stateNode = $this->_getState($state);
@@ -115,24 +121,48 @@ public function getStateDefaultStatus($state)
115121
}
116122

117123
/**
118-
* Retrieve status label
124+
* Get status label for a specified area
119125
*
120-
* @param string $code
121-
* @return string
126+
* @param string|null $code
127+
* @param string $area
128+
* @return string|null
122129
*/
123-
public function getStatusLabel($code)
130+
private function getStatusLabelForArea(?string $code, string $area): ?string
124131
{
125-
$area = $this->state->getAreaCode();
126132
$code = $this->maskStatusForArea($area, $code);
127133
$status = $this->orderStatusFactory->create()->load($code);
128134

129-
if ($area == 'adminhtml') {
135+
if ($area === 'adminhtml') {
130136
return $status->getLabel();
131137
}
132138

133139
return $status->getStoreLabel();
134140
}
135141

142+
/**
143+
* Retrieve status label for detected area
144+
*
145+
* @param string|null $code
146+
* @return string|null
147+
* @throws LocalizedException
148+
*/
149+
public function getStatusLabel($code)
150+
{
151+
$area = $this->state->getAreaCode() ?: \Magento\Framework\App\Area::AREA_FRONTEND;
152+
return $this->getStatusLabelForArea($code, $area);
153+
}
154+
155+
/**
156+
* Retrieve status label for area
157+
*
158+
* @param string|null $code
159+
* @return string|null
160+
*/
161+
public function getStatusFrontendLabel(?string $code): ?string
162+
{
163+
return $this->getStatusLabelForArea($code, \Magento\Framework\App\Area::AREA_FRONTEND);
164+
}
165+
136166
/**
137167
* Mask status for order for specified area
138168
*
@@ -249,8 +279,9 @@ public function getInvisibleOnFrontStatuses()
249279
}
250280

251281
/**
252-
* Get existing order statuses
253-
* Visible or invisible on frontend according to passed param
282+
* Get existing order statuses.
283+
*
284+
* Visible or invisible on frontend according to passed param.
254285
*
255286
* @param bool $visibility
256287
* @return array

app/code/Magento/Sales/view/frontend/email/creditmemo_update.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
1212
"var order.getCustomerName()":"Customer Name",
1313
"var order.increment_id":"Order Id",
14-
"var order.getStatusLabel()":"Order Status"
14+
"var order.getFrontendStatusLabel()":"Order Status"
1515
} @-->
1616
{{template config_path="design/email/header_template"}}
1717

@@ -24,7 +24,7 @@
2424
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2525

2626
increment_id=$order.increment_id
27-
order_status=$order.getStatusLabel()
27+
order_status=$order.getFrontendStatusLabel()
2828
|raw}}
2929
</p>
3030
<p>{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}</p>

app/code/Magento/Sales/view/frontend/email/creditmemo_update_guest.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"var creditmemo.increment_id":"Credit Memo Id",
1111
"var billing.getName()":"Guest Customer Name",
1212
"var order.increment_id":"Order Id",
13-
"var order.getStatusLabel()":"Order Status"
13+
"var order.getFrontendStatusLabel()":"Order Status"
1414
} @-->
1515
{{template config_path="design/email/header_template"}}
1616

@@ -23,7 +23,7 @@
2323
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2424

2525
increment_id=$order.increment_id
26-
order_status=$order.getStatusLabel()
26+
order_status=$order.getFrontendStatusLabel()
2727
|raw}}
2828
</p>
2929
<p>

app/code/Magento/Sales/view/frontend/email/invoice_update.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"var comment":"Invoice Comment",
1212
"var invoice.increment_id":"Invoice Id",
1313
"var order.increment_id":"Order Id",
14-
"var order.getStatusLabel()":"Order Status"
14+
"var order.getFrontendStatusLabel()":"Order Status"
1515
} @-->
1616
{{template config_path="design/email/header_template"}}
1717

@@ -24,7 +24,7 @@
2424
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2525

2626
increment_id=$order.increment_id
27-
order_status=$order.getStatusLabel()
27+
order_status=$order.getFrontendStatusLabel()
2828
|raw}}
2929
</p>
3030
<p>{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}</p>

app/code/Magento/Sales/view/frontend/email/invoice_update_guest.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"var comment":"Invoice Comment",
1111
"var invoice.increment_id":"Invoice Id",
1212
"var order.increment_id":"Order Id",
13-
"var order.getStatusLabel()":"Order Status"
13+
"var order.getFrontendStatusLabel()":"Order Status"
1414
} @-->
1515
{{template config_path="design/email/header_template"}}
1616

@@ -23,7 +23,7 @@
2323
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2424

2525
increment_id=$order.increment_id
26-
order_status=$order.getStatusLabel()
26+
order_status=$order.getFrontendStatusLabel()
2727
|raw}}
2828
</p>
2929
<p>

app/code/Magento/Sales/view/frontend/email/order_update.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"var order.getCustomerName()":"Customer Name",
1111
"var comment":"Order Comment",
1212
"var order.increment_id":"Order Id",
13-
"var order.getStatusLabel()":"Order Status"
13+
"var order.getFrontendStatusLabel()":"Order Status"
1414
} @-->
1515
{{template config_path="design/email/header_template"}}
1616

@@ -23,7 +23,7 @@
2323
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2424

2525
increment_id=$order.increment_id
26-
order_status=$order.getStatusLabel()
26+
order_status=$order.getFrontendStatusLabel()
2727
|raw}}
2828
</p>
2929
<p>{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}</p>

app/code/Magento/Sales/view/frontend/email/order_update_guest.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"var billing.getName()":"Guest Customer Name",
1010
"var comment":"Order Comment",
1111
"var order.increment_id":"Order Id",
12-
"var order.getStatusLabel()":"Order Status"
12+
"var order.getFrontendStatusLabel()":"Order Status"
1313
} @-->
1414
{{template config_path="design/email/header_template"}}
1515

@@ -22,7 +22,7 @@
2222
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2323

2424
increment_id=$order.increment_id
25-
order_status=$order.getStatusLabel()
25+
order_status=$order.getFrontendStatusLabel()
2626
|raw}}
2727
</p>
2828
<p>

app/code/Magento/Sales/view/frontend/email/shipment_update.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"var order.getCustomerName()":"Customer Name",
1111
"var comment":"Order Comment",
1212
"var order.increment_id":"Order Id",
13-
"var order.getStatusLabel()":"Order Status",
13+
"var order.getFrontendStatusLabel()":"Order Status",
1414
"var shipment.increment_id":"Shipment Id"
1515
} @-->
1616
{{template config_path="design/email/header_template"}}
@@ -24,7 +24,7 @@
2424
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2525

2626
increment_id=$order.increment_id
27-
order_status=$order.getStatusLabel()
27+
order_status=$order.getFrontendStatusLabel()
2828
|raw}}
2929
</p>
3030
<p>{{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}}</p>

app/code/Magento/Sales/view/frontend/email/shipment_update_guest.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"var billing.getName()":"Guest Customer Name",
1010
"var comment":"Order Comment",
1111
"var order.increment_id":"Order Id",
12-
"var order.getStatusLabel()":"Order Status",
12+
"var order.getFrontendStatusLabel()":"Order Status",
1313
"var shipment.increment_id":"Shipment Id"
1414
} @-->
1515
{{template config_path="design/email/header_template"}}
@@ -23,7 +23,7 @@
2323
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."
2424

2525
increment_id=$order.increment_id
26-
order_status=$order.getStatusLabel()
26+
order_status=$order.getFrontendStatusLabel()
2727
|raw}}
2828
</p>
2929
<p>

0 commit comments

Comments
 (0)