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 <cursoragent@cursor.com>
This commit is contained in:
@@ -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<int, mixed>|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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user