Skip to content

Commit 05af89c

Browse files
committed
Merge remote-tracking branch 'perf/MAGETWO-56986' into MAGETWO-55787
2 parents 0474352 + b2437a9 commit 05af89c

File tree

8 files changed

+64
-100
lines changed

8 files changed

+64
-100
lines changed

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@
606606
<item name="websiteReader" xsi:type="string">Magento\Catalog\Model\Product\Website\ReadHandler</item>
607607
</item>
608608
<item name="create" xsi:type="array">
609-
<item name="custom_options" xsi:type="string">Magento\Catalog\Model\Product\Option\CreateHandler</item>
609+
<item name="custom_options" xsi:type="string">Magento\Catalog\Model\Product\Option\SaveHandler</item>
610610
<item name="mediaGalleryCreate" xsi:type="string">Magento\Catalog\Model\Product\Gallery\CreateHandler</item>
611611
<item name="categoryProductLinksSave" xsi:type="string">Magento\Catalog\Model\Category\Link\SaveHandler</item>
612612
<item name="websitePersistor" xsi:type="string">Magento\Catalog\Model\Product\Website\SaveHandler</item>

app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ class StockItemRepository implements StockItemRepositoryInterface
9090
*/
9191
protected $stockRegistryStorage;
9292

93-
/** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory */
94-
protected $productCollectionFactory;
95-
9693
/**
9794
* @param StockConfigurationInterface $stockConfiguration
9895
* @param StockStateProviderInterface $stockStateProvider
@@ -133,20 +130,6 @@ public function __construct(
133130
$this->dateTime = $dateTime;
134131
}
135132

136-
/**
137-
* @return \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
138-
*/
139-
private function getProductCollectionFactory()
140-
{
141-
if ($this->productCollectionFactory === null) {
142-
$this->productCollectionFactory = ObjectManager::getInstance()->get(
143-
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class
144-
);
145-
}
146-
147-
return $this->productCollectionFactory;
148-
}
149-
150133
/**
151134
* @inheritdoc
152135
*/

app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/StockItemRepositoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ protected function setUp()
156156
->setMethods(['load', 'getId', 'getTypeId', '__wakeup'])
157157
->getMock();
158158

159+
$this->productFactoryMock->expects($this->any())->method('create')->willReturn($this->productMock);
160+
159161
$this->queryBuilderFactoryMock = $this->getMockBuilder(\Magento\Framework\DB\QueryBuilderFactory::class)
160162
->setMethods(['create'])
161163
->disableOriginalConstructor()

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurations.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UpdateConfigurations
3232
'swatch_image',
3333
'small_image',
3434
'thumbnail',
35-
'image'
35+
'image',
3636
];
3737

3838
/**
@@ -65,13 +65,15 @@ public function afterInitialize(
6565
) {
6666
$configurations = $this->getConfigurations();
6767
$configurations = $this->variationHandler->duplicateImagesForVariations($configurations);
68-
foreach ($configurations as $productId => $productData) {
69-
/** @var \Magento\Catalog\Model\Product $product */
70-
$product = $this->productRepository->getById($productId, false, $this->request->getParam('store', 0));
71-
$productData = $this->variationHandler->processMediaGallery($product, $productData);
72-
$product->addData($productData);
73-
if ($product->hasDataChanges()) {
74-
$product->save();
68+
if (count($configurations)) {
69+
foreach ($configurations as $productId => $productData) {
70+
/** @var \Magento\Catalog\Model\Product $product */
71+
$product = $this->productRepository->getById($productId, false, $this->request->getParam('store', 0));
72+
$productData = $this->variationHandler->processMediaGallery($product, $productData);
73+
$product->addData($productData);
74+
if ($product->hasDataChanges()) {
75+
$product->save();
76+
}
7577
}
7678
}
7779
return $configurableProduct;
@@ -91,6 +93,12 @@ protected function getConfigurations()
9193
}
9294

9395
foreach ($configurableMatrix as $item) {
96+
if (empty($item['was_changed'])) {
97+
continue;
98+
} else {
99+
unset($item['was_changed']);
100+
}
101+
94102
if (!$item['newProduct']) {
95103
$result[$item['id']] = $this->mapData($item);
96104

app/code/Magento/ConfigurableProduct/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/Plugin/UpdateConfigurationsTest.php

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,24 @@ public function testAfterInitialize()
9090
'swatch_image' => 'simple2_swatch_image',
9191
'small_image' => 'simple2_small_image',
9292
'thumbnail' => 'simple2_thumbnail',
93-
'image' => 'simple2_image'
93+
'image' => 'simple2_image',
94+
'was_changed' => true,
9495
],
9596
[
9697
'newProduct' => false,
9798
'id' => 'product3',
98-
'qty' => '3'
99-
]
99+
'qty' => '3',
100+
'was_changed' => true,
101+
],
102+
[
103+
'newProduct' => false,
104+
'id' => 'product4',
105+
'status' => 'simple4_status',
106+
'sku' => 'simple2_sku',
107+
'name' => 'simple2_name',
108+
'price' => '3.33',
109+
'weight' => '5.55',
110+
],
100111
];
101112
$configurations = [
102113
'product2' => [
@@ -118,8 +129,8 @@ public function testAfterInitialize()
118129
];
119130
/** @var Product[]|\PHPUnit_Framework_MockObject_MockObject[] $productMocks */
120131
$productMocks = [
121-
'product2' => $this->getProductMock($configurations['product2'], true),
122-
'product3' => $this->getProductMock($configurations['product3'])
132+
'product2' => $this->getProductMock($configurations['product2'], true, true),
133+
'product3' => $this->getProductMock($configurations['product3'], false, true),
123134
];
124135

125136
$this->requestMock->expects(static::any())
@@ -161,26 +172,27 @@ public function testAfterInitialize()
161172
* @param bool $hasDataChanges
162173
* @return Product|\PHPUnit_Framework_MockObject_MockObject
163174
*/
164-
protected function getProductMock(array $expectedData = null, $hasDataChanges = false)
175+
protected function getProductMock(array $expectedData = null, $hasDataChanges = false, $wasChanged = false)
165176
{
166177
$productMock = $this->getMockBuilder(Product::class)
167178
->disableOriginalConstructor()
168179
->getMock();
169180

170-
if ($expectedData !== null) {
171-
$productMock->expects(static::once())
172-
->method('addData')
173-
->with($expectedData)
181+
if ($wasChanged !== false) {
182+
if ($expectedData !== null) {
183+
$productMock->expects(static::once())
184+
->method('addData')
185+
->with($expectedData)
186+
->willReturnSelf();
187+
}
188+
189+
$productMock->expects(static::any())
190+
->method('hasDataChanges')
191+
->willReturn($hasDataChanges);
192+
$productMock->expects($hasDataChanges ? static::once() : static::never())
193+
->method('save')
174194
->willReturnSelf();
175195
}
176-
177-
$productMock->expects(static::any())
178-
->method('hasDataChanges')
179-
->willReturn($hasDataChanges);
180-
$productMock->expects($hasDataChanges ? static::once() : static::never())
181-
->method('save')
182-
->willReturnSelf();
183-
184196
return $productMock;
185197
}
186198
}

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/dynamic-rows-configurable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ define([
391391
'small_image': row['small_image'],
392392
image: row.image,
393393
'thumbnail': row.thumbnail,
394-
'attributes': attributesText
394+
'attributes': attributesText,
395+
'was_changed': true
395396
};
396397
product[this.canEditField] = row.editable;
397398
product[this.newProductField] = row.newProduct;
398-
399399
tmpArray.push(product);
400400
}, this);
401401

app/code/Magento/Eav/Model/ResourceModel/CreateHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Eav\Model\ResourceModel;
77

88
use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository;
9+
use Magento\Eav\Model\Entity\AttributeCache;
910
use Magento\Framework\Api\SearchCriteriaBuilder;
1011
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\EntityManager\MetadataPool;
@@ -43,6 +44,11 @@ class CreateHandler implements AttributeInterface
4344
*/
4445
private $scopeResolver;
4546

47+
/**
48+
* @var AttributeCache
49+
*/
50+
private $attributeCache;
51+
4652
/**
4753
* @param AttributeRepository $attributeRepository
4854
* @param MetadataPool $metadataPool
@@ -66,11 +72,15 @@ public function __construct(
6672

6773
/**
6874
* @deprecated
69-
* @return \Magento\Eav\Model\Entity\AttributeCache
75+
* @return AttributeCache
7076
*/
7177
private function getAttributeCache()
7278
{
73-
return ObjectManager::getInstance()->get(\Magento\Eav\Model\Entity\AttributeCache::class);
79+
if ($this->attributeCache === null) {
80+
$this->attributeCache = ObjectManager::getInstance()->get(AttributeCache::class);
81+
}
82+
83+
return $this->attributeCache;
7484
}
7585

7686
/**
@@ -80,7 +90,7 @@ private function getAttributeCache()
8090
*/
8191
protected function getAttributes($entityType)
8292
{
83-
/** @var \Magento\Eav\Model\Entity\AttributeCache $cache */
93+
/** @var AttributeCache $cache */
8494
$cache = $this->getAttributeCache();
8595
if ($attributes = $cache->getAttributes($entityType)) {
8696
return $attributes;

0 commit comments

Comments
 (0)