From ffaded6fef7e101ce5aab6ba34fbb2ceb12b57d7 Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 25 Aug 2026 20:49:53 +0330 Subject: [PATCH] fix(price): normalize store product list for SSE identity and images Store SSE payloads were Eloquent models, so listIdentity skipped them and file_id changes never republished; encode to plain arrays before hash/publish. Co-authored-by: Cursor --- app/Services/PriceBroadcastService.php | 43 ++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/app/Services/PriceBroadcastService.php b/app/Services/PriceBroadcastService.php index 0c25546..5820e09 100644 --- a/app/Services/PriceBroadcastService.php +++ b/app/Services/PriceBroadcastService.php @@ -171,11 +171,21 @@ class PriceBroadcastService $identity = []; foreach ($listPayload as $product) { + if ($product instanceof \Illuminate\Database\Eloquent\Model) { + $product = $product->toArray(); + } + if (! is_array($product)) { continue; } - $file = is_array($product['file'] ?? null) ? $product['file'] : []; + $file = $product['file'] ?? null; + if ($file instanceof \Illuminate\Database\Eloquent\Model) { + $file = $file->toArray(); + } + if (! is_array($file)) { + $file = []; + } $identity[] = [ 'id' => (int) ($product['id'] ?? 0), @@ -218,7 +228,9 @@ class PriceBroadcastService private function buildProductListPayload(): ?array { if (app(ConfigService::class)->isStore()) { - return app(ProductController::class)->customerStoreProductListPayload(); + return $this->normalizeListPayload( + app(ProductController::class)->customerStoreProductListPayload() + ); } $request = Request::create('/customer/product/list', 'GET'); @@ -229,4 +241,31 @@ class PriceBroadcastService return is_array($decoded) ? $decoded : null; } + + /** + * مدل/کالکشن Eloquent را به آرایهٔ خالص تبدیل می‌کند تا listIdentity و SSE + * همیشه file_id و URL تصویر را ببینند (قبلاً is_array روی Model شکست می‌خورد). + * + * @param mixed $payload + * @return array|null + */ + private function normalizeListPayload(mixed $payload): ?array + { + if ($payload === null) { + return null; + } + + if ($payload === []) { + return []; + } + + $encoded = json_encode($payload, JSON_UNESCAPED_UNICODE); + if ($encoded === false) { + return null; + } + + $decoded = json_decode($encoded, true); + + return is_array($decoded) ? $decoded : null; + } }