Skip to content

Commit acae330

Browse files
committed
Merge remote-tracking branch 'mpi/MC-20225' into Chaika-PR-2019-09-26
2 parents cdb0e5f + b2a4ec9 commit acae330

File tree

3 files changed

+23
-11
lines changed
  • app/code/Magento
    • Catalog/Ui/DataProvider/Product/Form/Modifier
    • ConfigurableProduct

3 files changed

+23
-11
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4747
* @SuppressWarnings(PHPMD.TooManyFields)
4848
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
49+
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
4950
* @since 101.0.0
5051
*/
5152
class Eav extends AbstractModifier
@@ -1048,6 +1049,10 @@ private function isScopeGlobal($attribute)
10481049
*/
10491050
private function getAttributeModel($attribute)
10501051
{
1052+
// The statement below solves performance issue related to loading same attribute options on different models
1053+
if ($attribute instanceof EavAttribute) {
1054+
return $attribute;
1055+
}
10511056
$attributeId = $attribute->getAttributeId();
10521057

10531058
if (!array_key_exists($attributeId, $this->attributesCache)) {

app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config/Matrix.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ protected function getAttributes()
197197
foreach ($attributes as $key => $attribute) {
198198
if (isset($configurableData[$key])) {
199199
$attributes[$key] = array_replace_recursive($attribute, $configurableData[$key]);
200+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
200201
$attributes[$key]['values'] = array_merge(
201202
isset($attribute['values']) ? $attribute['values'] : [],
202203
isset($configurableData[$key]['values'])
@@ -412,14 +413,15 @@ private function prepareAttributes(
412413
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
413414
'chosen' => [],
414415
];
415-
foreach ($attribute->getOptions() as $option) {
416-
if (!empty($option->getValue())) {
416+
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
417+
foreach ($options as $option) {
418+
if (!empty($option['value'])) {
417419
$attributes[$attribute->getAttributeId()]['options'][] = [
418420
'attribute_code' => $attribute->getAttributeCode(),
419421
'attribute_label' => $attribute->getStoreLabel(0),
420-
'id' => $option->getValue(),
421-
'label' => $option->getLabel(),
422-
'value' => $option->getValue(),
422+
'id' => $option['value'],
423+
'label' => $option['label'],
424+
'value' => $option['value'],
423425
'__disableTmpl' => true,
424426
];
425427
}

app/code/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProducts.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Framework\Escaper;
2222

2323
/**
24+
* Associated products helper
25+
*
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
2628
class AssociatedProducts
@@ -231,6 +233,8 @@ public function getConfigurableAttributesData()
231233
*
232234
* @return void
233235
* @throws \Zend_Currency_Exception
236+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
237+
* phpcs:disable Generic.Metrics.NestingLevel
234238
*/
235239
protected function prepareVariations()
236240
{
@@ -262,14 +266,15 @@ protected function prepareVariations()
262266
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
263267
'chosen' => [],
264268
];
265-
foreach ($attribute->getOptions() as $option) {
266-
if (!empty($option->getValue())) {
267-
$attributes[$attribute->getAttributeId()]['options'][$option->getValue()] = [
269+
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
270+
foreach ($options as $option) {
271+
if (!empty($option['value'])) {
272+
$attributes[$attribute->getAttributeId()]['options'][$option['value']] = [
268273
'attribute_code' => $attribute->getAttributeCode(),
269274
'attribute_label' => $attribute->getStoreLabel(0),
270-
'id' => $option->getValue(),
271-
'label' => $option->getLabel(),
272-
'value' => $option->getValue(),
275+
'id' => $option['value'],
276+
'label' => $option['label'],
277+
'value' => $option['value'],
273278
];
274279
}
275280
}

0 commit comments

Comments
 (0)