Skip to content

Commit d11b646

Browse files
ENGCOM-5937: Fix error in configurables #24659
- Merge Pull Request #24659 from elfeffe/magento2:patch-1 - Merged commits: 1. bff262d 2. d16dd4c 3. 4437767
2 parents db0dce6 + 4437767 commit d11b646

File tree

2 files changed

+113
-37
lines changed

2 files changed

+113
-37
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/VariationMatrix.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ConfigurableProduct\Model\Product\Type;
78

89
/**
10+
* Variation matrix.
11+
*
912
* @api
1013
* @since 100.0.2
1114
*/
@@ -40,7 +43,9 @@ public function getVariations($usedProductAttributes)
4043
for ($attributeIndex = $attributesCount; $attributeIndex--;) {
4144
$currentAttribute = $variationalAttributes[$attributeIndex];
4245
$currentVariationValue = $currentVariation[$attributeIndex];
43-
$filledVariation[$currentAttribute['id']] = $currentAttribute['values'][$currentVariationValue];
46+
if (!empty($currentAttribute['id'])) {
47+
$filledVariation[$currentAttribute['id']] = $currentAttribute['values'][$currentVariationValue];
48+
}
4449
}
4550

4651
$variations[] = $filledVariation;

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/Type/VariationMatrixTest.php

Lines changed: 107 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,117 @@ protected function setUp()
2525
);
2626
}
2727

28-
public function testGetVariations()
28+
/**
29+
* Variations matrix test.
30+
*
31+
* @param array $expectedResult
32+
* @dataProvider variationProvider
33+
*/
34+
public function testGetVariations($expectedResult)
2935
{
30-
$result = [
31-
[
32-
130 => [
33-
'value' => '3',
34-
'label' => 'red',
35-
'price' => ['value_index' => '3', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1',],
36-
],
37-
],
38-
[
39-
130 => [
40-
'value' => '4',
41-
'label' => 'blue',
42-
'price' => ['value_index' => '4', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1',],
43-
],
44-
],
45-
];
4636

47-
$input = [
48-
130 => [
49-
'values' => [
50-
[
51-
'value_index' => '3',
52-
'pricing_value' => '',
53-
'is_percent' => '0',
54-
'include' => '1'
55-
],
56-
[
57-
'value_index' => '4',
58-
'pricing_value' => '',
59-
'is_percent' => '0',
60-
'include' => '1'
37+
$this->assertEquals($expectedResult['result'], $this->model->getVariations($expectedResult['input']));
38+
}
39+
40+
/**
41+
* Test data provider.
42+
*/
43+
public function variationProvider()
44+
{
45+
return [
46+
[
47+
'with_attribute_id' => [
48+
'result' => [
49+
[
50+
130 => [
51+
'value' => '3',
52+
'label' => 'red',
53+
'price' => [
54+
'value_index' => '3',
55+
'pricing_value' => '',
56+
'is_percent' => '0',
57+
'include' => '1'
58+
],
59+
],
60+
],
61+
[
62+
130 => [
63+
'value' => '4',
64+
'label' => 'blue',
65+
'price' => [
66+
'value_index' => '4',
67+
'pricing_value' => '',
68+
'is_percent' => '0',
69+
'include' => '1'
70+
],
71+
],
72+
],
6173
],
74+
'input' => [
75+
130 => [
76+
'values' => [
77+
[
78+
'value_index' => '3',
79+
'pricing_value' => '',
80+
'is_percent' => '0',
81+
'include' => '1'
82+
],
83+
[
84+
'value_index' => '4',
85+
'pricing_value' => '',
86+
'is_percent' => '0',
87+
'include' => '1'
88+
],
89+
],
90+
'attribute_id' => '130',
91+
'options' => [
92+
[
93+
'value' => '3',
94+
'label' => 'red'
95+
],
96+
['value' => '4',
97+
'label' => 'blue'
98+
]
99+
],
100+
],
101+
]
62102
],
63-
'attribute_id' => '130',
64-
'options' => [['value' => '3', 'label' => 'red',], ['value' => '4', 'label' => 'blue',],],
65-
],
103+
'without_attribute_id' => [
104+
'result' => [
105+
[
106+
130 => [
107+
'value' => '4',
108+
'label' => 'blue',
109+
'price' => [
110+
'value_index' => '4',
111+
'pricing_value' => '',
112+
'is_percent' => '0',
113+
'include' => '1'
114+
],
115+
],
116+
],
117+
],
118+
'input' => [
119+
130 => [
120+
'values' => [
121+
[
122+
'value_index' => '3',
123+
'pricing_value' => '',
124+
'is_percent' => '0',
125+
'include' => '1'
126+
]
127+
],
128+
'attribute_id' => '',
129+
'options' => [
130+
[
131+
'value' => '3',
132+
'label' => 'red'
133+
]
134+
],
135+
],
136+
]
137+
]
138+
]
66139
];
67-
68-
$this->assertEquals($result, $this->model->getVariations($input));
69140
}
70141
}

0 commit comments

Comments
 (0)