Skip to content

Commit 655e460

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98912' into 2.1.18-develop-pr71
2 parents 5cba861 + 7d8dee1 commit 655e460

File tree

1 file changed

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

1 file changed

+76
-31
lines changed

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

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function __construct(
9191
}
9292

9393
/**
94+
* Return currency symbol.
95+
*
9496
* @return string
9597
*/
9698
public function getCurrencySymbol()
@@ -173,6 +175,7 @@ public function getEditProductUrl($id)
173175
* Retrieve attributes data
174176
*
175177
* @return array
178+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
176179
*/
177180
protected function getAttributes()
178181
{
@@ -263,6 +266,8 @@ public function getImageUploadUrl()
263266
}
264267

265268
/**
269+
* Return product qty.
270+
*
266271
* @param Product $product
267272
* @return float
268273
*/
@@ -272,6 +277,8 @@ public function getProductStockQty(Product $product)
272277
}
273278

274279
/**
280+
* Return variation wizard.
281+
*
275282
* @param array $initData
276283
* @return string
277284
*/
@@ -287,6 +294,8 @@ public function getVariationWizard($initData)
287294
}
288295

289296
/**
297+
* Return product configuration matrix.
298+
*
290299
* @return array|null
291300
*/
292301
public function getProductMatrix()
@@ -298,17 +307,22 @@ public function getProductMatrix()
298307
}
299308

300309
/**
310+
* Return product attributes.
311+
*
301312
* @return array|null
302313
*/
303314
public function getProductAttributes()
304315
{
305316
if ($this->productAttributes === null) {
306317
$this->prepareVariations();
307318
}
319+
308320
return $this->productAttributes;
309321
}
310322

311323
/**
324+
* Prepare product variations.
325+
*
312326
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
313327
* @return void
314328
* TODO: move to class
@@ -333,36 +347,13 @@ protected function prepareVariations()
333347
$price = $product->getPrice();
334348
$variationOptions = [];
335349
foreach ($usedProductAttributes as $attribute) {
336-
if (!isset($attributes[$attribute->getAttributeId()])) {
337-
$attributes[$attribute->getAttributeId()] = [
338-
'code' => $attribute->getAttributeCode(),
339-
'label' => $attribute->getStoreLabel(),
340-
'id' => $attribute->getAttributeId(),
341-
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
342-
'chosen' => [],
343-
];
344-
foreach ($attribute->getOptions() as $option) {
345-
if (!empty($option->getValue())) {
346-
$attributes[$attribute->getAttributeId()]['options'][] = [
347-
'attribute_code' => $attribute->getAttributeCode(),
348-
'attribute_label' => $attribute->getStoreLabel(0),
349-
'id' => $option->getValue(),
350-
'label' => $option->getLabel(),
351-
'value' => $option->getValue(),
352-
];
353-
}
354-
}
355-
}
356-
$optionId = $variation[$attribute->getId()]['value'];
357-
$variationOption = [
358-
'attribute_code' => $attribute->getAttributeCode(),
359-
'attribute_label' => $attribute->getStoreLabel(0),
360-
'id' => $optionId,
361-
'label' => $variation[$attribute->getId()]['label'],
362-
'value' => $optionId,
363-
];
364-
$variationOptions[] = $variationOption;
365-
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
350+
list($attributes, $variationOptions) = $this->prepareAttributes(
351+
$attributes,
352+
$attribute,
353+
$configurableAttributes,
354+
$variation,
355+
$variationOptions
356+
);
366357
}
367358

368359
$productMatrix[] = [
@@ -376,12 +367,66 @@ protected function prepareVariations()
376367
'price' => $price,
377368
'options' => $variationOptions,
378369
'weight' => $product->getWeight(),
379-
'status' => $product->getStatus()
370+
'status' => $product->getStatus(),
371+
'__disableTmpl' => true,
380372
];
381373
}
382374
}
383375
}
384376
$this->productMatrix = $productMatrix;
385377
$this->productAttributes = array_values($attributes);
386378
}
379+
380+
/**
381+
* Prepare attributes.
382+
*
383+
* @param array $attributes
384+
* @param object $attribute
385+
* @param array $configurableAttributes
386+
* @param array $variation
387+
* @param array $variationOptions
388+
* @return array
389+
*/
390+
private function prepareAttributes(
391+
array $attributes,
392+
$attribute,
393+
array $configurableAttributes,
394+
array $variation,
395+
array $variationOptions
396+
) {
397+
if (!isset($attributes[$attribute->getAttributeId()])) {
398+
$attributes[$attribute->getAttributeId()] = [
399+
'code' => $attribute->getAttributeCode(),
400+
'label' => $attribute->getStoreLabel(),
401+
'id' => $attribute->getAttributeId(),
402+
'position' => $configurableAttributes[$attribute->getAttributeId()]['position'],
403+
'chosen' => [],
404+
];
405+
foreach ($attribute->getOptions() as $option) {
406+
if (!empty($option->getValue())) {
407+
$attributes[$attribute->getAttributeId()]['options'][] = [
408+
'attribute_code' => $attribute->getAttributeCode(),
409+
'attribute_label' => $attribute->getStoreLabel(0),
410+
'id' => $option->getValue(),
411+
'label' => $option->getLabel(),
412+
'value' => $option->getValue(),
413+
'__disableTmpl' => true,
414+
];
415+
}
416+
}
417+
}
418+
$optionId = $variation[$attribute->getId()]['value'];
419+
$variationOption = [
420+
'attribute_code' => $attribute->getAttributeCode(),
421+
'attribute_label' => $attribute->getStoreLabel(0),
422+
'id' => $optionId,
423+
'label' => $variation[$attribute->getId()]['label'],
424+
'value' => $optionId,
425+
'__disableTmpl' => true,
426+
];
427+
$variationOptions[] = $variationOption;
428+
$attributes[$attribute->getAttributeId()]['chosen'][] = $variationOption;
429+
430+
return [$attributes, $variationOptions];
431+
}
387432
}

0 commit comments

Comments
 (0)