Skip to content

Commit 77cabe8

Browse files
author
Stanislav Idolov
authored
ENGCOM-1429: FIX for issue #14849 - In Sales Emails no translation using order.getStatusLabel() #14914
2 parents 4c86381 + 106fe00 commit 77cabe8

18 files changed

+88
-47
lines changed

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

Lines changed: 22 additions & 7 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;
@@ -977,10 +978,21 @@ public function setState($state)
977978
return $this->setData(self::STATE, $state);
978979
}
979980

981+
/**
982+
* Retrieve frontend label of order status
983+
*
984+
* @return string
985+
*/
986+
public function getFrontendStatusLabel()
987+
{
988+
return $this->getConfig()->getStatusFrontendLabel($this->getStatus());
989+
}
990+
980991
/**
981992
* Retrieve label of order status
982993
*
983994
* @return string
995+
* @throws LocalizedException
984996
*/
985997
public function getStatusLabel()
986998
{
@@ -1084,12 +1096,12 @@ public function place()
10841096

10851097
/**
10861098
* @return $this
1087-
* @throws \Magento\Framework\Exception\LocalizedException
1099+
* @throws LocalizedException
10881100
*/
10891101
public function hold()
10901102
{
10911103
if (!$this->canHold()) {
1092-
throw new \Magento\Framework\Exception\LocalizedException(__('A hold action is not available.'));
1104+
throw new LocalizedException(__('A hold action is not available.'));
10931105
}
10941106
$this->setHoldBeforeState($this->getState());
10951107
$this->setHoldBeforeStatus($this->getStatus());
@@ -1102,12 +1114,12 @@ public function hold()
11021114
* Attempt to unhold the order
11031115
*
11041116
* @return $this
1105-
* @throws \Magento\Framework\Exception\LocalizedException
1117+
* @throws LocalizedException
11061118
*/
11071119
public function unhold()
11081120
{
11091121
if (!$this->canUnhold()) {
1110-
throw new \Magento\Framework\Exception\LocalizedException(__('You cannot remove the hold.'));
1122+
throw new LocalizedException(__('You cannot remove the hold.'));
11111123
}
11121124

11131125
$this->setState($this->getHoldBeforeState())
@@ -1151,7 +1163,7 @@ public function isFraudDetected()
11511163
* @param string $comment
11521164
* @param bool $graceful
11531165
* @return $this
1154-
* @throws \Magento\Framework\Exception\LocalizedException
1166+
* @throws LocalizedException
11551167
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
11561168
*/
11571169
public function registerCancellation($comment = '', $graceful = true)
@@ -1190,7 +1202,7 @@ public function registerCancellation($comment = '', $graceful = true)
11901202
$this->addStatusHistoryComment($comment, false);
11911203
}
11921204
} elseif (!$graceful) {
1193-
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot cancel this order.'));
1205+
throw new LocalizedException(__('We cannot cancel this order.'));
11941206
}
11951207
return $this;
11961208
}
@@ -1550,7 +1562,10 @@ public function getStatusHistoryById($statusId)
15501562
public function addStatusHistory(\Magento\Sales\Model\Order\Status\History $history)
15511563
{
15521564
$history->setOrder($this);
1553-
$this->setStatus($history->getStatus());
1565+
$status = $history->getStatus();
1566+
if (null !== $status) {
1567+
$this->setStatus($status);
1568+
}
15541569
if (!$history->getId()) {
15551570
$this->setStatusHistories(array_merge($this->getStatusHistories(), [$history]));
15561571
$this->setDataChanges(true);

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>

0 commit comments

Comments
 (0)