Skip to content

Commit af6366d

Browse files
committed
Fix configurable attribute options not being sorted
See github issue #7441, internal ticket MAGETWO-61484 and PR #12420.
1 parent e738316 commit af6366d

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ private function getAttributeOptionsSelect(AbstractAttribute $superAttribute, $p
122122
]
123123
),
124124
[]
125+
)->joinInner(
126+
['attribute_option' => $this->attributeResource->getTable('eav_attribute_option')],
127+
'attribute_option.option_id = entity_value.value',
128+
[]
129+
)->order(
130+
'attribute_option.sort_order ASC'
125131
)->where(
126132
'super_attribute.product_id = ?',
127133
$productId

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function setUp()
9797
->disableOriginalConstructor()
9898
->getMockForAbstractClass();
9999
$this->select = $this->getMockBuilder(Select::class)
100-
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns'])
100+
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns', 'order'])
101101
->disableOriginalConstructor()
102102
->getMock();
103103
$this->connectionMock->expects($this->any())
@@ -161,10 +161,28 @@ public function testGetAttributeOptions(array $options)
161161

162162
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
163163
$this->select->expects($this->exactly(1))->method('columns')->willReturnSelf();
164-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
164+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
165165
$this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf();
166+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
166167
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
167168

169+
$this->attributeResource->expects($this->exactly(9))
170+
->method('getTable')
171+
->will(
172+
$this->returnValueMap(
173+
[
174+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
175+
['catalog_product_entity', 'catalog_product_entity value'],
176+
['catalog_product_super_link', 'catalog_product_super_link value'],
177+
['eav_attribute', 'eav_attribute value'],
178+
['catalog_product_entity', 'catalog_product_entity value'],
179+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
180+
['eav_attribute_option', 'eav_attribute_option value'],
181+
['eav_attribute_option_value', 'eav_attribute_option_value value']
182+
]
183+
)
184+
);
185+
168186
$this->abstractAttribute->expects($this->any())
169187
->method('getBackendTable')
170188
->willReturn('getBackendTable value');
@@ -193,10 +211,27 @@ public function testGetAttributeOptionsWithBackendModel(array $options)
193211

194212
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
195213
$this->select->expects($this->exactly(0))->method('columns')->willReturnSelf();
196-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
214+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
197215
$this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf();
216+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
198217
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
199218

219+
$this->attributeResource->expects($this->exactly(7))
220+
->method('getTable')
221+
->will(
222+
$this->returnValueMap(
223+
[
224+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
225+
['catalog_product_entity', 'catalog_product_entity value'],
226+
['catalog_product_super_link', 'catalog_product_super_link value'],
227+
['eav_attribute', 'eav_attribute value'],
228+
['catalog_product_entity', 'catalog_product_entity value'],
229+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
230+
['eav_attribute_option', 'eav_attribute_option value']
231+
]
232+
)
233+
);
234+
200235
$source = $this->getMockBuilder(AbstractSource::class)
201236
->disableOriginalConstructor()
202237
->setMethods(['getOptionText'])

0 commit comments

Comments
 (0)