fix(product): separate list and TV visibility toggles

Product active toggle now drives show_in_list; TV has its own endpoint and no longer requires active.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 10:16:35 +03:30
co-authored by Cursor
parent f3eaf91559
commit e4e9c74872
2 changed files with 62 additions and 14 deletions
@@ -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()) {