diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 2e855a8..5677406 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -191,9 +191,7 @@ class ProductController extends SuperController $products = $categoryService->sortProductsForStore($products); if (str_contains(request()->path(), '/customer/')) { - $products->each(function (Product $product) { - $product->setAttribute('show', $this->storeProductShowForCustomer($product)); - }); + $this->applyCustomerShow($products); } return response()->json($products); @@ -203,12 +201,7 @@ class ProductController extends SuperController $products = Product::with(['file'])->where('active', 1)->get(); if (str_contains(request()->path(), '/customer/')) { - $displayPriceService = app(ProductDisplayPriceService::class); - $displayPriceService->warmLivePriceCache(); - $displayPriceService->enrichForApi($products); - $products->each(function (Product $product) use ($displayPriceService) { - $product->setAttribute('show', $displayPriceService->resolveCustomerShow($product)); - }); + $this->applyCustomerShow($products); } if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) { @@ -231,10 +224,18 @@ class ProductController extends SuperController ->first(); if ($product) { + if (str_contains(request()->path(), '/customer/')) { + $this->applyCustomerShow(collect([$product])); + } + $product->similar = Product::with(['file']) ->where('group_type', $product->group_type) ->where('id', '!=', $id) ->get(); + + if (str_contains(request()->path(), '/customer/')) { + $this->applyCustomerShow($product->similar); + } } else { return response()->json(false); } @@ -378,6 +379,32 @@ class ProductController extends SuperController return false; } + private function applyCustomerShow($products): void + { + $products = $products instanceof \Illuminate\Support\Collection + ? $products + : collect($products); + + if ($products->isEmpty()) { + return; + } + + if (app(ConfigService::class)->isStore()) { + $products->each(function (Product $product) { + $product->setAttribute('show', $this->storeProductShowForCustomer($product)); + }); + + return; + } + + $displayPriceService = app(ProductDisplayPriceService::class); + $displayPriceService->warmLivePriceCache(); + $displayPriceService->enrichForApi($products); + $products->each(function (Product $product) use ($displayPriceService) { + $product->setAttribute('show', $displayPriceService->resolveCustomerShow($product)); + }); + } + private function filterProductData(array $data): array { if (!Product::hasPriceOffsetColumn()) { diff --git a/app/Services/ProductPriceSyncService.php b/app/Services/ProductPriceSyncService.php index e750b93..132d5a9 100644 --- a/app/Services/ProductPriceSyncService.php +++ b/app/Services/ProductPriceSyncService.php @@ -174,7 +174,6 @@ class ProductPriceSyncService } $products = Product::query()->whereNotNull('reading_method')->get(); - $currentTime = now()->format('H:i:s'); $synced = false; foreach ($products as $product) {