Skip to content
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

[Backport 2.2] Translate order getCreatedAtFormatted() to store locale #11422

Merged
merged 2 commits into from
Nov 25, 2017
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
17 changes: 14 additions & 3 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 @@ -267,6 +269,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
*/
protected $timezone;

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

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand Down Expand Up @@ -295,7 +302,9 @@ 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)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand Down Expand Up @@ -324,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 @@ -335,7 +345,6 @@ public function __construct(
$this->_productVisibility = $productVisibility;
$this->invoiceManagement = $invoiceManagement;
$this->_currencyFactory = $currencyFactory;
$this->_eavConfig = $eavConfig;
$this->_orderHistoryFactory = $orderHistoryFactory;
$this->_addressCollectionFactory = $addressCollectionFactory;
$this->_paymentCollectionFactory = $paymentCollectionFactory;
Expand All @@ -346,6 +355,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 @@ -1830,7 +1841,7 @@ public function getCreatedAtFormatted($format)
new \DateTime($this->getCreatedAt()),
$format,
$format,
null,
$this->localeResolver->getDefaultLocale(),
$this->timezone->getConfigTimezone('store', $this->getStore())
);
}
Expand Down
34 changes: 33 additions & 1 deletion app/code/Magento/Sales/Test/Unit/Model/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory as HistoryCollectionFactory;
Expand Down Expand Up @@ -73,6 +75,16 @@ class OrderTest extends \PHPUnit\Framework\TestCase
*/
protected $productCollectionFactoryMock;

/**
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $localeResolver;

/**
* @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $timezone;

protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand Down Expand Up @@ -124,6 +136,8 @@ protected function setUp()
true,
['round']
);
$this->localeResolver = $this->createMock(ResolverInterface::class);
$this->timezone = $this->createMock(TimezoneInterface::class);
$this->incrementId = '#00000001';
$this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
$context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
Expand All @@ -138,7 +152,9 @@ protected function setUp()
'historyCollectionFactory' => $this->historyCollectionFactoryMock,
'salesOrderCollectionFactory' => $this->salesOrderCollectionFactoryMock,
'priceCurrency' => $this->priceCurrency,
'productListFactory' => $this->productCollectionFactoryMock
'productListFactory' => $this->productCollectionFactoryMock,
'localeResolver' => $this->localeResolver,
'timezone' => $this->timezone,
]
);
}
Expand Down Expand Up @@ -1044,6 +1060,22 @@ public function testResetOrderWillResetPayment()
);
}

public function testGetCreatedAtFormattedUsesCorrectLocale()
{
$localeCode = 'nl_NL';

$this->localeResolver->expects($this->once())->method('getDefaultLocale')->willReturn($localeCode);
$this->timezone->expects($this->once())->method('formatDateTime')
->with(
$this->anything(),
$this->anything(),
$this->anything(),
$localeCode
);

$this->order->getCreatedAtFormatted(\IntlDateFormatter::SHORT);
}

public function notInvoicingStatesProvider()
{
return [
Expand Down