Skip to content

Commit 18b6194

Browse files
committed
MC-37954: PLP sort by name is case-sensitive with ElasticSearch
1 parent a1e5689 commit 18b6194

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ class ProductDataMapper implements BatchDataMapperInterface
9090
*/
9191
private $filterableAttributeTypes;
9292

93+
/**
94+
* @var string[]
95+
*/
96+
private $sortableCaseSensitiveAttributes = [
97+
'name',
98+
];
99+
93100
/**
94101
* @param Builder $builder
95102
* @param FieldMapperInterface $fieldMapper
@@ -99,6 +106,7 @@ class ProductDataMapper implements BatchDataMapperInterface
99106
* @param array $excludedAttributes
100107
* @param array $sortableAttributesValuesToImplode
101108
* @param array $filterableAttributeTypes
109+
* @param array $sortableCaseSensitiveAttributes
102110
*/
103111
public function __construct(
104112
Builder $builder,
@@ -108,7 +116,8 @@ public function __construct(
108116
DataProvider $dataProvider,
109117
array $excludedAttributes = [],
110118
array $sortableAttributesValuesToImplode = [],
111-
array $filterableAttributeTypes = []
119+
array $filterableAttributeTypes = [],
120+
array $sortableCaseSensitiveAttributes = []
112121
) {
113122
$this->builder = $builder;
114123
$this->fieldMapper = $fieldMapper;
@@ -122,6 +131,10 @@ public function __construct(
122131
$this->dataProvider = $dataProvider;
123132
$this->attributeOptionsCache = [];
124133
$this->filterableAttributeTypes = $filterableAttributeTypes;
134+
$this->sortableCaseSensitiveAttributes = array_merge(
135+
$this->sortableCaseSensitiveAttributes,
136+
$sortableCaseSensitiveAttributes
137+
);
125138
}
126139

127140
/**
@@ -298,6 +311,12 @@ function (string $valueId) {
298311
$attributeValues = [$productId => implode(' ', $attributeValues)];
299312
}
300313

314+
if (in_array($attribute->getAttributeCode(), $this->sortableCaseSensitiveAttributes)) {
315+
foreach ($attributeValues as $key => $attributeValue) {
316+
$attributeValues[$key] = strtolower($attributeValue);
317+
}
318+
}
319+
301320
return $attributeValues;
302321
}
303322

0 commit comments

Comments
 (0)