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