fallback handled

This commit is contained in:
2026-06-17 16:13:18 +03:30
parent 34298d3bc5
commit cc5808e755
7 changed files with 232 additions and 2 deletions
+25
View File
@@ -21,6 +21,7 @@ class Product extends Model
private static ?bool $showInAssetsColumnExists = null;
private static ?bool $useLastPriceIfZeroColumnExists = null;
private static ?bool $directPriceColumnExists = null;
private static ?bool $tradeByQuantityColumnExists = null;
protected static function booted(): void
{
@@ -44,6 +45,9 @@ class Product extends Model
if (!static::hasDirectPriceColumn()) {
unset($product->attributes['direct_price']);
}
if (!static::hasTradeByQuantityColumn()) {
unset($product->attributes['trade_by_quantity']);
}
});
}
@@ -153,6 +157,24 @@ class Product extends Model
return static::$directPriceColumnExists;
}
public static function hasTradeByQuantityColumn(): bool
{
if (static::$tradeByQuantityColumnExists !== null) {
return static::$tradeByQuantityColumnExists;
}
try {
static::$tradeByQuantityColumnExists = Schema::hasColumn(
(new static)->getTable(),
'trade_by_quantity'
);
} catch (\Throwable) {
static::$tradeByQuantityColumnExists = false;
}
return static::$tradeByQuantityColumnExists;
}
public function orderLimitsEnabled(): bool
{
if (!static::hasOrderLimitColumns() || !($this->order_limit_enabled ?? false)) {
@@ -204,6 +226,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
'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).
'auto_open_at', // Whether selling is open (boolean).
@@ -230,6 +253,7 @@ class Product extends Model
protected $attributes = [
'show_in_assets' => false,
'trade_by_quantity' => false,
'use_last_price_if_zero' => false,
];
@@ -238,6 +262,7 @@ class Product extends Model
'active' => 'boolean', // Cast to boolean.
'show' => 'boolean', // Cast to boolean.
'show_in_assets' => 'boolean',
'trade_by_quantity' => 'boolean',
'use_last_price_if_zero' => 'boolean',
'for_barayand' => 'boolean', // Cast to boolean.
'open_sell' => 'boolean', // Cast to boolean.