diff --git a/app/Http/Controllers/Admin/ProductController.php b/app/Http/Controllers/Admin/ProductController.php index b73f057..3391f70 100644 --- a/app/Http/Controllers/Admin/ProductController.php +++ b/app/Http/Controllers/Admin/ProductController.php @@ -227,7 +227,13 @@ class ProductController extends SuperController } // آبشده خانگی — کران قیمت را آپدیت می‌کند؛ list فقط از DB می‌خواند - $products = Product::with(['file'])->where('active', 1)->get(); + $query = Product::with(['file']); + if (Product::hasShowInListColumn()) { + $query->where('show_in_list', 1); + } else { + $query->where('active', 1); + } + $products = $query->get(); if ($this->isCustomerApiRequest()) { $products = $this->filterProductsForCustomerList($products); @@ -255,7 +261,6 @@ class ProductController extends SuperController } $products = Product::with(['file']) - ->where('active', 1) ->where('show_on_tv', true) ->get(); @@ -351,16 +356,40 @@ class ProductController extends SuperController } /** - * فعال/غیرفعال محصول — show باید با active هم‌گام باشد (اپ کاربر از show استفاده می‌کند). + * نمایش در لیست محصولات مشتری — با active/show هم‌گام می‌ماند (وضعیت باز/بسته جدول). + * تابلو TV جداست و با این متد عوض نمی‌شود. */ public function active($id) { $product = Product::findOrFail($id); - $active = !$product->active; + $on = ! $this->isProductShownInList($product); + $payload = [ + 'active' => $on, + 'show' => $on, + ]; + if (Product::hasShowInListColumn()) { + $payload['show_in_list'] = $on; + } + $product->update($payload); + $this->broadcastPricesAfterResponse(true); + + return response()->json(true); + } + + /** + * نمایش در تابلو TV — مستقل از لیست محصولات و active. + */ + public function showOnTv($id) + { + if (! Product::hasShowOnTvColumn()) { + return response()->json(['message' => 'ستون show_on_tv موجود نیست'], 404); + } + + $product = Product::findOrFail($id); $product->update([ - 'active' => $active, - 'show' => $active, + 'show_on_tv' => ! (bool) $product->show_on_tv, ]); + $this->broadcastPricesAfterResponse(true); return response()->json(true); } @@ -586,7 +615,13 @@ class ProductController extends SuperController */ public function customerStoreProductListPayload(): array { - $products = Product::with(['file'])->where('active', 1)->get(); + $query = Product::with(['file']); + if (Product::hasShowInListColumn()) { + $query->where('show_in_list', 1); + } else { + $query->where('active', 1); + } + $products = $query->get(); $products = $this->filterProductsForCustomerList($products); $categoryService = app(CategoryService::class); $products = $categoryService->filterProductsByVisibleCategories($products); @@ -653,10 +688,19 @@ class ProductController extends SuperController } return $collection->filter(function (Product $product) { - return (bool) $product->show_in_list; + return $this->isProductShownInList($product); })->values(); } + private function isProductShownInList(Product $product): bool + { + if (Product::hasShowInListColumn()) { + return (bool) $product->show_in_list; + } + + return (bool) $product->active; + } + private function applyCustomerShow($products): void { $products = $products instanceof \Illuminate\Support\Collection @@ -754,16 +798,19 @@ class ProductController extends SuperController $data['show_in_assets'] = !empty($data['show_in_assets']); } - if (!Product::hasShowOnTvColumn()) { - unset($data['show_on_tv']); - } elseif (array_key_exists('show_on_tv', $data)) { - $data['show_on_tv'] = !empty($data['show_on_tv']); - } - if (!Product::hasShowInListColumn()) { unset($data['show_in_list']); } elseif (array_key_exists('show_in_list', $data)) { $data['show_in_list'] = !empty($data['show_in_list']); + // لیست و وضعیت باز/بسته یکی‌اند؛ TV جدا می‌ماند + $data['active'] = $data['show_in_list']; + $data['show'] = $data['show_in_list']; + } + + if (!Product::hasShowOnTvColumn()) { + unset($data['show_on_tv']); + } elseif (array_key_exists('show_on_tv', $data)) { + $data['show_on_tv'] = !empty($data['show_on_tv']); } if (!Product::hasUseLastPriceIfZeroColumn()) { diff --git a/routes/admin.php b/routes/admin.php index eeb0931..dc8bfa4 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -96,6 +96,7 @@ Route::middleware('auth:user')->group(function (){ Route::post('/product/archive/table', [ProductController::class, 'archiveTable']); Route::get('/product/archive/{id}', [ProductController::class, 'archive']); Route::get('/product/active/{id}',[ProductController::class, 'active']); + Route::get('/product/show_on_tv/{id}',[ProductController::class, 'showOnTv']); Route::get('/product/hide/{id}',[ProductController::class, 'hide']); Route::get('/product/credit',[ProductController::class, 'listProductCredit']); Route::get('/product/list',[ProductController::class, 'listProduct']);