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 <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 18:20:13 +03:30
co-authored by Cursor
parent e0216d35a6
commit 7b81adc096
2 changed files with 27 additions and 5 deletions
@@ -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;
}
}
+4 -1
View File
@@ -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');