Files
3dealer/app/Http/Controllers/ProductController.php
T

53 lines
1.5 KiB
PHP
Raw Normal View History

2026-07-31 17:41:55 +03:00
<?php
namespace App\Http\Controllers;
use App\Catalog\ProductListing;
use App\Catalog\ProductListingPage;
use Illuminate\Http\Response;
use Modules\Core\Catalog\Services\ProductService;
2026-07-31 17:41:55 +03:00
class ProductController extends Controller
{
public function __construct(
private readonly ProductService $products,
private readonly ProductListingPage $listingPage,
) {}
/**
* All products — the category page without a collection scope. Filters,
* sort, pagination and the shared listing body all work identically.
*/
public function index(string $locale)
{
$listing = ProductListing::fromRequest(request());
$data = $this->listingPage->build(
$listing,
fn (array $query) => route('products', $query),
);
return view('products.index', $data);
}
public function show(string $locale, int $id)
2026-07-31 17:41:55 +03:00
{
$product = $this->products->getById($id);
abort_if($product === null, Response::HTTP_NOT_FOUND);
2026-07-31 17:41:55 +03:00
$collection = $product['collections'][0] ?? null;
2026-07-31 17:41:55 +03:00
$variantsData = $this->products->variantSummaries($product);
2026-07-31 17:41:55 +03:00
$firstVariant = $product['variants'][0] ?? null;
$option = $firstVariant['options'][0]['option'] ?? null;
2026-07-31 17:41:55 +03:00
return view('product.show', [
'collection' => $collection,
'product' => $product,
'option' => $option,
'variantsData' => $variantsData,
2026-07-31 17:41:55 +03:00
]);
}
}