Skip to content

Commit 45aee4e

Browse files
AC-700 Update elasticsearch sort for complex attribute
1 parent 11899c6 commit 45aee4e

File tree

2 files changed

+43
-2
lines changed
  • app/code/Magento/Elasticsearch

2 files changed

+43
-2
lines changed

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Sort.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ public function getSort(RequestInterface $request)
9494
if (isset($this->map[$fieldName])) {
9595
$fieldName = $this->map[$fieldName];
9696
}
97-
if ($attribute->isSortable() && !($attribute->isFloatType() || $attribute->isIntegerType())) {
97+
if ($attribute->isSortable() && !$attribute->isComplexType() && !($attribute->isFloatType() || $attribute->isIntegerType())) {
98+
$suffix = $this->fieldNameResolver->getFieldName(
99+
$attribute,
100+
['type' => FieldMapperInterface::TYPE_SORT]
101+
);
102+
$fieldName .= '.' . $suffix;
103+
}
104+
if ($attribute->isComplexType() && $attribute->isSortable()) {
105+
$fieldName .= '_value';
98106
$suffix = $this->fieldNameResolver->getFieldName(
99107
$attribute,
100108
['type' => FieldMapperInterface::TYPE_SORT]

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/SortTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testGetSort(
7272
$isSortable,
7373
$isFloatType,
7474
$isIntegerType,
75+
$isComplexType,
7576
$fieldName,
7677
array $expected
7778
) {
@@ -85,7 +86,7 @@ public function testGetSort(
8586
->willReturn($sortItems);
8687
$attributeMock = $this->getMockBuilder(AttributeAdapter::class)
8788
->disableOriginalConstructor()
88-
->setMethods(['isSortable', 'isFloatType', 'isIntegerType'])
89+
->setMethods(['isSortable', 'isFloatType', 'isIntegerType', 'isComplexType'])
8990
->getMock();
9091
$attributeMock->expects($this->any())
9192
->method('isSortable')
@@ -96,6 +97,9 @@ public function testGetSort(
9697
$attributeMock->expects($this->any())
9798
->method('isIntegerType')
9899
->willReturn($isIntegerType);
100+
$attributeMock->expects($this->any())
101+
->method('isComplexType')
102+
->willReturn($isComplexType);
99103
$this->attributeAdapterProvider->expects($this->any())
100104
->method('getByAttributeCode')
101105
->with($this->anything())
@@ -136,6 +140,7 @@ public function getSortProvider()
136140
false,
137141
false,
138142
false,
143+
false,
139144
null,
140145
[]
141146
],
@@ -153,6 +158,7 @@ public function getSortProvider()
153158
false,
154159
false,
155160
false,
161+
false,
156162
'price',
157163
[
158164
[
@@ -176,6 +182,7 @@ public function getSortProvider()
176182
true,
177183
true,
178184
true,
185+
false,
179186
'price',
180187
[
181188
[
@@ -199,6 +206,7 @@ public function getSortProvider()
199206
true,
200207
false,
201208
false,
209+
false,
202210
'name',
203211
[
204212
[
@@ -222,6 +230,7 @@ public function getSortProvider()
222230
false,
223231
false,
224232
false,
233+
false,
225234
'not_eav_attribute',
226235
[
227236
[
@@ -230,6 +239,30 @@ public function getSortProvider()
230239
]
231240
]
232241
]
242+
],
243+
[
244+
[
245+
[
246+
'field' => 'entity_id',
247+
'direction' => 'DESC'
248+
],
249+
[
250+
'field' => 'color',
251+
'direction' => 'DESC'
252+
],
253+
],
254+
true,
255+
false,
256+
false,
257+
true,
258+
'color',
259+
[
260+
[
261+
'color_value.sort_color' => [
262+
'order' => 'desc'
263+
]
264+
]
265+
]
233266
]
234267
];
235268
}

0 commit comments

Comments
 (0)