khanegi admin changes

This commit is contained in:
2026-06-13 15:55:28 +03:30
parent 2d2e5f2e4d
commit 9b28a55634
2 changed files with 20 additions and 13 deletions
+19 -7
View File
@@ -8,6 +8,17 @@ use Illuminate\Support\Collection;
class CategoryService
{
/** دسته‌های پیش‌فرض — باید با سلکت افزودن محصول و تب فیلتر اپ یکسان باشند */
public const DEFAULT_CATEGORY_NAMES = [
'آبشده',
'مکعب',
'گوی',
'سکه',
'سکه پارسیان',
'مس',
'نقره',
];
/** دسته‌هایی که صریحاً غیرفعال شده‌اند — بقیه (بدون ردیف) نمایش داده می‌شوند */
public function hiddenCategoryNames(): Collection
{
@@ -54,22 +65,23 @@ class CategoryService
public function syncFromProducts(): int
{
$names = Product::query()
$fromProducts = Product::query()
->whereNotNull('group_type')
->where('group_type', '!=', '')
->distinct()
->orderBy('group_type')
->pluck('group_type');
$names = collect(self::DEFAULT_CATEGORY_NAMES)
->merge($fromProducts)
->map(static fn ($name) => trim((string) $name))
->filter()
->unique()
->values();
$created = 0;
$order = (int) Category::max('sort_order');
foreach ($names as $name) {
$name = trim((string) $name);
if ($name === '') {
continue;
}
if (Category::where('name', $name)->exists()) {
continue;
}