From 6c0db0af4e5e8549b45e56fc0eee419ae17e2948 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Fri, 9 Jan 2026 22:16:07 +0700 Subject: [PATCH] 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. --- app/Traits/Order/WithMember.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Traits/Order/WithMember.php b/app/Traits/Order/WithMember.php index cb638e1..ea6ed7e 100644 --- a/app/Traits/Order/WithMember.php +++ b/app/Traits/Order/WithMember.php @@ -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(); }