feat(product): add show_in_list toggle and TV price formula
- New `show_in_list` column to control product visibility in customer list - New `tv_price_formula_enabled` + `tv_price_formula` columns for separate TV pricing - FormulaPriceService: isTvEnabled() and calculateTvForProduct() - listTvProducts applies TV formula overrides before returning - filterProductData handles both new field sets Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -20,6 +20,7 @@ class Product extends Model
|
||||
private static ?bool $orderLimitColumnsExist = null;
|
||||
private static ?bool $showInAssetsColumnExists = null;
|
||||
private static ?bool $showOnTvColumnExists = null;
|
||||
private static ?bool $showInListColumnExists = null;
|
||||
private static ?bool $useLastPriceIfZeroColumnExists = null;
|
||||
private static ?bool $directPriceColumnExists = null;
|
||||
private static ?bool $appPriceColumnExists = null;
|
||||
@@ -29,6 +30,7 @@ class Product extends Model
|
||||
private static ?bool $cashFeePercentModeColumnsExist = null;
|
||||
private static ?bool $physicalDeliveryColumnsExist = null;
|
||||
private static ?bool $descriptionColumnExists = null;
|
||||
private static ?bool $tvPriceFormulaColumnsExist = null;
|
||||
private static ?bool $priceFormulaColumnsExist = null;
|
||||
|
||||
protected static function booted(): void
|
||||
@@ -50,6 +52,9 @@ class Product extends Model
|
||||
if (!static::hasShowOnTvColumn()) {
|
||||
unset($product->attributes['show_on_tv']);
|
||||
}
|
||||
if (!static::hasShowInListColumn()) {
|
||||
unset($product->attributes['show_in_list']);
|
||||
}
|
||||
if (!static::hasUseLastPriceIfZeroColumn()) {
|
||||
unset($product->attributes['use_last_price_if_zero']);
|
||||
}
|
||||
@@ -89,9 +94,32 @@ class Product extends Model
|
||||
$product->attributes['price_formula']
|
||||
);
|
||||
}
|
||||
if (!static::hasTvPriceFormulaColumns()) {
|
||||
unset(
|
||||
$product->attributes['tv_price_formula_enabled'],
|
||||
$product->attributes['tv_price_formula']
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function hasTvPriceFormulaColumns(): bool
|
||||
{
|
||||
if (static::$tvPriceFormulaColumnsExist !== null) {
|
||||
return static::$tvPriceFormulaColumnsExist;
|
||||
}
|
||||
|
||||
try {
|
||||
$table = (new static)->getTable();
|
||||
static::$tvPriceFormulaColumnsExist = Schema::hasColumn($table, 'tv_price_formula_enabled')
|
||||
&& Schema::hasColumn($table, 'tv_price_formula');
|
||||
} catch (\Throwable) {
|
||||
static::$tvPriceFormulaColumnsExist = false;
|
||||
}
|
||||
|
||||
return static::$tvPriceFormulaColumnsExist;
|
||||
}
|
||||
|
||||
public static function hasPriceFormulaColumns(): bool
|
||||
{
|
||||
if (static::$priceFormulaColumnsExist !== null) {
|
||||
@@ -253,6 +281,24 @@ class Product extends Model
|
||||
return static::$showOnTvColumnExists;
|
||||
}
|
||||
|
||||
public static function hasShowInListColumn(): bool
|
||||
{
|
||||
if (static::$showInListColumnExists !== null) {
|
||||
return static::$showInListColumnExists;
|
||||
}
|
||||
|
||||
try {
|
||||
static::$showInListColumnExists = Schema::hasColumn(
|
||||
(new static)->getTable(),
|
||||
'show_in_list'
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
static::$showInListColumnExists = false;
|
||||
}
|
||||
|
||||
return static::$showInListColumnExists;
|
||||
}
|
||||
|
||||
public static function hasUseLastPriceIfZeroColumn(): bool
|
||||
{
|
||||
if (static::$useLastPriceIfZeroColumnExists !== null) {
|
||||
@@ -436,6 +482,7 @@ class Product extends Model
|
||||
'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
|
||||
'show_in_list', // Show this product in customer product list
|
||||
'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).
|
||||
@@ -467,17 +514,21 @@ class Product extends Model
|
||||
'app_price', // روشن: قیمت واحد از قیمت زندهٔ اپ هر گرم × وزن محاسبه میشود
|
||||
'price_formula_enabled',
|
||||
'price_formula',
|
||||
'tv_price_formula_enabled',
|
||||
'tv_price_formula',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
'show_in_assets' => false,
|
||||
'show_on_tv' => false,
|
||||
'show_in_list' => true,
|
||||
'trade_by_quantity' => false,
|
||||
'use_last_price_if_zero' => false,
|
||||
'cash_fee_buy_is_percent' => false,
|
||||
'cash_fee_sell_is_percent' => false,
|
||||
'app_price' => false,
|
||||
'price_formula_enabled' => false,
|
||||
'tv_price_formula_enabled' => false,
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -486,6 +537,7 @@ class Product extends Model
|
||||
'show' => 'boolean', // Cast to boolean.
|
||||
'show_in_assets' => 'boolean',
|
||||
'show_on_tv' => 'boolean',
|
||||
'show_in_list' => 'boolean',
|
||||
'trade_by_quantity' => 'boolean',
|
||||
'use_last_price_if_zero' => 'boolean',
|
||||
'override_trading_hours' => 'boolean',
|
||||
@@ -510,6 +562,7 @@ class Product extends Model
|
||||
'price_profit' => 'int',
|
||||
'app_price' => 'boolean',
|
||||
'price_formula_enabled' => 'boolean',
|
||||
'tv_price_formula_enabled' => 'boolean',
|
||||
];
|
||||
|
||||
static $METAL_ID = [
|
||||
|
||||
Reference in New Issue
Block a user