feat(server): add show_on_tv product flag and public /tv products API

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 17:17:01 +03:30
co-authored by Cursor
parent da9f98b958
commit e158831fd3
6 changed files with 177 additions and 0 deletions
@@ -244,6 +244,43 @@ class ProductController extends SuperController
return response()->json($products);
}
/**
* تابلو /tv — بدون لاگین؛ فقط محصولات تیک‌خورده.
*/
public function listTvProducts()
{
if (! Product::hasShowOnTvColumn()) {
return response()->json([]);
}
$products = Product::with(['file'])
->where('active', 1)
->where('show_on_tv', true)
->get();
if (app(ConfigService::class)->isStore()) {
$categoryService = app(CategoryService::class);
$products = $categoryService->filterProductsByVisibleCategories($products);
$products = $categoryService->sortProductsForStore($products);
}
$this->applyCustomerShow($products);
$products = $products->filter(function (Product $product) {
return (bool) $product->show_on_tv;
});
if (Product::hasPriceOffsetColumn()) {
$products->each(function (Product $product) {
if ($product->reading_method) {
$product->makeHidden(['price_offset_percent']);
}
});
}
return response()->json($products->values()->all());
}
public function ProductById($id)
{
if (! $this->isCustomerApiRequest()) {
@@ -652,6 +689,12 @@ 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::hasUseLastPriceIfZeroColumn()) {
unset($data['use_last_price_if_zero']);
} elseif (array_key_exists('use_last_price_if_zero', $data)) {
+25
View File
@@ -19,6 +19,7 @@ class Product extends Model
private static ?bool $priceColumnExists = null;
private static ?bool $orderLimitColumnsExist = null;
private static ?bool $showInAssetsColumnExists = null;
private static ?bool $showOnTvColumnExists = null;
private static ?bool $useLastPriceIfZeroColumnExists = null;
private static ?bool $directPriceColumnExists = null;
private static ?bool $appPriceColumnExists = null;
@@ -46,6 +47,9 @@ class Product extends Model
if (!static::hasShowInAssetsColumn()) {
unset($product->attributes['show_in_assets']);
}
if (!static::hasShowOnTvColumn()) {
unset($product->attributes['show_on_tv']);
}
if (!static::hasUseLastPriceIfZeroColumn()) {
unset($product->attributes['use_last_price_if_zero']);
}
@@ -231,6 +235,24 @@ class Product extends Model
return static::$showInAssetsColumnExists;
}
public static function hasShowOnTvColumn(): bool
{
if (static::$showOnTvColumnExists !== null) {
return static::$showOnTvColumnExists;
}
try {
static::$showOnTvColumnExists = Schema::hasColumn(
(new static)->getTable(),
'show_on_tv'
);
} catch (\Throwable) {
static::$showOnTvColumnExists = false;
}
return static::$showOnTvColumnExists;
}
public static function hasUseLastPriceIfZeroColumn(): bool
{
if (static::$useLastPriceIfZeroColumnExists !== null) {
@@ -413,6 +435,7 @@ class Product extends Model
'for_barayand', // Whether it is for Barayand (boolean).
'show', // Whether to show the record (boolean).
'show_in_assets', // Show balance on customer assets page cards
'show_on_tv', // Show this product on customer /tv board
'trade_by_quantity', // UI معامله مقداری: ارزش کل + مقدار
'use_last_price_if_zero', // Keep last DB price when automatic provider returns zero
'open_sell', // Whether selling is open (boolean).
@@ -448,6 +471,7 @@ class Product extends Model
protected $attributes = [
'show_in_assets' => false,
'show_on_tv' => false,
'trade_by_quantity' => false,
'use_last_price_if_zero' => false,
'cash_fee_buy_is_percent' => false,
@@ -461,6 +485,7 @@ class Product extends Model
'active' => 'boolean', // Cast to boolean.
'show' => 'boolean', // Cast to boolean.
'show_in_assets' => 'boolean',
'show_on_tv' => 'boolean',
'trade_by_quantity' => 'boolean',
'use_last_price_if_zero' => 'boolean',
'override_trading_hours' => 'boolean',