2026-08-26 13:43:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2026-08-31 22:56:40 +03:00
|
|
|
use App\Catalog\CategoryListing;
|
2026-09-03 11:47:38 +03:00
|
|
|
use App\Catalog\ProductCard;
|
2026-08-29 00:17:34 +03:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Modules\Core\Catalog\Services\CollectionService;
|
2026-08-27 11:46:33 +03:00
|
|
|
use Modules\Core\Catalog\Services\ProductService;
|
2026-08-26 13:43:30 +03:00
|
|
|
|
|
|
|
|
class CategoryController extends Controller
|
|
|
|
|
{
|
2026-08-26 18:28:16 +03:00
|
|
|
public function __construct(
|
|
|
|
|
private readonly ProductService $products,
|
2026-08-29 00:17:34 +03:00
|
|
|
private readonly CollectionService $collections,
|
2026-08-26 18:28:16 +03:00
|
|
|
) {}
|
|
|
|
|
|
2026-08-29 00:17:34 +03:00
|
|
|
public function show(string $locale, int $collection)
|
2026-08-26 13:43:30 +03:00
|
|
|
{
|
2026-08-29 00:17:34 +03:00
|
|
|
$collectionData = $this->collections->getById($collection);
|
|
|
|
|
abort_if($collectionData === null, Response::HTTP_NOT_FOUND);
|
|
|
|
|
|
2026-08-31 22:56:40 +03:00
|
|
|
$listing = CategoryListing::fromRequest(request());
|
|
|
|
|
$filters = $listing->filters($collectionData['id']);
|
2026-08-26 18:28:16 +03:00
|
|
|
$perPage = 12;
|
|
|
|
|
|
2026-09-03 11:47:38 +03:00
|
|
|
// One call for both the product page and the price slider's bounds —
|
|
|
|
|
// see ProductService::list()'s own docblock for why a controller no
|
|
|
|
|
// longer orchestrates list() + priceSliderBounds() itself.
|
|
|
|
|
$listingResult = $this->products->list(
|
2026-08-31 22:56:40 +03:00
|
|
|
filters: $filters,
|
2026-08-26 18:28:16 +03:00
|
|
|
perPage: $perPage,
|
2026-08-31 22:56:40 +03:00
|
|
|
page: $listing->page,
|
|
|
|
|
sort: $listing->sort,
|
2026-09-03 11:47:38 +03:00
|
|
|
);
|
2026-08-31 22:56:40 +03:00
|
|
|
|
2026-09-03 11:47:38 +03:00
|
|
|
$products = $listingResult->products
|
|
|
|
|
->through(fn (array $product) => ProductCard::fromIndexed($product))
|
|
|
|
|
->appends($listing->query(['page' => null]));
|
2026-08-31 22:56:40 +03:00
|
|
|
|
2026-09-03 11:47:38 +03:00
|
|
|
$priceBounds = $listingResult->priceBounds;
|
2026-08-26 13:43:30 +03:00
|
|
|
|
|
|
|
|
return view('category.show', [
|
2026-08-29 00:17:34 +03:00
|
|
|
'collection' => $collectionData,
|
2026-08-26 13:43:30 +03:00
|
|
|
'products' => $products,
|
2026-08-31 22:56:40 +03:00
|
|
|
'listing' => $listing,
|
2026-09-03 11:47:38 +03:00
|
|
|
'priceFloor' => $priceBounds->floor,
|
|
|
|
|
'priceCeil' => $priceBounds->ceil,
|
|
|
|
|
'priceFiltered' => $priceBounds->filtered,
|
2026-08-26 13:43:30 +03:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|