From d316266da739dc55b5fc968cea928964a00437ea Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 28 Jul 2026 15:38:40 +0700 Subject: [PATCH] fix: handle missing product variants gracefully in applyPayloadToProduct method --- app/Services/Master/ProductService.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Services/Master/ProductService.php b/app/Services/Master/ProductService.php index 45d0c85..e558481 100644 --- a/app/Services/Master/ProductService.php +++ b/app/Services/Master/ProductService.php @@ -543,7 +543,11 @@ private function applyPayloadToProduct( foreach ($payload['variants'] ?? [] as $index => $variantData) { if (! empty($variantData['id'])) { - $variant = $product->variants()->findOrFail($variantData['id']); + $variant = $product->variants()->find($variantData['id']); + + if ($variant === null) { + continue; + } $this->recordVariantStockChanges($variant, $variantData);