Skip to content

Commit 3a2292e

Browse files
authored
Merge pull request #1297 from magento-east/MAGETWO-66588
[EAST] MAGETWO-66588: [Backport] Perfomance toolkit generator improvement for 2.1
2 parents d98c1d3 + ef6a60e commit 3a2292e

File tree

190 files changed

+103700
-42488
lines changed

Some content is hidden

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

190 files changed

+103700
-42488
lines changed

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

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\Exception\InputException;
1010
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Eav\Api\Data\AttributeInterface;
1112

1213
/**
1314
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -49,11 +50,6 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
4950
*/
5051
protected $searchCriteriaBuilder;
5152

52-
/**
53-
* @var \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
54-
*/
55-
private $optionManagement;
56-
5753
/**
5854
* @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
5955
* @param \Magento\Catalog\Helper\Product $productHelper
@@ -117,12 +113,17 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
117113
throw NoSuchEntityException::singleField('attribute_code', $existingModel->getAttributeCode());
118114
}
119115

116+
// Attribute code must not be changed after attribute creation
117+
$attribute->setAttributeCode($existingModel->getAttributeCode());
120118
$attribute->setAttributeId($existingModel->getAttributeId());
121119
$attribute->setIsUserDefined($existingModel->getIsUserDefined());
122120
$attribute->setFrontendInput($existingModel->getFrontendInput());
123121

124122
if (is_array($attribute->getFrontendLabels())) {
125-
$frontendLabel[0] = $existingModel->getDefaultFrontendLabel();
123+
$defaultFrontendLabel = $attribute->getDefaultFrontendLabel();
124+
$frontendLabel[0] = !empty($defaultFrontendLabel)
125+
? $defaultFrontendLabel
126+
: $existingModel->getDefaultFrontendLabel();
126127
foreach ($attribute->getFrontendLabels() as $item) {
127128
$frontendLabel[$item->getStoreId()] = $item->getLabel();
128129
}
@@ -171,10 +172,31 @@ public function save(\Magento\Catalog\Api\Data\ProductAttributeInterface $attrib
171172
);
172173
$attribute->setIsUserDefined(1);
173174
}
174-
$this->attributeResource->save($attribute);
175-
foreach ($attribute->getOptions() as $option) {
176-
$this->getOptionManagement()->add($attribute->getAttributeCode(), $option);
175+
if (!empty($attribute->getData(AttributeInterface::OPTIONS))) {
176+
$options = [];
177+
$sortOrder = 0;
178+
$default = [];
179+
$optionIndex = 0;
180+
foreach ($attribute->getOptions() as $option) {
181+
$optionIndex++;
182+
$optionId = $option->getValue() ?: 'option_' . $optionIndex;
183+
$options['value'][$optionId][0] = $option->getLabel();
184+
$options['order'][$optionId] = $option->getSortOrder() ?: $sortOrder++;
185+
if (is_array($option->getStoreLabels())) {
186+
foreach ($option->getStoreLabels() as $label) {
187+
$options['value'][$optionId][$label->getStoreId()] = $label->getLabel();
188+
}
189+
}
190+
if ($option->getIsDefault()) {
191+
$default[] = $optionId;
192+
}
193+
}
194+
$attribute->setDefault($default);
195+
if (count($options)) {
196+
$attribute->setOption($options);
197+
}
177198
}
199+
$this->attributeResource->save($attribute);
178200
return $this->get($attribute->getAttributeCode());
179201
}
180202

@@ -253,16 +275,4 @@ protected function validateFrontendInput($frontendInput)
253275
throw InputException::invalidFieldValue('frontend_input', $frontendInput);
254276
}
255277
}
256-
257-
/**
258-
* @return \Magento\Catalog\Api\ProductAttributeOptionManagementInterface
259-
*/
260-
private function getOptionManagement()
261-
{
262-
if (null === $this->optionManagement) {
263-
$this->optionManagement = \Magento\Framework\App\ObjectManager::getInstance()
264-
->get('Magento\Catalog\Api\ProductAttributeOptionManagementInterface');
265-
}
266-
return $this->optionManagement;
267-
}
268278
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
10+
11+
/**
12+
* Skip validate attributes used for create configurable product
13+
*/
14+
class AttributeValidation
15+
{
16+
/**
17+
* @var Configurable
18+
*/
19+
private $configurableProductType;
20+
21+
/**
22+
* AttributeValidation constructor.
23+
* @param Configurable $configurableProductType
24+
*/
25+
public function __construct(
26+
Configurable $configurableProductType
27+
) {
28+
$this->configurableProductType = $configurableProductType;
29+
}
30+
31+
/**
32+
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
33+
* @param \Closure $proceed
34+
* @param \Magento\Framework\DataObject $entity
35+
* @return bool
36+
*/
37+
public function aroundValidate(
38+
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39+
\Closure $proceed,
40+
\Magento\Framework\DataObject $entity
41+
) {
42+
$attribute = $subject->getAttribute();
43+
if ($entity instanceof ProductInterface
44+
&& $entity->getTypeId() == Configurable::TYPE_CODE
45+
&& in_array(
46+
$attribute->getAttributeId(),
47+
$this->configurableProductType->getUsedProductAttributeIds($entity),
48+
true
49+
)
50+
) {
51+
return true;
52+
}
53+
return $proceed($entity);
54+
}
55+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
3131
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Helper\Product\Configuration\SaveProductPlugin" sortOrder="50" />
3232
</type>
33+
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
34+
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
35+
</type>
3336
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3437
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3538
</type>

app/code/Magento/Customer/Model/Address.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ public function reindex()
350350
{
351351
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
352352
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
353-
$indexer->reindexRow($this->getCustomerId());
353+
if (!$indexer->isScheduled()) {
354+
$indexer->reindexRow($this->getCustomerId());
355+
}
354356
}
355357

356358
/**

app/code/Magento/Customer/Model/Customer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,9 @@ public function reindex()
10761076
{
10771077
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
10781078
$indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1079-
$indexer->reindexRow($this->getId());
1079+
if (!$indexer->isScheduled()) {
1080+
$indexer->reindexRow($this->getId());
1081+
}
10801082
}
10811083

10821084
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,15 @@
318318
<argument name="cache" xsi:type="object">Magento\Customer\Model\Cache\Type\Notification</argument>
319319
</arguments>
320320
</type>
321+
<type name="Magento\Framework\EntityManager\MetadataPool">
322+
<arguments>
323+
<argument name="metadata" xsi:type="array">
324+
<item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="array">
325+
<item name="entityTableName" xsi:type="string">customer_entity</item>
326+
<item name="eavEntityType" xsi:type="string">customer</item>
327+
<item name="identifierField" xsi:type="string">entity_id</item>
328+
</item>
329+
</argument>
330+
</arguments>
331+
</type>
321332
</config>

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
* @param Attribute $attribute
7272
* @return void
7373
*/
74-
public function beforeSave(Attribute $attribute)
74+
public function beforeBeforeSave(Attribute $attribute)
7575
{
7676
if ($this->swatchHelper->isSwatchAttribute($attribute)) {
7777
$this->setProperOptionsArray($attribute);

app/code/Magento/Swatches/Test/Unit/Model/Plugin/EavAttributeTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testBeforeSaveVisualSwatch()
134134
->willReturn(true);
135135
$this->swatchHelper->expects($this->never())->method('isTextSwatch');
136136

137-
$this->eavAttribute->beforeSave($this->attribute);
137+
$this->eavAttribute->beforeBeforeSave($this->attribute);
138138
}
139139

140140
public function testBeforeSaveTextSwatch()
@@ -179,7 +179,7 @@ public function testBeforeSaveTextSwatch()
179179
->with($this->attribute)
180180
->willReturn(true);
181181

182-
$this->eavAttribute->beforeSave($this->attribute);
182+
$this->eavAttribute->beforeBeforeSave($this->attribute);
183183
}
184184

185185
/**
@@ -220,11 +220,11 @@ public function testBeforeSaveWithFailedValidation()
220220
)
221221
);
222222

223-
$this->eavAttribute->beforeSave($this->attribute);
223+
$this->eavAttribute->beforeBeforeSave($this->attribute);
224224
}
225225

226226
/**
227-
* @covers \Magento\Swatches\Model\Plugin\EavAttribute::beforeSave()
227+
* @covers \Magento\Swatches\Model\Plugin\EavAttribute::beforeBeforeSave()
228228
*/
229229
public function testBeforeSaveWithDeletedOption()
230230
{
@@ -262,7 +262,7 @@ public function testBeforeSaveWithDeletedOption()
262262
false
263263
)
264264
);
265-
$this->eavAttribute->beforeSave($this->attribute);
265+
$this->eavAttribute->beforeBeforeSave($this->attribute);
266266
}
267267

268268
public function testBeforeSaveNotSwatch()
@@ -300,7 +300,7 @@ public function testBeforeSaveNotSwatch()
300300
->with($this->attribute)
301301
->willReturn(false);
302302

303-
$this->eavAttribute->beforeSave($this->attribute);
303+
$this->eavAttribute->beforeBeforeSave($this->attribute);
304304
}
305305

306306
public function visualSwatchProvider()

0 commit comments

Comments
 (0)