Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ public function getFormatArray($addressAttributes = null)
*
* @param array $addressAttributes
* @param Format|null $format
* @param string|null $locale
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function renderArray($addressAttributes, $format = null)
public function renderArray($addressAttributes, $format = null, $locale = null)
{
switch ($this->getType()->getCode()) {
case 'html':
Expand All @@ -174,7 +175,7 @@ public function renderArray($addressAttributes, $format = null)
if ($attributeCode == 'country_id' && isset($addressAttributes['country_id'])) {
$data['country'] = $this->_countryFactory->create()->loadByCode(
$addressAttributes['country_id']
)->getName();
)->getName($locale);
} elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) {
$data['region'] = (string)__($addressAttributes['region']);
} elseif (isset($addressAttributes[$attributeCode])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function getFormatArray($addressAttributes = null);
*
* @param array $addressAttributes
* @param Format|null $format
* @param string|null $locale
* @return string
*/
public function renderArray($addressAttributes, $format = null);
public function renderArray($addressAttributes, $format = null, $locale = null);
}
17 changes: 16 additions & 1 deletion app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Sales\Model;

use Magento\Config\Model\Config\Source\Nooptreq;
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Directory\Model\Currency;
use Magento\Directory\Model\RegionFactory;
use Magento\Framework\Api\AttributeValueFactory;
Expand Down Expand Up @@ -2052,7 +2053,7 @@ public function getCreatedAtFormatted($format)
new \DateTime($this->getCreatedAt()),
$format,
$format,
$this->localeResolver->getDefaultLocale(),
$this->getLocale(),
$this->timezone->getConfigTimezone('store', $this->getStore())
);
}
Expand Down Expand Up @@ -4586,6 +4587,20 @@ public function setShippingMethod($shippingMethod)
return $this->setData('shipping_method', $shippingMethod);
}

/**
* Return the locale for the order's store
*
* @return string
*/
private function getLocale(): string
{
return (string) $this->scopeConfig->getValue(
DirectoryHelper::XML_PATH_DEFAULT_LOCALE,
ScopeInterface::SCOPE_STORES,
$this->getStoreId()
);
}

/**
* Is visible customer middlename
*
Expand Down
20 changes: 18 additions & 2 deletions app/code/Magento/Sales/Model/Order/Address/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
namespace Magento\Sales\Model\Order\Address;

use Magento\Customer\Model\Address\Config as AddressConfig;
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Magento\Sales\Model\Order\Address;
use Magento\Store\Model\ScopeInterface;

/**
* Class Renderer used for formatting an order address
Expand All @@ -27,18 +30,26 @@ class Renderer
*/
protected $eventManager;

/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;

/**
* Constructor
*
* @param AddressConfig $addressConfig
* @param EventManager $eventManager
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
AddressConfig $addressConfig,
EventManager $eventManager
EventManager $eventManager,
ScopeConfigInterface $scopeConfig
) {
$this->addressConfig = $addressConfig;
$this->eventManager = $eventManager;
$this->scopeConfig = $scopeConfig;
}

/**
Expand All @@ -56,6 +67,11 @@ public function format(Address $address, $type)
return null;
}
$this->eventManager->dispatch('customer_address_format', ['type' => $formatType, 'address' => $address]);
return $formatType->getRenderer()->renderArray($address->getData());
$locale = $this->scopeConfig->getValue(
DirectoryHelper::XML_PATH_DEFAULT_LOCALE,
ScopeInterface::SCOPE_STORES,
$address->getOrder()->getStoreId()
);
return $formatType->getRenderer()->renderArray($address->getData(), null, $locale);
}
}