From 7b81adc096cb7a2d8a1f1ae85e8ed70f159639bc Mon Sep 17 00:00:00 2001 From: safavimohadeseh78 Date: Mon, 2 Nov 2026 18:20:13 +0330 Subject: [PATCH] fix(price-trigger): store the selected product instead of defaulting to gold Only a real numeric product id is saved, and an empty alert title no longer falls back to gold. Co-authored-by: Cursor --- .../Customer/PriceTriggerController.php | 27 ++++++++++++++++--- app/Services/PriceTriggerService.php | 5 +++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Customer/PriceTriggerController.php b/app/Http/Controllers/Customer/PriceTriggerController.php index ecc4d48..d139e83 100644 --- a/app/Http/Controllers/Customer/PriceTriggerController.php +++ b/app/Http/Controllers/Customer/PriceTriggerController.php @@ -58,8 +58,8 @@ class PriceTriggerController extends SuperController return; } - $productId = $request->input('product_id'); - if ($productId === null || $productId === '') { + $productId = $this->normalizeProductId($request->input('product_id')); + if ($productId === null) { if ($required) { throw new UnprocessableEntityHttpException('محصول را انتخاب کنید'); } @@ -69,7 +69,7 @@ class PriceTriggerController extends SuperController } $exists = Product::query() - ->where('id', (int) $productId) + ->where('id', $productId) ->where('active', 1) ->exists(); @@ -77,6 +77,25 @@ class PriceTriggerController extends SuperController throw new UnprocessableEntityHttpException('محصول نامعتبر است'); } - $request->merge(['product_id' => (int) $productId]); + $request->merge(['product_id' => $productId]); + } + + private function normalizeProductId($productId): ?int + { + if (is_array($productId)) { + $productId = $productId['id'] ?? $productId['product_id'] ?? null; + } + + if (is_object($productId)) { + $productId = $productId->id ?? null; + } + + if ($productId === null || $productId === '' || ! is_numeric($productId)) { + return null; + } + + $id = (int) $productId; + + return $id > 0 ? $id : null; } } diff --git a/app/Services/PriceTriggerService.php b/app/Services/PriceTriggerService.php index 51fe3bb..fab871b 100644 --- a/app/Services/PriceTriggerService.php +++ b/app/Services/PriceTriggerService.php @@ -160,7 +160,10 @@ class PriceTriggerService { $title = trim((string) ($product?->title ?? '')); if ($title === '') { - $title = 'طلا'; + $title = trim((string) app(ConfigService::class)->getString('metal_type', '')); + } + if ($title === '') { + $title = 'محصول'; } $shopName = (string) app(ConfigService::class)->getString('name_fa');