fix bug 22/4 2

This commit is contained in:
2026-07-13 19:03:30 +03:30
parent 7eb4650b80
commit 277cf31d93
8 changed files with 217 additions and 29 deletions
+33 -8
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 $appPriceColumnExists = null;
private static ?bool $tradeByQuantityColumnExists = null;
private static ?bool $inventoryColumnExists = null;
private static ?bool $overrideTradingHoursColumnExists = null;
@@ -49,6 +50,9 @@ class Product extends Model
if (!static::hasDirectPriceColumn()) {
unset($product->attributes['direct_price']);
}
if (!static::hasAppPriceColumn()) {
unset($product->attributes['app_price']);
}
if (!static::hasTradeByQuantityColumn()) {
unset($product->attributes['trade_by_quantity']);
}
@@ -67,7 +71,7 @@ class Product extends Model
if (!static::hasPhysicalDeliveryColumns()) {
unset(
$product->attributes['has_physical_delivery'],
$product->attributes['min_physical_delivery_grams']
$product->attributes['min_physical_delivery_quantity']
);
}
});
@@ -82,7 +86,7 @@ class Product extends Model
try {
$table = (new static)->getTable();
static::$physicalDeliveryColumnsExist = Schema::hasColumn($table, 'has_physical_delivery')
&& Schema::hasColumn($table, 'min_physical_delivery_grams');
&& Schema::hasColumn($table, 'min_physical_delivery_quantity');
} catch (\Throwable) {
static::$physicalDeliveryColumnsExist = false;
}
@@ -235,6 +239,24 @@ class Product extends Model
return static::$directPriceColumnExists;
}
public static function hasAppPriceColumn(): bool
{
if (static::$appPriceColumnExists !== null) {
return static::$appPriceColumnExists;
}
try {
static::$appPriceColumnExists = Schema::hasColumn(
(new static)->getTable(),
'app_price'
);
} catch (\Throwable) {
static::$appPriceColumnExists = false;
}
return static::$appPriceColumnExists;
}
public static function hasTradeByQuantityColumn(): bool
{
if (static::$tradeByQuantityColumnExists !== null) {
@@ -315,11 +337,11 @@ class Product extends Model
return (bool) ($this->attributes['has_physical_delivery'] ?? false);
}
public function minPhysicalDeliveryGrams(): float
public function minPhysicalDeliveryQuantity(): float
{
$value = static::hasPhysicalDeliveryColumns()
? ($this->min_physical_delivery_grams ?? 0)
: ($this->attributes['min_physical_delivery_grams'] ?? 0);
? ($this->min_physical_delivery_quantity ?? 0)
: ($this->attributes['min_physical_delivery_quantity'] ?? 0);
return max(0.0, (float) $value);
}
@@ -363,8 +385,8 @@ class Product extends Model
'order_limit_enabled',
'min_order_cash',
'max_order_cash',
'has_physical_delivery', // روشن: این محصول امکان تحویل فیزیکی دارد
'min_physical_delivery_grams', // حداقل موجودی (گرم) برای فعال شدن تحویل فیزیکی
'has_physical_delivery', // روشن: این محصول امکان تحویل فیزیکی دارد
'min_physical_delivery_quantity', // حداقل موجودی برای فعال شدن تحویل (عدد برای تعدادی، گرم/کیلوگرم برای وزنی)
'metal_id', //the material of metal (#gold or #silver)
'price_offset_percent', // admin only: +/- % vs automatic reference (baked into price on sync)
'price_profit',
@@ -372,6 +394,7 @@ class Product extends Model
'inventory',
'description',
'direct_price',
'app_price', // روشن: قیمت واحد از قیمت زندهٔ اپ هر گرم × وزن محاسبه می‌شود
];
protected $attributes = [
@@ -380,6 +403,7 @@ class Product extends Model
'use_last_price_if_zero' => false,
'cash_fee_buy_is_percent' => false,
'cash_fee_sell_is_percent' => false,
'app_price' => false,
];
protected $casts = [
@@ -402,13 +426,14 @@ class Product extends Model
'min_order_cash' => 'int',
'max_order_cash' => 'int',
'has_physical_delivery' => 'boolean',
'min_physical_delivery_grams' => 'float',
'min_physical_delivery_quantity' => 'float',
'cash_fee_buy' => 'float',
'cash_fee_sell' => 'float',
'cash_fee_buy_is_percent' => 'boolean',
'cash_fee_sell_is_percent' => 'boolean',
'price_offset_percent' => 'float',
'price_profit' => 'int',
'app_price' => 'boolean',
];
static $METAL_ID = [