Skip to content

Commit fa0c0c9

Browse files
committed
ACP2E-3410: Configurable product edit form load causes timeout and memory exhaustion
1 parent 823ebb5 commit fa0c0c9

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,14 @@ private function getVariantAttributeComposition(): array
255255
/* @var $attribute AbstractAttribute */
256256
foreach ($this->getUsedAttributes() as $attribute) {
257257
$variants[$product->getId()][$attribute->getAttributeCode()] =
258-
[
259-
'value_id' => $product->getData($attribute->getAttributeCode()),
260-
'attribute' => $attribute
261-
];
258+
[
259+
'value_id' => $product->getData($attribute->getAttributeCode()),
260+
'label' => $this->extractAttributeValueLabel(
261+
$attribute,
262+
$product->getData($attribute->getAttributeCode())
263+
),
264+
'attribute' => $attribute
265+
];
262266
}
263267
}
264268

@@ -415,11 +419,11 @@ private function buildChildProductOption(array $attributeDetails): array
415419
/**
416420
* Get label for a specific value of an attribute.
417421
*
418-
* @param $attribute
422+
* @param AbstractAttribute $attribute
419423
* @param int $valueId
420424
* @return string
421425
*/
422-
private function extractAttributeValueLabel($attribute, int $valueId): string
426+
private function extractAttributeValueLabel(AbstractAttribute $attribute, int $valueId): string
423427
{
424428
foreach ($attribute->getOptions() as $attributeOption) {
425429
if ($attributeOption->getValue() == $valueId) {
@@ -455,10 +459,7 @@ protected function prepareVariations()
455459
'attribute_code' => $attribute->getAttributeCode(),
456460
'attribute_label' => $attribute->getStoreLabel(0),
457461
'id' => $attributeComposition['value_id'],
458-
'label' => $this->extractAttributeValueLabel(
459-
$attribute,
460-
$attributeComposition['value_id']
461-
),
462+
'label' => $attributeComposition['label'],
462463
'value' => $attributeComposition['value_id'],
463464
'__disableTmpl' => true,
464465
];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Composite extends AbstractModifier
5252
* @param LocatorInterface $locator
5353
* @param ObjectManagerInterface $objectManager
5454
* @param AssociatedProducts $associatedProducts
55-
* @param AllowedProductTypes $allowedProductTypes,
55+
* @param AllowedProductTypes $allowedProductTypes
5656
* @param array $modifiers
5757
*/
5858
public function __construct(
@@ -83,7 +83,7 @@ public function __construct(
8383
}
8484

8585
/**
86-
* {@inheritdoc}
86+
* @inheritdoc
8787
*/
8888
public function modifyData(array $data)
8989
{
@@ -111,7 +111,7 @@ public function modifyData(array $data)
111111
}
112112

113113
/**
114-
* {@inheritdoc}
114+
* @inheritdoc
115115
*/
116116
public function modifyMeta(array $meta)
117117
{

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ protected function prepareVariations()
231231
{
232232
$productMatrix = $attributes = [];
233233
$variants = $this->getVariantAttributeComposition();
234+
$productIds = [];
234235
foreach ($this->getAssociatedProducts() as $product) {
235236
$childProductOptions = [];
236237
$productIds[] = $product->getId();
@@ -246,12 +247,8 @@ protected function prepareVariations()
246247
'attribute_code' => $attribute->getAttributeCode(),
247248
'attribute_label' => $attribute->getStoreLabel(0),
248249
'id' => $attributeComposition['value_id'],
249-
'label' => $this->extractAttributeValueLabel(
250-
$attribute,
251-
$attributeComposition['value_id']
252-
),
253-
'value' => $attributeComposition['value_id'],
254-
'__disableTmpl' => true,
250+
'label' => $attributeComposition['label'],
251+
'value' => $attributeComposition['value_id']
255252
];
256253
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
257254
}
@@ -408,8 +405,7 @@ private function buildAttributeDetails(AbstractAttribute $attribute): array
408405
'label' => $attribute->getStoreLabel(),
409406
'id' => $attribute->getAttributeId(),
410407
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
411-
'chosen' => [],
412-
'__disableTmpl' => true
408+
'chosen' => []
413409
];
414410

415411
foreach ($attribute->getOptions() as $option) {
@@ -419,8 +415,7 @@ private function buildAttributeDetails(AbstractAttribute $attribute): array
419415
'attribute_label' => $attribute->getStoreLabel(0),
420416
'id' => $option['value'],
421417
'label' => $option['label'],
422-
'value' => $option['value'],
423-
'__disableTmpl' => true,
418+
'value' => $option['value']
424419
];
425420
}
426421
}
@@ -436,29 +431,23 @@ private function buildAttributeDetails(AbstractAttribute $attribute): array
436431
*/
437432
private function buildChildProductOption(array $attributeDetails): array
438433
{
439-
$label = $this->extractAttributeValueLabel(
440-
$attributeDetails['attribute'],
441-
$attributeDetails['value_id']
442-
);
443-
444434
return [
445435
'attribute_code' => $attributeDetails['attribute']->getAttributeCode(),
446436
'attribute_label' => $attributeDetails['attribute']->getStoreLabel(0),
447437
'id' => $attributeDetails['value_id'],
448-
'label' => $label,
449-
'value' => $attributeDetails['value_id'],
450-
'__disableTmpl' => true,
438+
'label' => $attributeDetails['value_id'],
439+
'value' => $attributeDetails['value_id']
451440
];
452441
}
453442

454443
/**
455444
* Get label for a specific value of an attribute.
456445
*
457-
* @param $attribute
446+
* @param AbstractAttribute $attribute
458447
* @param int $valueId
459448
* @return string
460449
*/
461-
private function extractAttributeValueLabel($attribute, int $valueId): string
450+
private function extractAttributeValueLabel(AbstractAttribute $attribute, int $valueId): string
462451
{
463452
foreach ($attribute->getOptions() as $attributeOption) {
464453
if ($attributeOption->getValue() == $valueId) {
@@ -469,7 +458,6 @@ private function extractAttributeValueLabel($attribute, int $valueId): string
469458
return '';
470459
}
471460

472-
473461
/**
474462
* Create child product details
475463
*
@@ -483,10 +471,9 @@ private function buildChildProductDetails(Product $product, array $childProductO
483471
$currency = $this->localeCurrency->getCurrency($this->locator->getBaseCurrencyCode());
484472
return [
485473
'id' => $product->getId(),
486-
'product_link' => '<a href="' . $this->urlBuilder->getUrl(
487-
'catalog/product/edit',
488-
['id' => $product->getId()]
489-
) . '" target="_blank">' . $this->escaper->escapeHtml($product->getName()) . '</a>',
474+
'product_link' => '<a href="' .
475+
$this->urlBuilder->getUrl('catalog/product/edit', ['id' => $product->getId()])
476+
. '" target="_blank">' . $this->escaper->escapeHtml($product->getName()) . '</a>',
490477
'sku' => $product->getSku(),
491478
'name' => $product->getName(),
492479
'qty' => $this->getProductStockQty($product),
@@ -518,6 +505,10 @@ private function getVariantAttributeComposition(): array
518505
$variants[$product->getId()][$attribute->getAttributeCode()] =
519506
[
520507
'value_id' => $product->getData($attribute->getAttributeCode()),
508+
'label' => $this->extractAttributeValueLabel(
509+
$attribute,
510+
$product->getData($attribute->getAttributeCode())
511+
),
521512
'attribute' => $attribute
522513
];
523514
}

0 commit comments

Comments
 (0)