fix amount

This commit is contained in:
2026-06-09 09:57:58 +03:30
parent f725e0fe8b
commit 518f4bd2ae
@@ -63,8 +63,11 @@ class SingleOrderController extends Controller
$customer = Customer::find(auth('customer')->id() ?? ($data['customer_id'] ?? null));
if ($min_sell = Setting::where('key', 'minimum_sell')->where('is_active', 1)->first()) {
if ((int) $data['direction'] === 2 && (float) $min_sell->value > (float) $data['amount']) {
throw new UnprocessableEntityHttpException('حداقل میزان فروش ' . $min_sell->value . ' گرم میباشد');
if ((int) $data['direction'] === 2) {
$sellAmount = $this->resolveOrderAmount($data);
if ($sellAmount !== null && (float) $min_sell->value > $sellAmount) {
throw new UnprocessableEntityHttpException('حداقل میزان فروش ' . $min_sell->value . ' گرم میباشد');
}
}
}
@@ -726,6 +729,22 @@ class SingleOrderController extends Controller
->count() < (int)$count;
}
private function resolveOrderAmount(array $data): ?float
{
if (isset($data['amount'])) {
return (float) $data['amount'];
}
if (!empty($data['product_id']) && isset($data['number'])) {
$product = $data['product'] ?? Product::find($data['product_id']);
if ($product) {
return (float) $data['number'] * (float) $product->amount;
}
}
return null;
}
private function isProductOrder(array $data): bool
{
return !empty($data['product_id']) && !empty($data['product']['title']);