generated from boboko/starter
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Lunar\Models\Collection;
|
|
use Modules\Core\Catalog\DTOs\ProductFilters;
|
|
use Modules\Core\Catalog\Services\ProductService;
|
|
|
|
class CategoryController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ProductService $products,
|
|
) {}
|
|
|
|
public function show(string $locale, Collection $collection)
|
|
{
|
|
$perPage = 12;
|
|
$page = (int) request('page', 1);
|
|
|
|
// Listing/filtering reads from the Meilisearch index via ProductService,
|
|
// not Eloquent — see Modules\Core\Catalog\Services\ProductService. list() returns a
|
|
// real LengthAwarePaginator of plain arrays (already localized/flattened),
|
|
// not Product models.
|
|
$products = $this->products->list(
|
|
filters: new ProductFilters(collectionId: $collection->id),
|
|
perPage: $perPage,
|
|
page: $page,
|
|
)->through(fn (array $product) => [
|
|
'name' => $product['name'],
|
|
'price' => $product['price'],
|
|
'image' => $product['media'][0]['url'] ?? null,
|
|
'href' => route('product.show', ['id' => $product['id']]),
|
|
]);
|
|
|
|
return view('category.show', [
|
|
'collection' => $collection,
|
|
'products' => $products,
|
|
]);
|
|
}
|
|
}
|