Skip to content

Commit de39d22

Browse files
committed
ACP2E-1916: Unable to sort catalog by Custom Attribute of type Dropdown
- with test
1 parent 3bffb9f commit de39d22

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ private function convertAttribute(Attribute $attribute, array $attributeValues,
250250
* - "Visible in Advanced Search" (is_visible_in_advanced_search)
251251
* - "Use in Layered Navigation" (is_filterable)
252252
* - "Use in Search Results Layered Navigation" (is_filterable_in_search)
253+
* - "Use in Sorting in Product Listing" (used_for_sort_by)
253254
*
254255
* @param Attribute $attribute
255256
* @return bool
@@ -261,6 +262,7 @@ private function isAttributeLabelsShouldBeMapped(Attribute $attribute): bool
261262
|| $attribute->getIsVisibleInAdvancedSearch()
262263
|| $attribute->getIsFilterable()
263264
|| $attribute->getIsFilterableInSearch()
265+
|| $attribute->getUsedForSortBy()
264266
);
265267
}
266268

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/BatchDataMapper/ProductDataMapperTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,57 @@ public static function mapProvider(): array
373373
[10 => '44', 11 => '45'],
374374
['color' => [44, 45], 'color_value' => ['red', 'black']],
375375
],
376+
'select with options with sort by and filterable' => [
377+
10,
378+
[
379+
'attribute_code' => 'color',
380+
'backend_type' => 'text',
381+
'frontend_input' => 'select',
382+
'is_searchable' => true,
383+
'used_for_sort_by' => true,
384+
'is_filterable_in_grid' => true,
385+
'options' => [
386+
['value' => '44', 'label' => 'red'],
387+
['value' => '45', 'label' => 'black'],
388+
],
389+
],
390+
[10 => '44', 11 => '45'],
391+
['color' => [44, 45], 'color_value' => ['red', 'black']],
392+
],
393+
'unsearchable select with options with sort by and filterable' => [
394+
10,
395+
[
396+
'attribute_code' => 'color',
397+
'backend_type' => 'text',
398+
'frontend_input' => 'select',
399+
'is_searchable' => false,
400+
'used_for_sort_by' => false,
401+
'is_filterable_in_grid' => false,
402+
'options' => [
403+
['value' => '44', 'label' => 'red'],
404+
['value' => '45', 'label' => 'black'],
405+
],
406+
],
407+
'44',
408+
['color' => 44],
409+
],
410+
'select with options with sort by only' => [
411+
10,
412+
[
413+
'attribute_code' => 'color',
414+
'backend_type' => 'text',
415+
'frontend_input' => 'select',
416+
'is_searchable' => false,
417+
'used_for_sort_by' => true,
418+
'is_filterable_in_grid' => false,
419+
'options' => [
420+
['value' => '44', 'label' => 'red'],
421+
['value' => '45', 'label' => 'black'],
422+
],
423+
],
424+
[10 => '44', 11 => '45'],
425+
['color' => [44, 45], 'color_value' => ['red', 'black']],
426+
],
376427
'multiselect without options' => [
377428
10,
378429
[

0 commit comments

Comments
 (0)