Skip to content

Commit f26ca6b

Browse files
committed
ACP2E-3410: Configurable product edit form load causes timeout and memory exhaustion
1 parent 7d90c6c commit f26ca6b

File tree

4 files changed

+65
-300
lines changed

4 files changed

+65
-300
lines changed

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

Lines changed: 26 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations\Config;
77

@@ -355,46 +355,6 @@ public function getProductAttributes()
355355
return $this->productAttributes;
356356
}
357357

358-
/**
359-
* Get configurable product existing setup
360-
*
361-
* @return array
362-
*/
363-
public function getExistingVariantConfiguration(): array
364-
{
365-
$productMatrix = $attributes = [];
366-
$variants = $this->getVariantAttributeComposition();
367-
foreach ($this->getAssociatedProducts() as $product) {
368-
$childProductOptions = [];
369-
foreach ($variants[$product->getId()] as $attributeComposition) {
370-
$childProductOptions[] = $this->buildChildProductOption($attributeComposition);
371-
372-
/** @var AbstractAttribute $attribute */
373-
$attribute = $attributeComposition['attribute'];
374-
if (!isset($attributes[$attribute->getAttributeId()])) {
375-
$attributes[$attribute->getAttributeId()] = $this->buildAttributeDetails($attribute);
376-
}
377-
$variationOption = [
378-
'attribute_code' => $attribute->getAttributeCode(),
379-
'attribute_label' => $attribute->getStoreLabel(0),
380-
'id' => $attributeComposition['value_id'],
381-
'label' => $this->extractAttributeValueLabel(
382-
$attribute,
383-
$attributeComposition['value_id']
384-
),
385-
'value' => $attributeComposition['value_id'],
386-
'__disableTmpl' => true,
387-
];
388-
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
389-
}
390-
$productMatrix[] = $this->buildChildProductDetails($product, $childProductOptions);
391-
}
392-
return [
393-
'product_matrix' => $productMatrix,
394-
'attributes' => array_values($attributes)
395-
];
396-
}
397-
398358
/**
399359
* Prepare attribute details for child product configuration
400360
*
@@ -479,109 +439,38 @@ private function extractAttributeValueLabel($attribute, int $valueId): string
479439
*/
480440
protected function prepareVariations()
481441
{
482-
$variations = $this->getVariations();
483-
$productMatrix = [];
484-
$attributes = [];
485-
if ($variations) {
486-
$usedProductAttributes = $this->getUsedAttributes();
487-
$productByUsedAttributes = $this->getAssociatedProducts();
488-
$configurableAttributes = $this->getAttributes();
489-
foreach ($variations as $variation) {
490-
$attributeValues = [];
491-
foreach ($usedProductAttributes as $attribute) {
492-
$attributeValues[$attribute->getAttributeCode()] = $variation[$attribute->getId()]['value'];
493-
}
494-
$key = implode('-', $attributeValues);
495-
if (isset($productByUsedAttributes[$key])) {
496-
$product = $productByUsedAttributes[$key];
497-
$price = $product->getPrice();
498-
$variationOptions = [];
499-
foreach ($usedProductAttributes as $attribute) {
500-
list($attributes, $variationOptions) = $this->prepareAttributes(
501-
$attributes,
502-
$attribute,
503-
$configurableAttributes,
504-
$variation,
505-
$variationOptions
506-
);
507-
}
442+
$productMatrix = $attributes = [];
443+
$variants = $this->getVariantAttributeComposition();
444+
foreach ($this->getAssociatedProducts() as $product) {
445+
$childProductOptions = [];
446+
foreach ($variants[$product->getId()] as $attributeComposition) {
447+
$childProductOptions[] = $this->buildChildProductOption($attributeComposition);
508448

509-
$productMatrix[] = [
510-
'productId' => $product->getId(),
511-
'images' => [
512-
'preview' => $this->image->init($product, 'product_thumbnail_image')->getUrl()
513-
],
514-
'sku' => $product->getSku(),
515-
'name' => $product->getName(),
516-
'quantity' => $this->getProductStockQty($product),
517-
'price' => $price,
518-
'options' => $variationOptions,
519-
'weight' => $product->getWeight(),
520-
'status' => $product->getStatus(),
521-
'__disableTmpl' => true,
522-
];
449+
/** @var AbstractAttribute $attribute */
450+
$attribute = $attributeComposition['attribute'];
451+
if (!isset($attributes[$attribute->getAttributeId()])) {
452+
$attributes[$attribute->getAttributeId()] = $this->buildAttributeDetails($attribute);
523453
}
454+
$variationOption = [
455+
'attribute_code' => $attribute->getAttributeCode(),
456+
'attribute_label' => $attribute->getStoreLabel(0),
457+
'id' => $attributeComposition['value_id'],
458+
'label' => $this->extractAttributeValueLabel(
459+
$attribute,
460+
$attributeComposition['value_id']
461+
),
462+
'value' => $attributeComposition['value_id'],
463+
'__disableTmpl' => true,
464+
];
465+
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
524466
}
467+
$productMatrix[] = $this->buildChildProductDetails($product, $childProductOptions);
525468
}
469+
526470
$this->productMatrix = $productMatrix;
527471
$this->productAttributes = array_values($attributes);
528472
}
529473

530-
/**
531-
* Prepare attributes.
532-
*
533-
* @param array $attributes
534-
* @param object $attribute
535-
* @param array $configurableAttributes
536-
* @param array $variation
537-
* @param array $variationOptions
538-
* @return array
539-
*/
540-
private function prepareAttributes(
541-
array $attributes,
542-
$attribute,
543-
array $configurableAttributes,
544-
array $variation,
545-
array $variationOptions
546-
): array {
547-
if (!isset($attributes[$attribute->getAttributeId()])) {
548-
$attributes[$attribute->getAttributeId()] = [
549-
'code' => $attribute->getAttributeCode(),
550-
'label' => $attribute->getStoreLabel(),
551-
'id' => $attribute->getAttributeId(),
552-
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
553-
'chosen' => [],
554-
'__disableTmpl' => true
555-
];
556-
$options = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : [];
557-
foreach ($options as $option) {
558-
if (!empty($option['value'])) {
559-
$attributes[$attribute->getAttributeId()]['options'][] = [
560-
'attribute_code' => $attribute->getAttributeCode(),
561-
'attribute_label' => $attribute->getStoreLabel(0),
562-
'id' => $option['value'],
563-
'label' => $option['label'],
564-
'value' => $option['value'],
565-
'__disableTmpl' => true,
566-
];
567-
}
568-
}
569-
}
570-
$optionId = $variation[$attribute->getId()]['value'];
571-
$variationOption = [
572-
'attribute_code' => $attribute->getAttributeCode(),
573-
'attribute_label' => $attribute->getStoreLabel(0),
574-
'id' => $optionId,
575-
'label' => $variation[$attribute->getId()]['label'],
576-
'value' => $optionId,
577-
'__disableTmpl' => true,
578-
];
579-
$variationOptions[] = $variationOption;
580-
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
581-
582-
return [$attributes, $variationOptions];
583-
}
584-
585474
/**
586475
* Create child product details
587476
*

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier;
77

88
use Magento\Catalog\Model\Locator\LocatorInterface;
99
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
1010
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableType;
11-
use Magento\Catalog\Model\Product\Type;
1211
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
1312
use Magento\Framework\ObjectManagerInterface;
1413
use Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\Data\AssociatedProducts;
@@ -95,18 +94,12 @@ public function modifyData(array $data)
9594
$productId = $model->getId();
9695
$data[$productId]['affect_configurable_product_attributes'] = '1';
9796

98-
$variantConfiguration = $this->associatedProducts->getExistingVariantConfiguration();
9997
if ($productTypeId === ConfigurableType::TYPE_CODE) {
100-
//$data[$productId]['configurable-matrix'] = $this->associatedProducts->getProductMatrix();
101-
$data[$productId]['configurable-matrix'] = $variantConfiguration['product_matrix'];
102-
//$data[$productId]['attributes'] = $this->associatedProducts->getProductAttributesIds();
103-
$data[$productId]['attributes'] = $variantConfiguration['attributes'];
104-
//$data[$productId]['attribute_codes'] = $this->associatedProducts->getProductAttributesCodes();
105-
foreach ($variantConfiguration['attributes'] as $attribute) {
106-
$data[$productId]['attribute_codes'][] = $attribute['code'];
107-
}
98+
$data[$productId]['configurable-matrix'] = $this->associatedProducts->getProductMatrix();
99+
$data[$productId]['attributes'] = $this->associatedProducts->getProductAttributesIds();
100+
$data[$productId]['attribute_codes'] = $this->associatedProducts->getProductAttributesCodes();
108101
$data[$productId]['product']['configurable_attributes_data'] =
109-
$this->associatedProducts->getConfigurableAttributesData($variantConfiguration['attributes']);
102+
$this->associatedProducts->getConfigurableAttributesData();
110103
}
111104
}
112105

0 commit comments

Comments
 (0)