From 9b28a556349d4cd23f5378e619085c80b1e3011f Mon Sep 17 00:00:00 2001 From: adonis Date: Sat, 13 Jun 2026 15:55:28 +0330 Subject: [PATCH] khanegi admin changes --- .../Admin/PriceSyncLogController.php | 7 +---- app/Services/CategoryService.php | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Admin/PriceSyncLogController.php b/app/Http/Controllers/Admin/PriceSyncLogController.php index d9e1507..7ff8754 100644 --- a/app/Http/Controllers/Admin/PriceSyncLogController.php +++ b/app/Http/Controllers/Admin/PriceSyncLogController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers\Admin; use App\DB\Te\TableEngine; use App\Http\Controllers\Controller; use App\Models\PriceSyncLog; -use App\Services\ConfigService; use App\Services\ProductPriceSyncService; use Illuminate\Http\Request; @@ -30,12 +29,8 @@ class PriceSyncLogController extends Controller return response()->json($log); } - public function runSync(ProductPriceSyncService $syncService, ConfigService $configService) + public function runSync(ProductPriceSyncService $syncService) { - if (! $configService->isStore()) { - return response()->json(['message' => 'فقط در حالت فروشگاه'], 422); - } - $syncService->syncStorePrices(true); $log = PriceSyncLog::with('items')->orderByDesc('id')->first(); diff --git a/app/Services/CategoryService.php b/app/Services/CategoryService.php index 3f082c5..7b56de1 100644 --- a/app/Services/CategoryService.php +++ b/app/Services/CategoryService.php @@ -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; }