Skip to content

Translate order getCreatedAtFormatted() to store locale #10390

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

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions app/code/Magento/Braintree/Model/LocaleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function setDefaultLocale($locale)
/**
* @inheritdoc
*/
public function getDefaultLocale()
public function getDefaultLocale($store = null)
{
return $this->resolver->getDefaultLocale();
return $this->resolver->getDefaultLocale($store);
}

/**
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Sales/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use Magento\Directory\Model\Currency;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
Expand Down Expand Up @@ -268,6 +270,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
*/
protected $timezone;

/**
* @var ResolverInterface
*/
protected $localeResolver;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -296,6 +303,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param ResolverInterface $localeResolver
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -325,7 +333,8 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
ResolverInterface $localeResolver = null
) {
$this->_storeManager = $storeManager;
$this->_orderConfig = $orderConfig;
Expand All @@ -347,6 +356,8 @@ public function __construct(
$this->_trackCollectionFactory = $trackCollectionFactory;
$this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
$this->priceCurrency = $priceCurrency;
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);

parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -1831,7 +1842,7 @@ public function getCreatedAtFormatted($format)
new \DateTime($this->getCreatedAt()),
$format,
$format,
null,
$this->localeResolver->getDefaultLocale($this->getStore()),
$this->timezone->getConfigTimezone('store', $this->getStore())
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Locale/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function setDefaultLocale($locale)
/**
* {@inheritdoc}
*/
public function getDefaultLocale()
public function getDefaultLocale($store = null)
{
if (!$this->defaultLocale) {
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType, $store);
if (!$locale) {
$locale = self::DEFAULT_LOCALE;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/internal/Magento/Framework/Locale/ResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Framework\Locale;

use Magento\Store\Api\Data\StoreInterface;

/**
* Manages locale config information
*
Expand All @@ -30,9 +32,11 @@ public function setDefaultLocale($locale);
/**
* Retrieve default locale code
*
* @param bool|int|null|string|StoreInterface $store
*
* @return string
*/
public function getDefaultLocale();
public function getDefaultLocale($store = null);

/**
* Set locale
Expand Down