fix bug in 22/4

This commit is contained in:
2026-07-13 13:31:44 +03:30
parent 82691cdf2c
commit 7eb4650b80
4 changed files with 145 additions and 0 deletions
+46
View File
@@ -25,6 +25,7 @@ class Product extends Model
private static ?bool $inventoryColumnExists = null;
private static ?bool $overrideTradingHoursColumnExists = null;
private static ?bool $cashFeePercentModeColumnsExist = null;
private static ?bool $physicalDeliveryColumnsExist = null;
protected static function booted(): void
{
@@ -63,9 +64,32 @@ class Product extends Model
$product->attributes['cash_fee_sell_is_percent']
);
}
if (!static::hasPhysicalDeliveryColumns()) {
unset(
$product->attributes['has_physical_delivery'],
$product->attributes['min_physical_delivery_grams']
);
}
});
}
public static function hasPhysicalDeliveryColumns(): bool
{
if (static::$physicalDeliveryColumnsExist !== null) {
return static::$physicalDeliveryColumnsExist;
}
try {
$table = (new static)->getTable();
static::$physicalDeliveryColumnsExist = Schema::hasColumn($table, 'has_physical_delivery')
&& Schema::hasColumn($table, 'min_physical_delivery_grams');
} catch (\Throwable) {
static::$physicalDeliveryColumnsExist = false;
}
return static::$physicalDeliveryColumnsExist;
}
public static function hasOverrideTradingHoursColumn(): bool
{
if (static::$overrideTradingHoursColumnExists !== null) {
@@ -282,6 +306,24 @@ class Product extends Model
}
}
public function physicalDeliveryEnabled(): bool
{
if (static::hasPhysicalDeliveryColumns()) {
return (bool) ($this->has_physical_delivery ?? false);
}
return (bool) ($this->attributes['has_physical_delivery'] ?? false);
}
public function minPhysicalDeliveryGrams(): float
{
$value = static::hasPhysicalDeliveryColumns()
? ($this->min_physical_delivery_grams ?? 0)
: ($this->attributes['min_physical_delivery_grams'] ?? 0);
return max(0.0, (float) $value);
}
public function getPriceOffsetPercentAttribute($value): float
{
if (!static::hasPriceOffsetColumn()) {
@@ -321,6 +363,8 @@ class Product extends Model
'order_limit_enabled',
'min_order_cash',
'max_order_cash',
'has_physical_delivery', // روشن: این محصول امکان تحویل فیزیکی دارد
'min_physical_delivery_grams', // حداقل موجودی (گرم) برای فعال شدن تحویل فیزیکی
'metal_id', //the material of metal (#gold or #silver)
'price_offset_percent', // admin only: +/- % vs automatic reference (baked into price on sync)
'price_profit',
@@ -357,6 +401,8 @@ class Product extends Model
'order_limit_enabled' => 'boolean',
'min_order_cash' => 'int',
'max_order_cash' => 'int',
'has_physical_delivery' => 'boolean',
'min_physical_delivery_grams' => 'float',
'cash_fee_buy' => 'float',
'cash_fee_sell' => 'float',
'cash_fee_buy_is_percent' => 'boolean',