generated from boboko/starter
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Response;
|
|
use Modules\Core\Catalog\Services\ProductService;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function __construct(private readonly ProductService $products) {}
|
|
|
|
public function show(string $locale, int $id)
|
|
{
|
|
$product = $this->products->getById($id);
|
|
abort_if($product === null, Response::HTTP_NOT_FOUND);
|
|
|
|
$collection = $product['collections'][0] ?? null;
|
|
|
|
$variantsData = collect($product['variants'])
|
|
->map(fn (array $variant) => [
|
|
'id' => $variant['id'],
|
|
'price' => $variant['prices'][0]['price'] ?? null,
|
|
'image' => $variant['media'][0]['url'] ?? null,
|
|
])
|
|
->values()
|
|
->all();
|
|
|
|
$firstVariant = $product['variants'][0] ?? null;
|
|
$option = $firstVariant['options'][0]['option'] ?? null;
|
|
|
|
return view('product.show', [
|
|
'collection' => $collection,
|
|
'product' => $product,
|
|
'option' => $option,
|
|
'variantsData' => $variantsData,
|
|
]);
|
|
}
|
|
}
|