Skip to content

FIX for issue #14849 - In Sales Emails no translation using order.getStatusLabel() #14914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Directory\Model\Currency;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Sales\Api\Data\OrderInterface;
Expand Down Expand Up @@ -977,10 +978,21 @@ public function setState($state)
return $this->setData(self::STATE, $state);
}

/**
* Retrieve frontend label of order status
*
* @return string
*/
public function getFrontendStatusLabel()
{
return $this->getConfig()->getStatusFrontendLabel($this->getStatus());
}

/**
* Retrieve label of order status
*
* @return string
* @throws LocalizedException
*/
public function getStatusLabel()
{
Expand Down Expand Up @@ -1066,12 +1078,12 @@ public function place()

/**
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function hold()
{
if (!$this->canHold()) {
throw new \Magento\Framework\Exception\LocalizedException(__('A hold action is not available.'));
throw new LocalizedException(__('A hold action is not available.'));
}
$this->setHoldBeforeState($this->getState());
$this->setHoldBeforeStatus($this->getStatus());
Expand All @@ -1084,12 +1096,12 @@ public function hold()
* Attempt to unhold the order
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function unhold()
{
if (!$this->canUnhold()) {
throw new \Magento\Framework\Exception\LocalizedException(__('You cannot remove the hold.'));
throw new LocalizedException(__('You cannot remove the hold.'));
}

$this->setState($this->getHoldBeforeState())
Expand Down Expand Up @@ -1133,7 +1145,7 @@ public function isFraudDetected()
* @param string $comment
* @param bool $graceful
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function registerCancellation($comment = '', $graceful = true)
Expand Down Expand Up @@ -1172,7 +1184,7 @@ public function registerCancellation($comment = '', $graceful = true)
$this->addStatusHistoryComment($comment, false);
}
} elseif (!$graceful) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot cancel this order.'));
throw new LocalizedException(__('We cannot cancel this order.'));
}
return $this;
}
Expand Down
42 changes: 34 additions & 8 deletions app/code/Magento/Sales/Model/Order/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Sales\Model\Order;

use Magento\Framework\Exception\LocalizedException;

/**
* Order configuration model
*
Expand Down Expand Up @@ -85,7 +87,7 @@ protected function _getCollection()

/**
* @param string $state
* @return Status|null
* @return Status
*/
protected function _getState($state)
{
Expand All @@ -101,7 +103,7 @@ protected function _getState($state)
* Retrieve default status for state
*
* @param string $state
* @return string
* @return string|null
*/
public function getStateDefaultStatus($state)
{
Expand All @@ -115,24 +117,48 @@ public function getStateDefaultStatus($state)
}

/**
* Retrieve status label
* Get status label for a specified area
*
* @param string $code
* @return string
* @param string $code
* @param string $area
* @return string
*/
public function getStatusLabel($code)
private function getStatusLabelForArea(string $code, string $area): string
{
$area = $this->state->getAreaCode();
$code = $this->maskStatusForArea($area, $code);
$status = $this->orderStatusFactory->create()->load($code);

if ($area == 'adminhtml') {
if ($area === 'adminhtml') {
return $status->getLabel();
}

return $status->getStoreLabel();
}

/**
* Retrieve status label for detected area
*
* @param string $code
* @return string
* @throws LocalizedException
*/
public function getStatusLabel($code)
{
$area = $this->state->getAreaCode() ?: \Magento\Framework\App\Area::AREA_FRONTEND;
return $this->getStatusLabelForArea($code, $area);
}

/**
* Retrieve status label for area
*
* @param string $code
* @return string
*/
public function getStatusFrontendLabel(string $code): string
{
return $this->getStatusLabelForArea($code, \Magento\Framework\App\Area::AREA_FRONTEND);
}

/**
* Mask status for order for specified area
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
"var order.getCustomerName()":"Customer Name",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var creditmemo.increment_id":"Credit Memo Id",
"var billing.getName()":"Guest Customer Name",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"var comment":"Invoice Comment",
"var invoice.increment_id":"Invoice Id",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var comment":"Invoice Comment",
"var invoice.increment_id":"Invoice Id",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/view/frontend/email/order_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var order.getCustomerName()":"Customer Name",
"var comment":"Order Comment",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"var billing.getName()":"Guest Customer Name",
"var comment":"Order Comment",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var order.getCustomerName()":"Customer Name",
"var comment":"Order Comment",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status",
"var order.getFrontendStatusLabel()":"Order Status",
"var shipment.increment_id":"Shipment Id"
} @-->
{{template config_path="design/email/header_template"}}
Expand All @@ -24,7 +24,7 @@
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"var billing.getName()":"Guest Customer Name",
"var comment":"Order Comment",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status",
"var order.getFrontendStatusLabel()":"Order Status",
"var shipment.increment_id":"Shipment Id"
} @-->
{{template config_path="design/email/header_template"}}
Expand All @@ -23,7 +23,7 @@
"Your order #%increment_id has been updated with a status of <strong>%order_status</strong>."

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
"var order.getCustomerName()":"Customer Name",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
{{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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var creditmemo.increment_id":"Credit Memo Id",
"var billing.getName()":"Guest Customer Name",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"var comment":"Invoice Comment",
"var invoice.increment_id":"Invoice Id",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
{{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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var comment":"Invoice Comment",
"var invoice.increment_id":"Invoice Id",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"var order.getCustomerName()":"Customer Name",
"var comment":"Order Comment",
"var order.increment_id":"Order Id",
"var order.getStatusLabel()":"Order Status"
"var order.getFrontendStatusLabel()":"Order Status"
} @-->
{{template config_path="design/email/header_template"}}

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

increment_id=$order.increment_id
order_status=$order.getStatusLabel()
order_status=$order.getFrontendStatusLabel()
|raw}}
{{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>
Expand Down
Loading