fix: enhance voucher discount handling in order processing

- Updated the voucher discount calculation to handle error cases more gracefully.
- Reset voucher discount and selection if an error occurs during discount calculation.
- Improved user feedback by displaying error messages when voucher validation fails.
This commit is contained in:
Yoga Pangestu 2026-01-09 22:16:07 +07:00
parent 293dd7d1fd
commit 6c0db0af4e

View File

@ -43,7 +43,16 @@ public function updatedFormVoucherId(?string $voucherId = null): void
$subtotal = $this->getSubtotal();
$this->voucherDiscount = $this->calculateDiscount($subtotal, $voucher->id);
$voucherDiscountResult = $this->calculateDiscount($subtotal, $voucher->id);
if (is_array($voucherDiscountResult)) {
// Error case - reset voucher discount and show error
$this->voucherDiscount = 0;
$this->form->voucher_id = ''; // Reset voucher selection
$this->toast($voucherDiscountResult['message'], 'Error', 'danger');
} else {
$this->voucherDiscount = $voucherDiscountResult;
}
$this->total = $this->getTotal();
}