Skip to content

Commit 51828c8

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-61058: [Github] Wrong drop-down option labels for configurable products when using attributes with custom source
1 parent 6d8e6c7 commit 51828c8

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

app/code/Magento/ConfigurableProduct/Model/AttributeOptionProvider.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,20 @@ public function getAttributeOptions(AbstractAttribute $superAttribute, $productI
5252
{
5353
$scope = $this->scopeResolver->getScope();
5454
$select = $this->getAttributeOptionsSelect($superAttribute, $productId, $scope);
55-
5655
$data = $this->attributeResource->getConnection()->fetchAll($select);
56+
5757
if ($superAttribute->getSourceModel()) {
58+
$options = $superAttribute->getSource()->getAllOptions(false);
59+
60+
$optionLabels = [];
61+
foreach ($options as $option) {
62+
$optionLabels[$option['value']] = $option['label'];
63+
}
64+
5865
foreach ($data as $key => $value) {
59-
$optionText = $superAttribute->getSource()->getOptionText($value['value_index']);
66+
$optionText = isset($optionLabels[$value['value_index']])
67+
? $optionLabels[$value['value_index']]
68+
: false;
6069
$data[$key]['default_title'] = $optionText;
6170
$data[$key]['option_title'] = $optionText;
6271
}

app/code/Magento/ConfigurableProduct/Test/Unit/Model/AttributeOptionProviderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ public function testGetAttributeOptionsWithBackendModel(array $options)
199199

200200
$source = $this->getMockBuilder(AbstractSource::class)
201201
->disableOriginalConstructor()
202-
->setMethods(['getOptionText'])
202+
->setMethods(['getAllOptions'])
203203
->getMockForAbstractClass();
204204
$source->expects($this->any())
205-
->method('getOptionText')
206-
->willReturnCallback(
207-
function ($optionIndex) {
208-
return 'Option Value for index ' . $optionIndex;
209-
}
210-
);
205+
->method('getAllOptions')
206+
->willReturn([
207+
['value' => 13, 'label' => 'Option Value for index 13'],
208+
['value' => 14, 'label' => 'Option Value for index 14'],
209+
['value' => 15, 'label' => 'Option Value for index 15']
210+
]);
211211

212212
$this->abstractAttribute->expects($this->atLeastOnce())
213213
->method('getSource')

0 commit comments

Comments
 (0)