Skip to content

Commit 5294b5d

Browse files
committed
#28568:GraphQL query returns admin option value label within aggregations
- Added filter by store_id.
1 parent b3d318d commit 5294b5d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ public function __construct(ResourceConnection $resourceConnection)
4242
*
4343
* @param array $optionIds
4444
* @param array $attributeCodes
45+
* @param int|null $storeId
4546
* @return array
4647
* @throws \Zend_Db_Statement_Exception
4748
*/
48-
public function getOptions(array $optionIds, array $attributeCodes = []): array
49+
public function getOptions(array $optionIds, ?int $storeId, array $attributeCodes = []): array
4950
{
5051
if (!$optionIds) {
5152
return [];
5253
}
5354

55+
$storeId = $storeId ?: 0;
5456
$connection = $this->resourceConnection->getConnection();
5557
$select = $connection->select()
5658
->from(
@@ -70,10 +72,19 @@ public function getOptions(array $optionIds, array $attributeCodes = []): array
7072
['option_value' => $this->resourceConnection->getTableName('eav_attribute_option_value')],
7173
'options.option_id = option_value.option_id',
7274
[
73-
'option_label' => 'option_value.value',
7475
'option_id' => 'option_value.option_id',
7576
]
76-
);
77+
)->joinLeft(
78+
['option_value_store' => $this->resourceConnection->getTableName('eav_attribute_option_value')],
79+
"options.option_id = option_value_store.option_id AND option_value_store.store_id = {$storeId}",
80+
[
81+
'option_label' => $connection->getCheckSql(
82+
'option_value_store.value_id > 0',
83+
'option_value_store.value',
84+
'option_value.value'
85+
)
86+
]
87+
)->where('a.attribute_id = options.attribute_id AND option_value.store_id = ?', 0);
7788

7889
$select->where('option_value.option_id IN (?)', $optionIds);
7990

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Attribute.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
*/
7272
public function build(AggregationInterface $aggregation, ?int $storeId): array
7373
{
74-
$attributeOptions = $this->getAttributeOptions($aggregation);
74+
$attributeOptions = $this->getAttributeOptions($aggregation, $storeId);
7575

7676
// build layer per attribute
7777
$result = [];
@@ -133,10 +133,11 @@ private function isBucketEmpty(?BucketInterface $bucket): bool
133133
* Get list of attributes with options
134134
*
135135
* @param AggregationInterface $aggregation
136+
* @param int|null $storeId
136137
* @return array
137138
* @throws \Zend_Db_Statement_Exception
138139
*/
139-
private function getAttributeOptions(AggregationInterface $aggregation): array
140+
private function getAttributeOptions(AggregationInterface $aggregation, ?int $storeId): array
140141
{
141142
$attributeOptionIds = [];
142143
$attributes = [];
@@ -154,6 +155,6 @@ function (AggregationValueInterface $value) {
154155
return [];
155156
}
156157

157-
return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $attributes);
158+
return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $storeId, $attributes);
158159
}
159160
}

0 commit comments

Comments
 (0)