Skip to content

Commit e534394

Browse files
author
Serhii Balko
committed
MC-41885: [Magento Cloud] GraphQL | Attribute sorting issue
1 parent acac3a5 commit e534394

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ private function formatResult(Select $select): array
134134
'options' => [],
135135
];
136136
}
137-
$result[$option['attribute_code']]['options'][$option['option_id']] = $option['option_label'];
137+
if (!empty($option['option_id'])) {
138+
$result[$option['attribute_code']]['options'][$option['option_id']] = $option['option_label'];
139+
}
138140
}
139141

140142
return $result;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
8686
$attribute['attribute_code'] ?? $bucketName
8787
);
8888

89-
$options = $this->getSortedOptions($bucket,$attribute['options'] ?? []);
89+
$options = $this->getSortedOptions($bucket,$attribute['options'] ?: []);
9090
foreach ($options as $option) {
9191
$result[$bucketName]['options'][] = $this->layerFormatter->buildItem(
9292
$option['label'],
@@ -182,6 +182,15 @@ private function getSortedOptions(BucketInterface $bucket, array $optionLabels):
182182
$options[$optionValue] = $metrics + ['label' => $optionLabel];
183183
}
184184

185+
/**
186+
* Delete options without bucket values
187+
*/
188+
foreach ($options as $optionId => $option) {
189+
if (!is_array($options[$optionId])) {
190+
unset($options[$optionId]);
191+
}
192+
}
193+
185194
return array_values($options);
186195
}
187196
}

0 commit comments

Comments
 (0)