前台商品详情variables多语言处理

This commit is contained in:
TL 2022-07-21 18:32:26 +08:00
parent 31724b3660
commit b5f6249f87
2 changed files with 18 additions and 2 deletions

View File

@ -16,7 +16,7 @@ class ProductController extends Controller
$data = [
'product' => (new ProductDetail($product))->jsonSerialize(),
];
dd($data);
return view('product', $data);
}
}

View File

@ -23,8 +23,24 @@ class ProductDetail extends JsonResource
'description' => $this->description->description ?? '',
'image' => image_resize($this->image),
'category_id' => $this->category_id ?? null,
'variables' => $this->variables,
'variables' => $this->decodeVariables($this->variables),
'skus' => SkuDetail::collection($this->skus)->jsonSerialize(),
];
}
private function decodeVariables($variables)
{
$lang = current_language_code();
return array_map(function ($item) use ($lang){
return [
'name' => $item['name'][$lang],
'values' => array_map(function ($item) use ($lang){
return [
'name' => $item['name'][$lang],
'image' => image_resize($item['image'], 100, 100),
];
}, $item['values']),
];
}, $variables);
}
}