Skip to content

Commit 76d181f

Browse files
author
Oleksandr Karpenko
committed
Merge branch 'develop' of https://github.corp.magento.com/magento2/magento2ce into develop
2 parents a1abfa7 + ab051bf commit 76d181f

File tree

166 files changed

+4104
-2144
lines changed

Some content is hidden

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

166 files changed

+4104
-2144
lines changed

app/code/Magento/Backend/view/adminhtml/templates/admin/login.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
value=""
2828
data-validate="{required:true}"
2929
placeholder="<?php /* @escapeNotVerified */ echo __('user name') ?>"
30-
autocomplete="username"
30+
autocomplete="off"
3131
/>
3232
</div>
3333
</div>
@@ -43,7 +43,7 @@
4343
data-validate="{required:true}"
4444
value=""
4545
placeholder="<?php /* @escapeNotVerified */ echo __('password') ?>"
46-
autocomplete="current-password"
46+
autocomplete="off"
4747
/>
4848
</div>
4949
</div>

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
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Converter
1919
protected function indexBySku(array $products)
2020
{
2121
$converted = [];
22-
foreach($products as $product) {
22+
foreach ($products as $product) {
2323
$converted[$product->getSku()] = $product;
2424
}
2525
return $converted;
@@ -34,7 +34,7 @@ public function convertLinksToGroupedArray($entity)
3434
$basicData = $entity->getProductLinks();
3535
$associatedProducts = $entity->getTypeInstance()->getAssociatedProducts($entity);
3636
$associatedProducts = $this->indexBySku($associatedProducts);
37-
37+
$linksAsArray = [];
3838
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $link */
3939
foreach ($basicData as $link) {
4040
$info = $link->getData();
@@ -46,4 +46,4 @@ public function convertLinksToGroupedArray($entity)
4646
}
4747
return $linksAsArray;
4848
}
49-
}
49+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ class Resolver
1717
*/
1818
protected $links = null;
1919

20+
/**
21+
* Resolver constructor.
22+
* @param \Magento\Framework\App\RequestInterface $request
23+
*/
2024
public function __construct(
2125
\Magento\Framework\App\RequestInterface $request
2226
) {
2327
$this->request = $request;
2428
}
2529

26-
2730
/**
2831
* Get stored value.
2932
* Fallback to request if none.
@@ -42,6 +45,7 @@ public function getLinks()
4245
* Override link data from request
4346
*
4447
* @param array|null $links
48+
* @return void
4549
*/
4650
public function override($links)
4751
{

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Api\ImageProcessorInterface;
1616
use Magento\Framework\Api\SortOrder;
1717
use Magento\Framework\Exception\InputException;
18+
use Magento\Framework\Exception\LocalizedException;
1819
use Magento\Framework\Exception\NoSuchEntityException;
1920
use Magento\Framework\Exception\StateException;
2021
use Magento\Framework\Exception\ValidatorException;
@@ -546,6 +547,8 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
546547
);
547548
} catch (ValidatorException $e) {
548549
throw new CouldNotSaveException(__($e->getMessage()));
550+
} catch (LocalizedException $e) {
551+
throw $e;
549552
} catch (\Exception $e) {
550553
throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
551554
}
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+
}

0 commit comments

Comments
 (0)