fix bug
This commit is contained in:
@@ -17,6 +17,7 @@ class Product extends Model
|
||||
|
||||
private static ?bool $priceOffsetColumnExists = null;
|
||||
private static ?bool $priceColumnExists = null;
|
||||
private static ?bool $orderLimitColumnsExist = null;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
@@ -24,6 +25,13 @@ class Product extends Model
|
||||
if (!static::hasPriceOffsetColumn()) {
|
||||
unset($product->attributes['price_offset_percent']);
|
||||
}
|
||||
if (!static::hasOrderLimitColumns()) {
|
||||
unset(
|
||||
$product->attributes['order_limit_enabled'],
|
||||
$product->attributes['min_order_cash'],
|
||||
$product->attributes['max_order_cash']
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,6 +69,55 @@ class Product extends Model
|
||||
return static::$priceColumnExists;
|
||||
}
|
||||
|
||||
public static function hasOrderLimitColumns(): bool
|
||||
{
|
||||
if (static::$orderLimitColumnsExist !== null) {
|
||||
return static::$orderLimitColumnsExist;
|
||||
}
|
||||
|
||||
try {
|
||||
static::$orderLimitColumnsExist = Schema::hasColumn(
|
||||
(new static)->getTable(),
|
||||
'order_limit_enabled'
|
||||
);
|
||||
} catch (\Throwable) {
|
||||
static::$orderLimitColumnsExist = false;
|
||||
}
|
||||
|
||||
return static::$orderLimitColumnsExist;
|
||||
}
|
||||
|
||||
public function orderLimitsEnabled(): bool
|
||||
{
|
||||
if (!static::hasOrderLimitColumns() || !($this->order_limit_enabled ?? false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->min_order_cash !== null || $this->max_order_cash !== null;
|
||||
}
|
||||
|
||||
public function validateOrderCashLimit(float $totalPriceRial): void
|
||||
{
|
||||
if (!$this->orderLimitsEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$min = $this->min_order_cash;
|
||||
$max = $this->max_order_cash;
|
||||
|
||||
if ($min !== null && $totalPriceRial < (float) $min) {
|
||||
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
|
||||
'حداقل مبلغ این محصول ' . number_format((float) $min) . ' ریال میباشد'
|
||||
);
|
||||
}
|
||||
|
||||
if ($max !== null && $totalPriceRial > (float) $max) {
|
||||
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
|
||||
'حداکثر مبلغ این محصول ' . number_format((float) $max) . ' ریال میباشد'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPriceOffsetPercentAttribute($value): float
|
||||
{
|
||||
if (!static::hasPriceOffsetColumn()) {
|
||||
@@ -91,6 +148,9 @@ class Product extends Model
|
||||
'cash_fee_buy', // Add cash_fee_buy to fillable
|
||||
'cash_fee_sell', // Add cash_fee_sell to fillable
|
||||
'percent_fee_buy', // Add percent_fee_buy to fillable
|
||||
'order_limit_enabled',
|
||||
'min_order_cash',
|
||||
'max_order_cash',
|
||||
'metal_id', //the material of metal (#gold or #silver)
|
||||
'price_offset_percent', // admin only: +/- % vs automatic reference (baked into price on sync)
|
||||
'price_profit',
|
||||
@@ -109,6 +169,9 @@ class Product extends Model
|
||||
'price' => 'int', // Cast to float.
|
||||
'percent_fee_sell' => 'float', // Cast to float.
|
||||
'percent_fee_buy' => 'float', // Cast to float.
|
||||
'order_limit_enabled' => 'boolean',
|
||||
'min_order_cash' => 'int',
|
||||
'max_order_cash' => 'int',
|
||||
'cash_fee_buy' => 'int', // Cast to int or decimal if needed
|
||||
'cash_fee_sell' => 'int', // Cast to int or decimal if needed
|
||||
'price_offset_percent' => 'float',
|
||||
|
||||
Reference in New Issue
Block a user