Skip to content

Commit b2c8564

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into PR_Branch
2 parents 4733c43 + d447fa6 commit b2c8564

File tree

109 files changed

+2466
-1352
lines changed

Some content is hidden

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

109 files changed

+2466
-1352
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
use Magento\Backend\App\Action;
1010
use Magento\Catalog\Controller\Adminhtml\Product;
1111
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\App\Request\DataPersistorInterface;
1213

14+
/**
15+
* Class Save
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
1318
class Save extends \Magento\Catalog\Controller\Adminhtml\Product
1419
{
1520
/**
@@ -37,6 +42,11 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product
3742
*/
3843
protected $productRepository;
3944

45+
/**
46+
* @var DataPersistorInterface
47+
*/
48+
protected $dataPersistor;
49+
4050
/**
4151
* @var StoreManagerInterface
4252
*/
@@ -110,6 +120,7 @@ public function execute()
110120
$this->copyToStores($data, $productId);
111121

112122
$this->messageManager->addSuccess(__('You saved the product.'));
123+
$this->getDataPersistor()->clear('catalog_product');
113124
if ($product->getSku() != $originalSku) {
114125
$this->messageManager->addNotice(
115126
__(
@@ -131,11 +142,13 @@ public function execute()
131142
} catch (\Magento\Framework\Exception\LocalizedException $e) {
132143
$this->messageManager->addError($e->getMessage());
133144
$this->_session->setProductData($data);
145+
$this->getDataPersistor()->set('catalog_product', $data);
134146
$redirectBack = $productId ? true : 'new';
135147
} catch (\Exception $e) {
136148
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
137149
$this->messageManager->addError($e->getMessage());
138150
$this->_session->setProductData($data);
151+
$this->getDataPersistor()->set('catalog_product', $data);
139152
$redirectBack = $productId ? true : 'new';
140153
}
141154
} else {
@@ -246,4 +259,18 @@ private function getStoreManager()
246259
}
247260
return $this->storeManager;
248261
}
262+
263+
/**
264+
* Retrieve data persistor
265+
*
266+
* @return DataPersistorInterface|mixed
267+
*/
268+
protected function getDataPersistor()
269+
{
270+
if (null === $this->dataPersistor) {
271+
$this->dataPersistor = $this->_objectManager->get(DataPersistorInterface::class);
272+
}
273+
274+
return $this->dataPersistor;
275+
}
249276
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,32 @@ public function process(\DOMElement $mediaNode, $mediaParentTag)
3030
if ($attribute->nodeType != XML_ELEMENT_NODE) {
3131
continue;
3232
}
33-
$nodeValue = $attribute->nodeValue;
33+
if ($attribute->tagName == 'background') {
34+
$nodeValue = $this->processImageBackground($attribute->nodeValue);
35+
} else {
36+
$nodeValue = $attribute->nodeValue;
37+
}
3438
$result[$mediaParentTag][$moduleNameImage][Image::MEDIA_TYPE_CONFIG_NODE][$imageId][$attribute->tagName]
3539
= $nodeValue;
3640
}
3741
}
3842

3943
return $result;
4044
}
45+
46+
/**
47+
* Convert rgb background string into array
48+
*
49+
* @param string $backgroundString
50+
* @return int[]
51+
*/
52+
private function processImageBackground($backgroundString)
53+
{
54+
$pattern = '#\[(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\]#';
55+
$backgroundArray = [];
56+
if (preg_match($pattern, $backgroundString, $backgroundArray)) {
57+
array_shift($backgroundArray);
58+
}
59+
return $backgroundArray;
60+
}
4161
}

app/code/Magento/Catalog/Model/Locator/RegistryLocator.php

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
namespace Magento\Catalog\Model\Locator;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\Exception\NotFoundException;
810
use Magento\Framework\Registry;
11+
use Magento\Store\Api\Data\StoreInterface;
912

1013
/**
1114
* Class RegistryLocator
@@ -15,7 +18,17 @@ class RegistryLocator implements LocatorInterface
1518
/**
1619
* @var Registry
1720
*/
18-
protected $registry;
21+
private $registry;
22+
23+
/**
24+
* @var ProductInterface
25+
*/
26+
private $product;
27+
28+
/**
29+
* @var StoreInterface
30+
*/
31+
private $store;
1932

2033
/**
2134
* @param Registry $registry
@@ -27,30 +40,46 @@ public function __construct(Registry $registry)
2740

2841
/**
2942
* {@inheritdoc}
43+
* @throws NotFoundException
3044
*/
3145
public function getProduct()
3246
{
33-
return $this->registry->registry('current_product');
47+
if (null !== $this->product) {
48+
return $this->product;
49+
}
50+
51+
if ($product = $this->registry->registry('current_product')) {
52+
return $this->product = $product;
53+
}
54+
55+
throw new NotFoundException(__('Product was not registered'));
3456
}
3557

3658
/**
3759
* {@inheritdoc}
60+
* @throws NotFoundException
3861
*/
3962
public function getStore()
4063
{
41-
return $this->registry->registry('current_store');
42-
}
64+
if (null !== $this->store) {
65+
return $this->store;
66+
}
4367

68+
if ($store = $this->registry->registry('current_store')) {
69+
return $this->store = $store;
70+
}
71+
72+
throw new NotFoundException(__('Store was not registered'));
73+
}
4474

4575
/**
4676
* {@inheritdoc}
4777
*/
4878
public function getWebsiteIds()
4979
{
50-
return $this->registry->registry('current_product')->getWebsiteIds();
80+
return $this->getProduct()->getWebsiteIds();
5181
}
5282

53-
5483
/**
5584
* {@inheritdoc}
5685
*/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
10+
class ImageExtractorTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \Magento\Catalog\Model\ImageExtractor
14+
*/
15+
private $model;
16+
17+
protected function setUp()
18+
{
19+
$objectManager = new ObjectManager($this);
20+
$this->model = $objectManager->getObject(\Magento\Catalog\Model\ImageExtractor::class);
21+
}
22+
23+
public function testProcess()
24+
{
25+
$expectedArray = include(__DIR__ . '/_files/converted_view.php');
26+
$this->assertEquals($expectedArray, $this->model->process($this->getDomElement(), 'media'));
27+
}
28+
29+
/**
30+
* Get mocked dom element
31+
*
32+
* @return \DOMElement
33+
*/
34+
private function getDomElement()
35+
{
36+
$doc = new \DOMDocument();
37+
$doc->load(__DIR__ . '/_files/valid_view.xml');
38+
return $doc->getElementsByTagName('images')->item(0);
39+
}
40+
}

app/code/Magento/Catalog/Test/Unit/Model/Locator/RegistryLocatorTest.php

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Locator\RegistryLocator;
1010
use Magento\Framework\Registry;
1111
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Store\Api\Data\StoreInterface;
1213

1314
/**
1415
* Class RegistryLocatorTest
@@ -26,36 +27,75 @@ class RegistryLocatorTest extends \PHPUnit_Framework_TestCase
2627
protected $model;
2728

2829
/**
29-
* @var Registry
30+
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
3031
*/
3132
protected $registryMock;
3233

3334
/**
34-
* @var ProductInterface
35+
* @var ProductInterface|\PHPUnit_Framework_MockObject_MockObject
3536
*/
3637
protected $productMock;
3738

39+
/**
40+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $storeMock;
43+
3844
protected function setUp()
3945
{
4046
$this->objectManager = new ObjectManager($this);
41-
$this->registryMock = $this->getMockBuilder('Magento\Framework\Registry')
47+
$this->registryMock = $this->getMockBuilder(Registry::class)
4248
->setMethods(['registry'])
4349
->getMock();
44-
$this->productMock = $this->getMockBuilder('Magento\Catalog\Api\Data\ProductInterface')
50+
$this->productMock = $this->getMockBuilder(ProductInterface::class)
51+
->getMockForAbstractClass();
52+
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
4553
->getMockForAbstractClass();
4654

55+
$this->model = $this->objectManager->getObject(RegistryLocator::class, [
56+
'registry' => $this->registryMock,
57+
]);
58+
}
59+
60+
public function testGetProduct()
61+
{
4762
$this->registryMock->expects($this->once())
4863
->method('registry')
4964
->with('current_product')
5065
->willReturn($this->productMock);
5166

52-
$this->model = $this->objectManager->getObject('Magento\Catalog\Model\Locator\RegistryLocator', [
53-
'registry' => $this->registryMock,
54-
]);
67+
$this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
68+
// Lazy loading
69+
$this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
5570
}
5671

57-
public function testGetProduct()
72+
public function testGetStore()
73+
{
74+
$this->registryMock->expects($this->once())
75+
->method('registry')
76+
->with('current_store')
77+
->willReturn($this->storeMock);
78+
79+
$this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
80+
// Lazy loading
81+
$this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
82+
}
83+
84+
/**
85+
* @expectedException \Magento\Framework\Exception\NotFoundException
86+
* @expectedExceptionMessage Product was not registered
87+
*/
88+
public function testGetProductWithException()
89+
{
90+
$this->assertInstanceOf(ProductInterface::class, $this->model->getProduct());
91+
}
92+
93+
/**
94+
* @expectedException \Magento\Framework\Exception\NotFoundException
95+
* @expectedExceptionMessage Store was not registered
96+
*/
97+
public function testGetStoreWithException()
5898
{
59-
$this->assertInstanceOf('Magento\Catalog\Api\Data\ProductInterface', $this->model->getProduct());
99+
$this->assertInstanceOf(StoreInterface::class, $this->model->getStore());
60100
}
61101
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
return [
7+
"media" => [
8+
"Magento_Catalog" => [
9+
"images" => [
10+
"swatch_thumb_base" => [
11+
"type" => "swatch_thumb",
12+
"width" => 75,
13+
"height" => 75,
14+
"background" => [255, 25, 2]
15+
]
16+
]
17+
]
18+
]
19+
];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
9+
<media>
10+
<images module="Magento_Catalog">
11+
<image id="swatch_thumb_base" type="swatch_thumb">
12+
<width>75</width>
13+
<height>75</height>
14+
<background>[255, 25, 2]</background>
15+
</image>
16+
</images>
17+
</media>
18+
</view>

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AbstractModifierTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function setUp()
6666
'getExistsStoreValueFlag'
6767
])->getMockForAbstractClass();
6868
$this->storeMock = $this->getMockBuilder(StoreInterface::class)
69-
->setMethods(['load', 'getId'])
69+
->setMethods(['load', 'getId', 'getConfig'])
7070
->getMockForAbstractClass();
7171
$this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
7272
->disableOriginalConstructor()

app/code/Magento/Catalog/Ui/Component/Listing/Columns/Websites.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function prepareDataSource(array $dataSource)
5656
foreach ($dataSource['data']['items'] as & $item) {
5757
$websites = [];
5858
foreach ($item[$fieldName] as $websiteId) {
59+
if (!isset($websiteNames[$websiteId])) {
60+
continue;
61+
}
5962
$websites[] = $websiteNames[$websiteId];
6063
}
6164
$item[$fieldName] = implode(', ', $websites);

0 commit comments

Comments
 (0)