Skip to content

Commit

Permalink
Merge pull request #1430 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
ishakhsuvarov authored Aug 22, 2017
2 parents e7d2f8f + 65564bf commit df7d1c7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Model/OptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function save(
}
} else {
if (!$existingOption->getOptionId()) {
throw new NoSuchEntityException('Requested option doesn\'t exist');
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
}

$option->setData(array_merge($existingOption->getData(), $option->getData()));
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Customer/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,7 @@ Addresses,Addresses
"Password forgotten","Password forgotten"
"My Dashboard","My Dashboard"
"You are signed out","You are signed out"
"Associate to Website","Associate to Website"
"Prefix","Prefix"
"Middle Name/Initial","Middle Name/Initial"
"Suffix","Suffix"
20 changes: 18 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 @@ -211,6 +213,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
*/
protected $_currencyFactory;

/**
* @var \Magento\Eav\Model\Config
*/
private $_eavConfig;

/**
* @var \Magento\Sales\Model\Order\Status\HistoryFactory
*/
Expand Down Expand Up @@ -266,6 +273,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 @@ -294,6 +306,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 @@ -323,7 +336,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 @@ -345,6 +359,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 @@ -1829,7 +1845,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
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function _getDefaultConstructorDefinition()
/**
* Returns get() method
*
* @return string
* @return array
*/
protected function _getGetMethod()
{
Expand All @@ -223,13 +223,15 @@ protected function _getGetMethod()
/** @var ParameterReflection $parameterReflection */
$parameterReflection = $methodReflection->getParameters()[0];
$body = "if (!\$id) {\n"
. " throw new \\" . InputException::class . "('ID required');\n"
. " throw new \\" . InputException::class . "(new \\Magento\\Framework\\Phrase('ID required'));\n"
. "}\n"
. "if (!isset(\$this->registry[\$id])) {\n"
. " \$entity = \$this->" . $this->_getSourcePersistorPropertyName()
. "->loadEntity(\$id);\n"
. " if (!\$entity->getId()) {\n"
. " throw new \\" . NoSuchEntityException::class . "('Requested entity doesn\\'t exist');\n"
. " throw new \\" . NoSuchEntityException::class . "(\n"
. " new \\Magento\\Framework\\Phrase('Requested entity doesn\\'t exist')\n"
. " );\n"
. " }\n"
. " \$this->registry[\$id] = \$entity;\n"
. "}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class SampleRepository implements SampleRepositoryInterface
public function get($id)
{
if (!$id) {
throw new \Magento\Framework\Exception\InputException('ID required');
throw new \Magento\Framework\Exception\InputException(new \Magento\Framework\Phrase('ID required'));
}
if (!isset($this->registry[$id])) {
$entity = $this->sampleInterfacePersistor->loadEntity($id);
if (!$entity->getId()) {
throw new \Magento\Framework\Exception\NoSuchEntityException('Requested entity doesn\'t exist');
throw new \Magento\Framework\Exception\NoSuchEntityException(
new \Magento\Framework\Phrase('Requested entity doesn\'t exist')
);
}
$this->registry[$id] = $entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class TSampleRepository implements TSampleRepositoryInterface
public function get(int $id) : \Magento\Framework\ObjectManager\Code\Generator\TSampleInterface
{
if (!$id) {
throw new \Magento\Framework\Exception\InputException('ID required');
throw new \Magento\Framework\Exception\InputException(new \Magento\Framework\Phrase('ID required'));
}
if (!isset($this->registry[$id])) {
$entity = $this->tSampleInterfacePersistor->loadEntity($id);
if (!$entity->getId()) {
throw new \Magento\Framework\Exception\NoSuchEntityException('Requested entity doesn\'t exist');
throw new \Magento\Framework\Exception\NoSuchEntityException(
new \Magento\Framework\Phrase('Requested entity doesn\'t exist')
);
}
$this->registry[$id] = $entity;
}
Expand Down

0 comments on commit df7d1c7

Please sign in to comment.