Skip to content

Commit df7d1c7

Browse files
Merge pull request #1430 from magento-engcom/develop-prs
[EngCom] Public Pull Requests - MAGETWO-71769: Add missing translations in Customer module #10604 - MAGETWO-71761: Resolve fatal error in repository generator #10601 - MAGETWO-71603: Translate order getCreatedAtFormatted() to store locale #10491
2 parents e7d2f8f + 65564bf commit df7d1c7

File tree

7 files changed

+69
-11
lines changed

7 files changed

+69
-11
lines changed

app/code/Magento/Bundle/Model/OptionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function save(
208208
}
209209
} else {
210210
if (!$existingOption->getOptionId()) {
211-
throw new NoSuchEntityException('Requested option doesn\'t exist');
211+
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
212212
}
213213

214214
$option->setData(array_merge($existingOption->getData(), $option->getData()));

app/code/Magento/Customer/i18n/en_US.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,7 @@ Addresses,Addresses
536536
"Password forgotten","Password forgotten"
537537
"My Dashboard","My Dashboard"
538538
"You are signed out","You are signed out"
539+
"Associate to Website","Associate to Website"
540+
"Prefix","Prefix"
541+
"Middle Name/Initial","Middle Name/Initial"
542+
"Suffix","Suffix"

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Directory\Model\Currency;
99
use Magento\Framework\Api\AttributeValueFactory;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Locale\ResolverInterface;
1012
use Magento\Framework\Pricing\PriceCurrencyInterface;
1113
use Magento\Sales\Api\Data\OrderInterface;
1214
use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
@@ -211,6 +213,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
211213
*/
212214
protected $_currencyFactory;
213215

216+
/**
217+
* @var \Magento\Eav\Model\Config
218+
*/
219+
private $_eavConfig;
220+
214221
/**
215222
* @var \Magento\Sales\Model\Order\Status\HistoryFactory
216223
*/
@@ -266,6 +273,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
266273
*/
267274
protected $timezone;
268275

276+
/**
277+
* @var ResolverInterface
278+
*/
279+
private $localeResolver;
280+
269281
/**
270282
* @param \Magento\Framework\Model\Context $context
271283
* @param \Magento\Framework\Registry $registry
@@ -294,6 +306,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
294306
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
295307
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
296308
* @param array $data
309+
* @param ResolverInterface $localeResolver
297310
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
298311
*/
299312
public function __construct(
@@ -323,7 +336,8 @@ public function __construct(
323336
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productListFactory,
324337
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
325338
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
326-
array $data = []
339+
array $data = [],
340+
ResolverInterface $localeResolver = null
327341
) {
328342
$this->_storeManager = $storeManager;
329343
$this->_orderConfig = $orderConfig;
@@ -345,6 +359,8 @@ public function __construct(
345359
$this->_trackCollectionFactory = $trackCollectionFactory;
346360
$this->salesOrderCollectionFactory = $salesOrderCollectionFactory;
347361
$this->priceCurrency = $priceCurrency;
362+
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);
363+
348364
parent::__construct(
349365
$context,
350366
$registry,
@@ -1829,7 +1845,7 @@ public function getCreatedAtFormatted($format)
18291845
new \DateTime($this->getCreatedAt()),
18301846
$format,
18311847
$format,
1832-
null,
1848+
$this->localeResolver->getDefaultLocale(),
18331849
$this->timezone->getConfigTimezone('store', $this->getStore())
18341850
);
18351851
}

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1012
use Magento\Sales\Api\Data\OrderInterface;
1113
use Magento\Sales\Model\Order;
1214
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory as HistoryCollectionFactory;
@@ -73,6 +75,16 @@ class OrderTest extends \PHPUnit\Framework\TestCase
7375
*/
7476
protected $productCollectionFactoryMock;
7577

78+
/**
79+
* @var ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
80+
*/
81+
private $localeResolver;
82+
83+
/**
84+
* @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
85+
*/
86+
private $timezone;
87+
7688
protected function setUp()
7789
{
7890
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -124,6 +136,8 @@ protected function setUp()
124136
true,
125137
['round']
126138
);
139+
$this->localeResolver = $this->createMock(ResolverInterface::class);
140+
$this->timezone = $this->createMock(TimezoneInterface::class);
127141
$this->incrementId = '#00000001';
128142
$this->eventManager = $this->createMock(\Magento\Framework\Event\Manager::class);
129143
$context = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
@@ -138,7 +152,9 @@ protected function setUp()
138152
'historyCollectionFactory' => $this->historyCollectionFactoryMock,
139153
'salesOrderCollectionFactory' => $this->salesOrderCollectionFactoryMock,
140154
'priceCurrency' => $this->priceCurrency,
141-
'productListFactory' => $this->productCollectionFactoryMock
155+
'productListFactory' => $this->productCollectionFactoryMock,
156+
'localeResolver' => $this->localeResolver,
157+
'timezone' => $this->timezone,
142158
]
143159
);
144160
}
@@ -1044,6 +1060,22 @@ public function testResetOrderWillResetPayment()
10441060
);
10451061
}
10461062

1063+
public function testGetCreatedAtFormattedUsesCorrectLocale()
1064+
{
1065+
$localeCode = 'nl_NL';
1066+
1067+
$this->localeResolver->expects($this->once())->method('getDefaultLocale')->willReturn($localeCode);
1068+
$this->timezone->expects($this->once())->method('formatDateTime')
1069+
->with(
1070+
$this->anything(),
1071+
$this->anything(),
1072+
$this->anything(),
1073+
$localeCode
1074+
);
1075+
1076+
$this->order->getCreatedAtFormatted(\IntlDateFormatter::SHORT);
1077+
}
1078+
10471079
public function notInvoicingStatesProvider()
10481080
{
10491081
return [

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Repository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected function _getDefaultConstructorDefinition()
214214
/**
215215
* Returns get() method
216216
*
217-
* @return string
217+
* @return array
218218
*/
219219
protected function _getGetMethod()
220220
{
@@ -223,13 +223,15 @@ protected function _getGetMethod()
223223
/** @var ParameterReflection $parameterReflection */
224224
$parameterReflection = $methodReflection->getParameters()[0];
225225
$body = "if (!\$id) {\n"
226-
. " throw new \\" . InputException::class . "('ID required');\n"
226+
. " throw new \\" . InputException::class . "(new \\Magento\\Framework\\Phrase('ID required'));\n"
227227
. "}\n"
228228
. "if (!isset(\$this->registry[\$id])) {\n"
229229
. " \$entity = \$this->" . $this->_getSourcePersistorPropertyName()
230230
. "->loadEntity(\$id);\n"
231231
. " if (!\$entity->getId()) {\n"
232-
. " throw new \\" . NoSuchEntityException::class . "('Requested entity doesn\\'t exist');\n"
232+
. " throw new \\" . NoSuchEntityException::class . "(\n"
233+
. " new \\Magento\\Framework\\Phrase('Requested entity doesn\\'t exist')\n"
234+
. " );\n"
233235
. " }\n"
234236
. " \$this->registry[\$id] = \$entity;\n"
235237
. "}\n"

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/_files/SampleRepository.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ class SampleRepository implements SampleRepositoryInterface
6767
public function get($id)
6868
{
6969
if (!$id) {
70-
throw new \Magento\Framework\Exception\InputException('ID required');
70+
throw new \Magento\Framework\Exception\InputException(new \Magento\Framework\Phrase('ID required'));
7171
}
7272
if (!isset($this->registry[$id])) {
7373
$entity = $this->sampleInterfacePersistor->loadEntity($id);
7474
if (!$entity->getId()) {
75-
throw new \Magento\Framework\Exception\NoSuchEntityException('Requested entity doesn\'t exist');
75+
throw new \Magento\Framework\Exception\NoSuchEntityException(
76+
new \Magento\Framework\Phrase('Requested entity doesn\'t exist')
77+
);
7678
}
7779
$this->registry[$id] = $entity;
7880
}

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Code/Generator/_files/TSampleRepository.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ class TSampleRepository implements TSampleRepositoryInterface
6767
public function get(int $id) : \Magento\Framework\ObjectManager\Code\Generator\TSampleInterface
6868
{
6969
if (!$id) {
70-
throw new \Magento\Framework\Exception\InputException('ID required');
70+
throw new \Magento\Framework\Exception\InputException(new \Magento\Framework\Phrase('ID required'));
7171
}
7272
if (!isset($this->registry[$id])) {
7373
$entity = $this->tSampleInterfacePersistor->loadEntity($id);
7474
if (!$entity->getId()) {
75-
throw new \Magento\Framework\Exception\NoSuchEntityException('Requested entity doesn\'t exist');
75+
throw new \Magento\Framework\Exception\NoSuchEntityException(
76+
new \Magento\Framework\Phrase('Requested entity doesn\'t exist')
77+
);
7678
}
7779
$this->registry[$id] = $entity;
7880
}

0 commit comments

Comments
 (0)