前台商品详情variables多语言处理
This commit is contained in:
parent
31724b3660
commit
b5f6249f87
|
|
@ -16,7 +16,7 @@ class ProductController extends Controller
|
|||
$data = [
|
||||
'product' => (new ProductDetail($product))->jsonSerialize(),
|
||||
];
|
||||
|
||||
dd($data);
|
||||
return view('product', $data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue