Skip to content

Commit bbf1247

Browse files
committed
#14849: [Forwardport] In Sales Emails no translation using order.getStatusLabel().
1 parent 5f976fa commit bbf1247

18 files changed

+84
-46
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;
@@ -1024,10 +1025,21 @@ public function setState($state)
10241025
return $this->setData(self::STATE, $state);
10251026
}
10261027

1028+
/**
1029+
* Retrieve frontend label of order status
1030+
*
1031+
* @return string
1032+
*/
1033+
public function getFrontendStatusLabel()
1034+
{
1035+
return $this->getConfig()->getStatusFrontendLabel($this->getStatus());
1036+
}
1037+
10271038
/**
10281039
* Retrieve label of order status
10291040
*
10301041
* @return string
1042+
* @throws LocalizedException
10311043
*/
10321044
public function getStatusLabel()
10331045
{
@@ -1135,12 +1147,12 @@ public function place()
11351147
* Hold order
11361148
*
11371149
* @return $this
1138-
* @throws \Magento\Framework\Exception\LocalizedException
1150+
* @throws LocalizedException
11391151
*/
11401152
public function hold()
11411153
{
11421154
if (!$this->canHold()) {
1143-
throw new \Magento\Framework\Exception\LocalizedException(__('A hold action is not available.'));
1155+
throw new LocalizedException(__('A hold action is not available.'));
11441156
}
11451157
$this->setHoldBeforeState($this->getState());
11461158
$this->setHoldBeforeStatus($this->getStatus());
@@ -1153,12 +1165,12 @@ public function hold()
11531165
* Attempt to unhold the order
11541166
*
11551167
* @return $this
1156-
* @throws \Magento\Framework\Exception\LocalizedException
1168+
* @throws LocalizedException
11571169
*/
11581170
public function unhold()
11591171
{
11601172
if (!$this->canUnhold()) {
1161-
throw new \Magento\Framework\Exception\LocalizedException(__('You cannot remove the hold.'));
1173+
throw new LocalizedException(__('You cannot remove the hold.'));
11621174
}
11631175

11641176
$this->setState($this->getHoldBeforeState())
@@ -1202,7 +1214,7 @@ public function isFraudDetected()
12021214
* @param string $comment
12031215
* @param bool $graceful
12041216
* @return $this
1205-
* @throws \Magento\Framework\Exception\LocalizedException
1217+
* @throws LocalizedException
12061218
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
12071219
*/
12081220
public function registerCancellation($comment = '', $graceful = true)
@@ -1241,7 +1253,7 @@ public function registerCancellation($comment = '', $graceful = true)
12411253
$this->addStatusHistoryComment($comment, false);
12421254
}
12431255
} elseif (!$graceful) {
1244-
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot cancel this order.'));
1256+
throw new LocalizedException(__('We cannot cancel this order.'));
12451257
}
12461258
return $this;
12471259
}

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

Lines changed: 34 additions & 8 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
*
@@ -85,7 +87,7 @@ protected function _getCollection()
8587

8688
/**
8789
* @param string $state
88-
* @return Status|null
90+
* @return Status
8991
*/
9092
protected function _getState($state)
9193
{
@@ -101,7 +103,7 @@ protected function _getState($state)
101103
* Retrieve default status for state
102104
*
103105
* @param string $state
104-
* @return string
106+
* @return string|null
105107
*/
106108
public function getStateDefaultStatus($state)
107109
{
@@ -115,24 +117,48 @@ public function getStateDefaultStatus($state)
115117
}
116118

117119
/**
118-
* Retrieve status label
120+
* Get status label for a specified area
119121
*
120-
* @param string $code
121-
* @return string
122+
* @param string $code
123+
* @param string $area
124+
* @return string
122125
*/
123-
public function getStatusLabel($code)
126+
private function getStatusLabelForArea(string $code, string $area): string
124127
{
125-
$area = $this->state->getAreaCode();
126128
$code = $this->maskStatusForArea($area, $code);
127129
$status = $this->orderStatusFactory->create()->load($code);
128130

129-
if ($area == 'adminhtml') {
131+
if ($area === 'adminhtml') {
130132
return $status->getLabel();
131133
}
132134

133135
return $status->getStoreLabel();
134136
}
135137

138+
/**
139+
* Retrieve status label for detected area
140+
*
141+
* @param string $code
142+
* @return string
143+
* @throws LocalizedException
144+
*/
145+
public function getStatusLabel($code)
146+
{
147+
$area = $this->state->getAreaCode() ?: \Magento\Framework\App\Area::AREA_FRONTEND;
148+
return $this->getStatusLabelForArea($code, $area);
149+
}
150+
151+
/**
152+
* Retrieve status label for area
153+
*
154+
* @param string $code
155+
* @return string
156+
*/
157+
public function getStatusFrontendLabel(string $code): string
158+
{
159+
return $this->getStatusLabelForArea($code, \Magento\Framework\App\Area::AREA_FRONTEND);
160+
}
161+
136162
/**
137163
* Mask status for order for specified area
138164
*

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>

app/design/frontend/Magento/luma/Magento_Sales/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
{{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}}
3030
</p>

app/design/frontend/Magento/luma/Magento_Sales/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/design/frontend/Magento/luma/Magento_Sales/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
{{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}}
3030
</p>

app/design/frontend/Magento/luma/Magento_Sales/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/design/frontend/Magento/luma/Magento_Sales/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
{{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}}
2929
</p>

0 commit comments

Comments
 (0)