отображение ненужных цен за кг
This commit is contained in:
@@ -49,9 +49,51 @@ final class CategoryRepository extends BaseRepository
|
||||
$childrenByParent[$parentKey][] = $item;
|
||||
}
|
||||
|
||||
$childrenByParent[0] = $this->sortRootCategories($childrenByParent[0] ?? []);
|
||||
|
||||
return $this->buildTree($childrenByParent, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $categories
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
private function sortRootCategories(array $categories): array
|
||||
{
|
||||
usort($categories, function (array $left, array $right): int {
|
||||
return [
|
||||
$this->rootCategoryWeight((string) ($left['name'] ?? '')),
|
||||
(int) ($left['sort_order'] ?? 100),
|
||||
(string) ($left['name'] ?? ''),
|
||||
] <=> [
|
||||
$this->rootCategoryWeight((string) ($right['name'] ?? '')),
|
||||
(int) ($right['sort_order'] ?? 100),
|
||||
(string) ($right['name'] ?? ''),
|
||||
];
|
||||
});
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
private function rootCategoryWeight(string $name): int
|
||||
{
|
||||
$lowerName = trim(mb_strtolower($name));
|
||||
|
||||
return match (true) {
|
||||
str_contains($lowerName, 'рыб') => 10,
|
||||
str_contains($lowerName, 'морепроду') => 20,
|
||||
str_contains($lowerName, 'икра') => 30,
|
||||
$lowerName === 'мясо' => 40,
|
||||
str_contains($lowerName, 'сыр') => 50,
|
||||
str_contains($lowerName, 'полуфаб') => 60,
|
||||
str_contains($lowerName, 'фрукт') || str_contains($lowerName, 'овощ') || str_contains($lowerName, 'ягод') || str_contains($lowerName, 'гриб') => 70,
|
||||
str_contains($lowerName, 'бакале') => 80,
|
||||
str_contains($lowerName, 'мясная гастрономия') => 90,
|
||||
str_contains($lowerName, 'молоч') => 100,
|
||||
default => 1000,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array<int, array<string, mixed>>> $childrenByParent
|
||||
* @return array<int, array<string, mixed>>
|
||||
|
||||
Reference in New Issue
Block a user