2026-07-31 17:41:55 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-08-27 00:55:56 +03:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Lunar\Models\Collection;
|
2026-08-27 01:21:57 +03:00
|
|
|
use Modules\Core\Product\Services\ProductService;
|
2026-07-31 17:41:55 +03:00
|
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
2026-08-27 00:55:56 +03:00
|
|
|
public function __construct(private readonly ProductService $products) {}
|
|
|
|
|
|
|
|
|
|
public function show(string $locale, int $id)
|
2026-07-31 17:41:55 +03:00
|
|
|
{
|
2026-08-27 00:55:56 +03:00
|
|
|
$product = $this->products->getById($id);
|
|
|
|
|
|
|
|
|
|
abort_if($product === null, Response::HTTP_NOT_FOUND);
|
2026-07-31 17:41:55 +03:00
|
|
|
|
2026-08-27 00:55:56 +03:00
|
|
|
$collection = $product['collections'][0] ?? null;
|
|
|
|
|
$collectionModel = $collection !== null ? Collection::find($collection) : null;
|
2026-07-31 17:41:55 +03:00
|
|
|
|
2026-08-27 00:55:56 +03:00
|
|
|
$variantsData = collect($product['variants'])
|
|
|
|
|
->map(fn (array $variant) => [
|
|
|
|
|
'id' => $variant['id'],
|
|
|
|
|
'price' => $variant['prices'][0]['price'] ?? null,
|
|
|
|
|
'image' => $variant['media'][0]['url'] ?? null,
|
|
|
|
|
])
|
2026-07-31 17:41:55 +03:00
|
|
|
->values()
|
2026-08-27 00:55:56 +03:00
|
|
|
->all();
|
2026-07-31 17:41:55 +03:00
|
|
|
|
2026-08-27 00:55:56 +03:00
|
|
|
$firstVariant = $product['variants'][0] ?? null;
|
|
|
|
|
$option = $firstVariant['options'][0]['option'] ?? null;
|
2026-07-31 17:41:55 +03:00
|
|
|
|
|
|
|
|
// temp categories here
|
2026-08-27 00:55:56 +03:00
|
|
|
$categories = Collection::orderBy('_lft')->get();
|
|
|
|
|
|
|
|
|
|
return view('product.show', [
|
|
|
|
|
'categories' => $categories,
|
|
|
|
|
'collection' => $collectionModel,
|
|
|
|
|
'product' => $product,
|
|
|
|
|
'option' => $option,
|
|
|
|
|
'variantsData' => $variantsData,
|
2026-07-31 17:41:55 +03:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|