Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in configurables #24659

Merged
merged 3 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Model\Product\Type;

/**
* Variation matrix.
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -40,7 +43,9 @@ public function getVariations($usedProductAttributes)
for ($attributeIndex = $attributesCount; $attributeIndex--;) {
$currentAttribute = $variationalAttributes[$attributeIndex];
$currentVariationValue = $currentVariation[$attributeIndex];
$filledVariation[$currentAttribute['id']] = $currentAttribute['values'][$currentVariationValue];
if (!empty($currentAttribute['id'])) {
$filledVariation[$currentAttribute['id']] = $currentAttribute['values'][$currentVariationValue];
}
}

$variations[] = $filledVariation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,117 @@ protected function setUp()
);
}

public function testGetVariations()
/**
* Variations matrix test.
*
* @param array $expectedResult
* @dataProvider variationProvider
*/
public function testGetVariations($expectedResult)
{
$result = [
[
130 => [
'value' => '3',
'label' => 'red',
'price' => ['value_index' => '3', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1',],
],
],
[
130 => [
'value' => '4',
'label' => 'blue',
'price' => ['value_index' => '4', 'pricing_value' => '', 'is_percent' => '0', 'include' => '1',],
],
],
];

$input = [
130 => [
'values' => [
[
'value_index' => '3',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
[
'value_index' => '4',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
$this->assertEquals($expectedResult['result'], $this->model->getVariations($expectedResult['input']));
}

/**
* Test data provider.
*/
public function variationProvider()
{
return [
[
'with_attribute_id' => [
'result' => [
[
130 => [
'value' => '3',
'label' => 'red',
'price' => [
'value_index' => '3',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
],
],
[
130 => [
'value' => '4',
'label' => 'blue',
'price' => [
'value_index' => '4',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
],
],
],
'input' => [
130 => [
'values' => [
[
'value_index' => '3',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
[
'value_index' => '4',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
],
'attribute_id' => '130',
'options' => [
[
'value' => '3',
'label' => 'red'
],
['value' => '4',
'label' => 'blue'
]
],
],
]
],
'attribute_id' => '130',
'options' => [['value' => '3', 'label' => 'red',], ['value' => '4', 'label' => 'blue',],],
],
'without_attribute_id' => [
'result' => [
[
130 => [
'value' => '4',
'label' => 'blue',
'price' => [
'value_index' => '4',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
],
],
],
],
'input' => [
130 => [
'values' => [
[
'value_index' => '3',
'pricing_value' => '',
'is_percent' => '0',
'include' => '1'
]
],
'attribute_id' => '',
'options' => [
[
'value' => '3',
'label' => 'red'
]
],
],
]
]
]
];

$this->assertEquals($result, $this->model->getVariations($input));
}
}