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:
parent
293dd7d1fd
commit
6c0db0af4e
@ -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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user