From 8540d57abc8d27c8aa83e422a70fbe65e1b9abf5 Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Fri, 12 Jun 2026 16:55:22 +0330 Subject: [PATCH] new check for kashkol 3 --- .../Controllers/Admin/ProductController.php | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 7777f05..da17027 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -152,18 +152,38 @@ class ProductController extends SuperController public function listProduct() { + $isCustomerApi = str_contains(request()->path(), '/customer/'); + $config = app(ConfigService::class); + $isStore = $config->isStore(); + // ادمین: sync اختیاری از کش — کاربر: فقط enrich از کش کران (بدون HTTP / بدون UPDATE) - if (!str_contains(request()->path(), '/customer/')) { + if (! $isCustomerApi) { app(\App\Services\ProductPriceSyncService::class)->syncAll(false); } + // فروشگاه (قطره / کشکول): مثل ghatre — show بر اساس ساعت auto_open/auto_close + if ($isCustomerApi && $isStore) { + $this->auto_close_open(); + } + $products = Product::with(['file'])->where('active', 1)->get(); - if (str_contains(request()->path(), '/customer/')) { + if ($isCustomerApi) { $displayPriceService = app(ProductDisplayPriceService::class); $displayPriceService->enrichForApi($products); - $products->each(function (Product $product) use ($displayPriceService) { - if (!$displayPriceService->hasCustomerDisplayPrice($product)) { + $showLastPrice = $config->getBool('show_last_price', false); + + $products->each(function (Product $product) use ($displayPriceService, $isStore, $showLastPrice) { + if ($isStore) { + // فقط وقتی قیمت صفر است و fallback آخرین قیمت هم خاموش است + if (! $displayPriceService->hasCustomerDisplayPrice($product) && ! $showLastPrice) { + $product->setAttribute('show', false); + } + + return; + } + + if (! $displayPriceService->hasCustomerDisplayPrice($product)) { $product->setAttribute('show', false); } });