Skip to content

Commit 9794d38

Browse files
committed
Sort configurable attribute options by sort_order
When fetching configurable options using the configurable product option select builder, the sort_order of each option should be taken into account as well, making sure the desired sorting is passed to the frontend. See github issue #7441, internal ticket MAGETWO-61484 and PR#12420 for more on this.
1 parent a39e37f commit 9794d38

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco
9191
]
9292
),
9393
[]
94+
)->joinInner(
95+
['attribute_option' => $this->attributeResource->getTable('eav_attribute_option')],
96+
'attribute_option.option_id = entity_value.value',
97+
[]
98+
)->order(
99+
'attribute_option.sort_order ASC'
94100
)->where(
95101
'super_attribute.product_id = ?',
96102
$productId

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function setUp()
6666
->disableOriginalConstructor()
6767
->getMockForAbstractClass();
6868
$this->select = $this->getMockBuilder(Select::class)
69-
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns'])
69+
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns', 'order'])
7070
->disableOriginalConstructor()
7171
->getMock();
7272
$this->connectionMock->expects($this->atLeastOnce())
@@ -112,10 +112,28 @@ public function testGetSelect()
112112
{
113113
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
114114
$this->select->expects($this->exactly(1))->method('columns')->willReturnSelf();
115-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
115+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
116116
$this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf();
117+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
117118
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
118119

120+
$this->attributeResourceMock->expects($this->exactly(9))
121+
->method('getTable')
122+
->will(
123+
$this->returnValueMap(
124+
[
125+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
126+
['catalog_product_entity', 'catalog_product_entity value'],
127+
['catalog_product_super_link', 'catalog_product_super_link value'],
128+
['eav_attribute', 'eav_attribute value'],
129+
['catalog_product_entity', 'catalog_product_entity value'],
130+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
131+
['eav_attribute_option', 'eav_attribute_option value'],
132+
['eav_attribute_option_value', 'eav_attribute_option_value value']
133+
]
134+
)
135+
);
136+
119137
$this->abstractAttributeMock->expects($this->atLeastOnce())
120138
->method('getAttributeId')
121139
->willReturn('getAttributeId value');
@@ -138,10 +156,27 @@ public function testGetSelectWithBackendModel()
138156
{
139157
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
140158
$this->select->expects($this->exactly(0))->method('columns')->willReturnSelf();
141-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
159+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
142160
$this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf();
161+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
143162
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
144163

164+
$this->attributeResourceMock->expects($this->exactly(7))
165+
->method('getTable')
166+
->will(
167+
$this->returnValueMap(
168+
[
169+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
170+
['catalog_product_entity', 'catalog_product_entity value'],
171+
['catalog_product_super_link', 'catalog_product_super_link value'],
172+
['eav_attribute', 'eav_attribute value'],
173+
['catalog_product_entity', 'catalog_product_entity value'],
174+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
175+
['eav_attribute_option', 'eav_attribute_option value']
176+
]
177+
)
178+
);
179+
145180
$this->abstractAttributeMock->expects($this->atLeastOnce())
146181
->method('getAttributeId')
147182
->willReturn('getAttributeId value');

0 commit comments

Comments
 (0)