fix bug ۲

This commit is contained in:
2026-07-10 00:19:30 +03:30
parent e0c4897111
commit abc58c4180
2 changed files with 27 additions and 5 deletions
@@ -265,7 +265,7 @@ class SingleOrderController extends Controller
$data['total_price'] = $data['amount'] * $data['price'];
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
$this->enforceProductOrderLimits($data);
if (!empty($data['first_buy']) && ($minFirstBuy = Setting::where('is_active', 1)->where('key', 'min_first_buy')->value('value'))) {
if ($data['total_price'] < (int) $minFirstBuy) {
@@ -1278,7 +1278,7 @@ class SingleOrderController extends Controller
return false;
}
private function enforceProductOrderLimits(array &$data, float $totalPriceRial): void
private function enforceProductOrderLimits(array &$data, ?float $totalPriceRial = null): void
{
$product = $data['product'] ?? null;
@@ -1298,7 +1298,25 @@ class SingleOrderController extends Controller
}
if ($product instanceof Product) {
$product->validateOrderCashLimit($totalPriceRial);
$product->validateOrderCashLimit($this->resolveOrderLimitCashRial($data, $totalPriceRial));
}
}
/**
* مبلغ مؤثر برای min/max محصول — با target_cash همان مبلغی که کاربر وارد کرده
* (نه total_price موقت قبل از رُند گرم که ممکن است چند ریال کمتر شود).
*/
private function resolveOrderLimitCashRial(array $data, ?float $fallbackTotal = null): float
{
$targetCash = $this->resolveTargetCash($data);
if ($targetCash !== null) {
return (float) $targetCash;
}
if ($fallbackTotal !== null) {
return $fallbackTotal;
}
return (float) ($data['payment_amount'] ?? $data['total_price'] ?? 0);
}
}