Skip to content

Commit 45d28a9

Browse files
committed
Merge remote-tracking branch 'origin/MC-15574' into 2.3-qwerty-pr48
2 parents 2fa49b4 + b72ad7b commit 45d28a9

File tree

1 file changed

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

1 file changed

+75
-31
lines changed

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

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public function __construct(
9898
}
9999

100100
/**
101+
* Return currency symbol.
102+
*
101103
* @return string
102104
*/
103105
public function getCurrencySymbol()
@@ -274,6 +276,8 @@ public function getImageUploadUrl()
274276
}
275277

276278
/**
279+
* Return product qty.
280+
*
277281
* @param Product $product
278282
* @return float
279283
*/
@@ -283,6 +287,8 @@ public function getProductStockQty(Product $product)
283287
}
284288

285289
/**
290+
* Return variation wizard.
291+
*
286292
* @param array $initData
287293
* @return string
288294
*/
@@ -298,6 +304,8 @@ public function getVariationWizard($initData)
298304
}
299305

300306
/**
307+
* Return product configuration matrix.
308+
*
301309
* @return array|null
302310
*/
303311
public function getProductMatrix()
@@ -309,17 +317,22 @@ public function getProductMatrix()
309317
}
310318

311319
/**
320+
* Return product attributes.
321+
*
312322
* @return array|null
313323
*/
314324
public function getProductAttributes()
315325
{
316326
if ($this->productAttributes === null) {
317327
$this->prepareVariations();
318328
}
329+
319330
return $this->productAttributes;
320331
}
321332

322333
/**
334+
* Prepare product variations.
335+
*
323336
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
324337
* @return void
325338
* TODO: move to class
@@ -344,36 +357,13 @@ protected function prepareVariations()
344357
$price = $product->getPrice();
345358
$variationOptions = [];
346359
foreach ($usedProductAttributes as $attribute) {
347-
if (!isset($attributes[$attribute->getAttributeId()])) {
348-
$attributes[$attribute->getAttributeId()] = [
349-
'code' => $attribute->getAttributeCode(),
350-
'label' => $attribute->getStoreLabel(),
351-
'id' => $attribute->getAttributeId(),
352-
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
353-
'chosen' => [],
354-
];
355-
foreach ($attribute->getOptions() as $option) {
356-
if (!empty($option->getValue())) {
357-
$attributes[$attribute->getAttributeId()]['options'][] = [
358-
'attribute_code' => $attribute->getAttributeCode(),
359-
'attribute_label' => $attribute->getStoreLabel(0),
360-
'id' => $option->getValue(),
361-
'label' => $option->getLabel(),
362-
'value' => $option->getValue(),
363-
];
364-
}
365-
}
366-
}
367-
$optionId = $variation[$attribute->getId()]['value'];
368-
$variationOption = [
369-
'attribute_code' => $attribute->getAttributeCode(),
370-
'attribute_label' => $attribute->getStoreLabel(0),
371-
'id' => $optionId,
372-
'label' => $variation[$attribute->getId()]['label'],
373-
'value' => $optionId,
374-
];
375-
$variationOptions[] = $variationOption;
376-
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
360+
list($attributes, $variationOptions) = $this->prepareAttributes(
361+
$attributes,
362+
$attribute,
363+
$configurableAttributes,
364+
$variation,
365+
$variationOptions
366+
);
377367
}
378368

379369
$productMatrix[] = [
@@ -387,12 +377,66 @@ protected function prepareVariations()
387377
'price' => $price,
388378
'options' => $variationOptions,
389379
'weight' => $product->getWeight(),
390-
'status' => $product->getStatus()
380+
'status' => $product->getStatus(),
381+
'__disableTmpl' => true,
391382
];
392383
}
393384
}
394385
}
395386
$this->productMatrix = $productMatrix;
396387
$this->productAttributes = array_values($attributes);
397388
}
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+
}
398442
}

0 commit comments

Comments
 (0)