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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user