2026-07-31 17:41:55 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-09-03 16:28:10 +03:00
|
|
|
use App\Catalog\ProductListing;
|
|
|
|
|
use App\Catalog\ProductListingPage;
|
2026-08-27 00:55:56 +03:00
|
|
|
use Illuminate\Http\Response;
|
2026-08-27 11:46:33 +03:00
|
|
|
use Modules\Core\Catalog\Services\ProductService;
|
2026-07-31 17:41:55 +03:00
|
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
2026-09-03 16:28:10 +03:00
|
|
|
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);
|
|
|
|
|
}
|
2026-08-27 00:55:56 +03:00
|
|
|
|
|
|
|
|
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;
|
2026-07-31 17:41:55 +03:00
|
|
|
|
2026-09-03 11:47:38 +03:00
|
|
|
$variantsData = $this->products->variantSummaries($product);
|
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
|
|
|
|
2026-08-27 00:55:56 +03:00
|
|
|
return view('product.show', [
|
2026-08-29 00:17:34 +03:00
|
|
|
'collection' => $collection,
|
2026-08-27 00:55:56 +03:00
|
|
|
'product' => $product,
|
|
|
|
|
'option' => $option,
|
|
|
|
|
'variantsData' => $variantsData,
|
2026-07-31 17:41:55 +03:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|