diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index 5677406..6103ab4 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -181,7 +181,7 @@ class ProductController extends SuperController if (app(ConfigService::class)->isStore()) { app(ProductPriceSyncService::class)->syncStorePrices(true); - if (! str_contains(request()->path(), '/customer/')) { + if (! $this->isCustomerApiRequest()) { $this->auto_close_open(); } @@ -190,7 +190,7 @@ class ProductController extends SuperController $products = $categoryService->filterProductsByVisibleCategories($products); $products = $categoryService->sortProductsForStore($products); - if (str_contains(request()->path(), '/customer/')) { + if ($this->isCustomerApiRequest()) { $this->applyCustomerShow($products); } @@ -200,11 +200,11 @@ class ProductController extends SuperController // آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند $products = Product::with(['file'])->where('active', 1)->get(); - if (str_contains(request()->path(), '/customer/')) { + if ($this->isCustomerApiRequest()) { $this->applyCustomerShow($products); } - if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) { + if (Product::hasPriceOffsetColumn() && $this->isCustomerApiRequest()) { $products->each(function (Product $product) { if ($product->reading_method) { $product->makeHidden(['price_offset_percent']); @@ -224,7 +224,7 @@ class ProductController extends SuperController ->first(); if ($product) { - if (str_contains(request()->path(), '/customer/')) { + if ($this->isCustomerApiRequest()) { $this->applyCustomerShow(collect([$product])); } @@ -233,7 +233,7 @@ class ProductController extends SuperController ->where('id', '!=', $id) ->get(); - if (str_contains(request()->path(), '/customer/')) { + if ($this->isCustomerApiRequest()) { $this->applyCustomerShow($product->similar); } } else { @@ -379,6 +379,11 @@ class ProductController extends SuperController return false; } + private function isCustomerApiRequest(): bool + { + return str_starts_with(request()->path(), 'customer/'); + } + private function applyCustomerShow($products): void { $products = $products instanceof \Illuminate\Support\Collection