localization from boboko core and product service too

This commit is contained in:
elvira
2026-08-26 18:28:16 +03:00
parent 092fab8740
commit 90e32e337d
15 changed files with 374 additions and 169 deletions
+34 -12
View File
@@ -2,24 +2,46 @@
namespace App\Http\Controllers;
use Illuminate\Pagination\LengthAwarePaginator;
use Lunar\Models\Collection;
use Lunar\Models\Product;
use Modules\Core\Catalog\ProductFilters;
use Modules\Core\Catalog\ProductService;
class CategoryController extends Controller
{
public function __construct(
private readonly ProductService $products,
) {}
public function show(string $locale, Collection $collection)
{
$products = $collection
->products()
->with(['variants.prices.currency', 'media'])
->paginate(12)
->withQueryString()
->through(fn (Product $product) => [
'name' => $product->translateAttribute('name'),
'price' => $product->variants->first()?->prices->first()?->price->decimal,
'image' => $product->media->first()?->getUrl(),
'href' => route('product.show', ['product' => $product]),
]);
$perPage = 12;
$page = (int) request('page', 1);
// Listing/filtering reads from the Meilisearch index via ProductService,
// not Eloquent — see Modules\Core\Catalog\ProductService. It returns plain
// arrays (already localized/flattened), not Product models.
$result = $this->products->list(
filters: new ProductFilters(collectionId: $collection->id),
perPage: $perPage,
page: $page,
);
$products = new LengthAwarePaginator(
items: collect($result['data'])->map(fn (array $product) => [
'name' => $product['name'],
'price' => $product['price'],
'image' => $product['media'][0]['url'] ?? null,
'href' => route('product.show', ['product' => $product['id']]),
]),
total: $result['meta']['total'],
perPage: $result['meta']['per_page'],
currentPage: $result['meta']['current_page'],
options: [
'path' => request()->url(),
'query' => request()->query(),
],
);
return view('category.show', [
'collection' => $collection,