Skip to content

Commit 3e05b67

Browse files
committed
MC-15574: Fix associated product grid
1 parent f5d3217 commit 3e05b67

File tree

1 file changed

+60
-32
lines changed
  • app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Edit/Tab/Variations/Config

1 file changed

+60
-32
lines changed

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

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -357,38 +357,13 @@ protected function prepareVariations()
357357
$price = $product->getPrice();
358358
$variationOptions = [];
359359
foreach ($usedProductAttributes as $attribute) {
360-
if (!isset($attributes[$attribute->getAttributeId()])) {
361-
$attributes[$attribute->getAttributeId()] = [
362-
'code' => $attribute->getAttributeCode(),
363-
'label' => $attribute->getStoreLabel(),
364-
'id' => $attribute->getAttributeId(),
365-
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
366-
'chosen' => [],
367-
];
368-
foreach ($attribute->getOptions() as $option) {
369-
if (!empty($option->getValue())) {
370-
$attributes[$attribute->getAttributeId()]['options'][] = [
371-
'attribute_code' => $attribute->getAttributeCode(),
372-
'attribute_label' => $attribute->getStoreLabel(0),
373-
'id' => $option->getValue(),
374-
'label' => $option->getLabel(),
375-
'value' => $option->getValue(),
376-
'__disableTmpl' => true,
377-
];
378-
}
379-
}
380-
}
381-
$optionId = $variation[$attribute->getId()]['value'];
382-
$variationOption = [
383-
'attribute_code' => $attribute->getAttributeCode(),
384-
'attribute_label' => $attribute->getStoreLabel(0),
385-
'id' => $optionId,
386-
'label' => $variation[$attribute->getId()]['label'],
387-
'value' => $optionId,
388-
'__disableTmpl' => true,
389-
];
390-
$variationOptions[] = $variationOption;
391-
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
360+
list($attributes, $variationOptions) = $this->prepareAttributes(
361+
$attributes,
362+
$attribute,
363+
$configurableAttributes,
364+
$variation,
365+
$variationOptions
366+
);
392367
}
393368

394369
$productMatrix[] = [
@@ -411,4 +386,57 @@ protected function prepareVariations()
411386
$this->productMatrix = $productMatrix;
412387
$this->productAttributes = array_values($attributes);
413388
}
389+
390+
/**
391+
* Prepare attributes.
392+
*
393+
* @param array $attributes
394+
* @param object $attribute
395+
* @param array $configurableAttributes
396+
* @param array $variation
397+
* @param array $variationOptions
398+
* @return array
399+
*/
400+
private function prepareAttributes(
401+
array $attributes,
402+
$attribute,
403+
array $configurableAttributes,
404+
array $variation,
405+
array $variationOptions
406+
): array {
407+
if (!isset($attributes[$attribute->getAttributeId()])) {
408+
$attributes[$attribute->getAttributeId()] = [
409+
'code' => $attribute->getAttributeCode(),
410+
'label' => $attribute->getStoreLabel(),
411+
'id' => $attribute->getAttributeId(),
412+
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
413+
'chosen' => [],
414+
];
415+
foreach ($attribute->getOptions() as $option) {
416+
if (!empty($option->getValue())) {
417+
$attributes[$attribute->getAttributeId()]['options'][] = [
418+
'attribute_code' => $attribute->getAttributeCode(),
419+
'attribute_label' => $attribute->getStoreLabel(0),
420+
'id' => $option->getValue(),
421+
'label' => $option->getLabel(),
422+
'value' => $option->getValue(),
423+
'__disableTmpl' => true,
424+
];
425+
}
426+
}
427+
}
428+
$optionId = $variation[$attribute->getId()]['value'];
429+
$variationOption = [
430+
'attribute_code' => $attribute->getAttributeCode(),
431+
'attribute_label' => $attribute->getStoreLabel(0),
432+
'id' => $optionId,
433+
'label' => $variation[$attribute->getId()]['label'],
434+
'value' => $optionId,
435+
'__disableTmpl' => true,
436+
];
437+
$variationOptions[] = $variationOption;
438+
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
439+
440+
return [$attributes, $variationOptions];
441+
}
414442
}

0 commit comments

Comments
 (0)