Skip to content

Commit

Permalink
refacto: feature option provider getOptions method
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-devfront committed Apr 25, 2024
1 parent d04e770 commit e7967b1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions classes/ProductFilter/Options/FeatureOptionsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@ public function getOptions(): array

$options = [];
foreach ($rawData as $rawAttribute) {
// find existing attribute group to modify it...
foreach ($options as $option) {
if ($option['id'] === $rawAttribute['id_feature']) {
$option['values'][] = [
'id' => $rawAttribute['id_feature_value'],
'key' => $rawAttribute['feature_name'],
'value' => $rawAttribute['value'],
'language' => $this->languageRepository->getIsoById($rawAttribute['id_lang']),
];
continue 2;
}
if (isset($options[$rawAttribute['id_feature']])) {
$options[$rawAttribute['id_feature']]['values'][] = [
'id' => $rawAttribute['id_feature_value'],
// Repeat key to ease the creation of payload when value is selected
'key' => $rawAttribute['feature_name'],
'value' => $rawAttribute['value'],
'language' => $this->languageRepository->getIsoById($rawAttribute['id_lang']),
];
continue;
}

// ... or push a new one
$options[] = [
$options[$rawAttribute['id_feature']] = [
'id' => $rawAttribute['id_feature'],
'key' => $rawAttribute['feature_name'],
'values' => [
Expand All @@ -78,6 +75,6 @@ public function getOptions(): array
];
}

return $options;
return array_values($options);
}
}

0 comments on commit e7967b1

Please sign in to comment.