Skip to content

Commit 6a51e7f

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'develop' into MAGETWO-36849
2 parents 0d34116 + a279c15 commit 6a51e7f

File tree

79 files changed

+2344
-1199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2344
-1199
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Backend\Block\Widget\Grid\Column\Filter;
88

9+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
10+
911
/**
1012
* Date grid column filter
1113
*/
@@ -21,23 +23,31 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt
2123
*/
2224
protected $localeResolver;
2325

26+
/**
27+
* @var DateTimeFormatterInterface
28+
*/
29+
protected $dateTimeFormatter;
30+
2431
/**
2532
* @param \Magento\Backend\Block\Context $context
2633
* @param \Magento\Framework\DB\Helper $resourceHelper
2734
* @param \Magento\Framework\Math\Random $mathRandom
2835
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
36+
* @param DateTimeFormatterInterface $dateTimeFormatter
2937
* @param array $data
3038
*/
3139
public function __construct(
3240
\Magento\Backend\Block\Context $context,
3341
\Magento\Framework\DB\Helper $resourceHelper,
3442
\Magento\Framework\Math\Random $mathRandom,
3543
\Magento\Framework\Locale\ResolverInterface $localeResolver,
44+
DateTimeFormatterInterface $dateTimeFormatter,
3645
array $data = []
3746
) {
3847
$this->mathRandom = $mathRandom;
3948
$this->localeResolver = $localeResolver;
4049
parent::__construct($context, $resourceHelper, $data);
50+
$this->dateTimeFormatter = $dateTimeFormatter;
4151
}
4252

4353
/**
@@ -121,7 +131,7 @@ public function getEscapedValue($index = null)
121131
{
122132
$value = $this->getValue($index);
123133
if ($value instanceof \DateTime) {
124-
return \IntlDateFormatter::formatObject(
134+
return $this->dateTimeFormatter->formatObject(
125135
$value,
126136
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)
127137
);

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
77

8+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
9+
810
/**
911
* Backend grid item renderer date
1012
*/
@@ -22,13 +24,23 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe
2224
*/
2325
protected static $_format = null;
2426

27+
/**
28+
* @var DateTimeFormatterInterface
29+
*/
30+
protected $dateTimeFormatter;
31+
2532
/**
2633
* @param \Magento\Backend\Block\Context $context
34+
* @param DateTimeFormatterInterface $dateTimeFormatter
2735
* @param array $data
2836
*/
29-
public function __construct(\Magento\Backend\Block\Context $context, array $data = [])
30-
{
37+
public function __construct(
38+
\Magento\Backend\Block\Context $context,
39+
DateTimeFormatterInterface $dateTimeFormatter,
40+
array $data = []
41+
) {
3142
parent::__construct($context, $data);
43+
$this->dateTimeFormatter = $dateTimeFormatter;
3244
}
3345

3446
/**
@@ -63,8 +75,10 @@ protected function _getFormat()
6375
public function render(\Magento\Framework\DataObject $row)
6476
{
6577
if ($data = $row->getData($this->getColumn()->getIndex())) {
66-
$format = $this->_getFormat();
67-
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format);
78+
return $this->dateTimeFormatter->formatObject(
79+
$this->_localeDate->date(new \DateTime($data)),
80+
$this->_getFormat()
81+
);
6882
}
6983
return $this->getColumn()->getDefault();
7084
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function execute()
6161
$resultRedirect = $this->resultRedirectFactory->create();
6262

6363
$data = $this->getRequest()->getPostValue();
64+
$productAttributeSetId = $this->getRequest()->getParam('set');
65+
$productTypeId = $this->getRequest()->getParam('type');
6466
if ($data) {
6567
try {
6668
$product = $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest()));
@@ -73,6 +75,8 @@ public function execute()
7375
$originalSku = $product->getSku();
7476
$product->save();
7577
$productId = $product->getId();
78+
$productAttributeSetId = $product->getAttributeSetId();
79+
$productTypeId = $product->getTypeId();
7680

7781
/**
7882
* Do copying data to stores
@@ -123,18 +127,21 @@ public function execute()
123127
return $resultRedirect;
124128
}
125129

126-
if ($redirectBack === 'new' && isset($product)) {
130+
if ($redirectBack === 'new') {
127131
$resultRedirect->setPath(
128132
'catalog/*/new',
129-
['set' => $product->getAttributeSetId(), 'type' => $product->getTypeId()]
133+
['set' => $productAttributeSetId, 'type' => $productTypeId]
130134
);
131135
} elseif ($redirectBack === 'duplicate' && isset($newProduct)) {
132136
$resultRedirect->setPath(
133137
'catalog/*/edit',
134138
['id' => $newProduct->getId(), 'back' => null, '_current' => true]
135139
);
136140
} elseif ($redirectBack) {
137-
$resultRedirect->setPath('catalog/*/edit', ['id' => $productId, '_current' => true]);
141+
$resultRedirect->setPath(
142+
'catalog/*/edit',
143+
['id' => $productId, '_current' => true, 'set' => $productAttributeSetId]
144+
);
138145
} else {
139146
$resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
140147
}

app/code/Magento/Catalog/Model/Entity/Attribute.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Model\Attribute\LockValidatorInterface;
99
use Magento\Framework\Api\AttributeValueFactory;
10+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1011

1112
/**
1213
* Product attribute extension with event dispatching
@@ -85,6 +86,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute
8586
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
8687
* @param \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList
8788
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
89+
* @param DateTimeFormatterInterface $dateTimeFormatter
8890
* @param LockValidatorInterface $lockValidator
8991
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
9092
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
@@ -107,6 +109,7 @@ public function __construct(
107109
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
108110
\Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList,
109111
\Magento\Framework\Locale\ResolverInterface $localeResolver,
112+
DateTimeFormatterInterface $dateTimeFormatter,
110113
LockValidatorInterface $lockValidator,
111114
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
112115
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
@@ -129,6 +132,7 @@ public function __construct(
129132
$localeDate,
130133
$reservedAttributeList,
131134
$localeResolver,
135+
$dateTimeFormatter,
132136
$resource,
133137
$resourceCollection,
134138
$data

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ public function getMediaGalleryImages()
15161516
continue;
15171517
}
15181518
$image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
1519-
$image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
1519+
$image['id'] = !empty($image['value_id']) ? $image['value_id'] : null;
15201520
$image['path'] = $directory->getAbsolutePath($this->getMediaConfig()->getMediaPath($image['file']));
15211521
$images->addItem(new \Magento\Framework\DataObject($image));
15221522
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,9 @@ public function getAffectedFields($object)
818818
$images = (array)$object->getData($this->getAttribute()->getName());
819819
$tableName = $this->_getResource()->getMainTable();
820820
foreach ($images['images'] as $value) {
821+
if (empty($value['value_id'])) {
822+
continue;
823+
}
821824
$data[$tableName][] = [
822825
'attribute_id' => $this->getAttribute()->getAttributeId(),
823826
'value_id' => $value['value_id'],

app/code/Magento/Catalog/Model/Resource/Eav/Attribute.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Catalog\Model\Attribute\LockValidatorInterface;
1212
use Magento\Framework\Api\AttributeValueFactory;
13+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1314

1415
/**
1516
* Catalog attribute model
@@ -106,6 +107,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
106107
* @param \Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor
107108
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $productFlatIndexerHelper
108109
* @param LockValidatorInterface $lockValidator
110+
* @param DateTimeFormatterInterface $dateTimeFormatter
109111
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
110112
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
111113
* @param array $data
@@ -127,6 +129,7 @@ public function __construct(
127129
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
128130
\Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList,
129131
\Magento\Framework\Locale\ResolverInterface $localeResolver,
132+
DateTimeFormatterInterface $dateTimeFormatter,
130133
\Magento\Catalog\Model\Indexer\Product\Flat\Processor $productFlatIndexerProcessor,
131134
\Magento\Catalog\Model\Indexer\Product\Eav\Processor $indexerEavProcessor,
132135
\Magento\Catalog\Helper\Product\Flat\Indexer $productFlatIndexerHelper,
@@ -155,6 +158,7 @@ public function __construct(
155158
$localeDate,
156159
$reservedAttributeList,
157160
$localeResolver,
161+
$dateTimeFormatter,
158162
$resource,
159163
$resourceCollection,
160164
$data

app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
121121
*/
122122
private $extensionAttributesFactory;
123123

124+
/**
125+
* @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface|\PHPUnit_Framework_MockObject_MockObject
126+
*/
127+
private $dateTimeFormatter;
128+
124129
protected function setUp()
125130
{
126131
$this->contextMock = $this->getMockBuilder('Magento\Framework\Model\Context')
@@ -172,6 +177,7 @@ protected function setUp()
172177
->getMock();
173178
$this->lockValidatorMock = $this->getMockBuilder('Magento\Catalog\Model\Attribute\LockValidatorInterface')
174179
->getMock();
180+
$this->dateTimeFormatter = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface');
175181

176182
$this->resourceMock = $this->getMockBuilder('Magento\Framework\Model\Resource\AbstractResource')
177183
->setMethods(['_construct', 'getConnection', 'getIdFieldName', 'saveInSetIncluding'])
@@ -206,6 +212,7 @@ protected function setUp()
206212
$this->timezoneMock,
207213
$this->reservedAttributeListMock,
208214
$this->resolverMock,
215+
$this->dateTimeFormatter,
209216
$this->lockValidatorMock,
210217
$this->resourceMock
211218
);

app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,42 @@
66
namespace Magento\Config\Block\System\Config\Form\Field;
77

88
use Magento\Framework\Data\Form\Element\AbstractElement;
9+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
910

1011
/**
1112
* Backend system config datetime field renderer
1213
*/
1314
class Datetime extends \Magento\Config\Block\System\Config\Form\Field
1415
{
16+
/**
17+
* @var DateTimeFormatterInterface
18+
*/
19+
protected $dateTimeFormatter;
20+
21+
/**
22+
* @param \Magento\Backend\Block\Template\Context $context
23+
* @param DateTimeFormatterInterface $dateTimeFormatter
24+
* @param array $data
25+
*/
26+
public function __construct(
27+
\Magento\Backend\Block\Template\Context $context,
28+
DateTimeFormatterInterface $dateTimeFormatter,
29+
array $data = []
30+
) {
31+
parent::__construct($context, $data);
32+
$this->dateTimeFormatter = $dateTimeFormatter;
33+
}
34+
1535
/**
1636
* @param AbstractElement $element
1737
* @return string
1838
* @codeCoverageIgnore
1939
*/
2040
protected function _getElementHtml(AbstractElement $element)
2141
{
22-
$format = $this->_localeDate->getDateTimeFormat(
23-
\IntlDateFormatter::MEDIUM
42+
return $this->dateTimeFormatter->formatObject(
43+
$this->_localeDate->date(intval($element->getValue())),
44+
$this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM)
2445
);
25-
return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format);
2646
}
2747
}

app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,32 @@
66
namespace Magento\Config\Block\System\Config\Form\Field;
77

88
use Magento\Framework\Data\Form\Element\AbstractElement;
9+
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
910

1011
/**
1112
* Backend system config datetime field renderer
1213
*/
1314
class Notification extends \Magento\Config\Block\System\Config\Form\Field
1415
{
16+
/**
17+
* @var DateTimeFormatterInterface
18+
*/
19+
protected $dateTimeFormatter;
20+
21+
/**
22+
* @param \Magento\Backend\Block\Template\Context $context
23+
* @param DateTimeFormatterInterface $dateTimeFormatter
24+
* @param array $data
25+
*/
26+
public function __construct(
27+
\Magento\Backend\Block\Template\Context $context,
28+
DateTimeFormatterInterface $dateTimeFormatter,
29+
array $data = []
30+
) {
31+
parent::__construct($context, $data);
32+
$this->dateTimeFormatter = $dateTimeFormatter;
33+
}
34+
1535
/**
1636
* @param AbstractElement $element
1737
* @return string
@@ -22,6 +42,6 @@ protected function _getElementHtml(AbstractElement $element)
2242
$format = $this->_localeDate->getDateTimeFormat(
2343
\IntlDateFormatter::MEDIUM
2444
);
25-
return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format);
45+
return $this->dateTimeFormatter->formatObject($this->_localeDate->date(intval($element->getValue())), $format);
2646
}
2747
}

app/code/Magento/Config/Test/Unit/Block/System/Config/Form/Field/NotificationTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ class NotificationTest extends \PHPUnit_Framework_TestCase
1313
{
1414
public function testRender()
1515
{
16+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
17+
1618
$testCacheValue = '1433259723';
17-
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
18-
$formattedDate = (\IntlDateFormatter::formatObject($testDatetime));
19-
$htmlId = 'test_HTML_id';
20-
$label = 'test_label';
19+
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
2120

22-
$cacheMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')
23-
->disableOriginalConstructor()
24-
->setMethods(['load', 'getFrontend', 'remove', 'save', 'clean'])
25-
->getMock();
26-
$cacheMock->expects($this->any())->method('load')->willReturn($testCacheValue);
21+
/** @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface $dateTimeFormatter */
22+
$dateTimeFormatter = $objectManager->getObject('Magento\Framework\Stdlib\DateTime\DateTimeFormatter');
23+
$formattedDate = $dateTimeFormatter->formatObject($testDatetime);
24+
25+
$htmlId = 'test_HTML_id';
26+
$label = 'test_label';
2727

2828
$localeDateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\TimezoneInterface')
2929
->disableOriginalConstructor()
@@ -38,13 +38,18 @@ public function testRender()
3838
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
3939
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
4040

41-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
41+
$dateTimeFormatter = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface');
42+
$dateTimeFormatter->expects($this->once())
43+
->method('formatObject')
44+
->with($testDatetime)
45+
->willReturn($formattedDate);
4246

47+
/** @var \Magento\Config\Block\System\Config\Form\Field\Notification $notification */
4348
$notification = $objectManager->getObject(
4449
'Magento\Config\Block\System\Config\Form\Field\Notification',
4550
[
46-
'cache' => $cacheMock,
4751
'localeDate' => $localeDateMock,
52+
'dateTimeFormatter' => $dateTimeFormatter,
4853
]
4954
);
5055

0 commit comments

Comments
 (0)