diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 2fc2227..dae9b4a 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -2,18 +2,23 @@ namespace App\Http\Controllers; -use Lunar\Models\Collection; +use Illuminate\Http\Response; use Modules\Core\Catalog\DTOs\ProductFilters; +use Modules\Core\Catalog\Services\CollectionService; use Modules\Core\Catalog\Services\ProductService; class CategoryController extends Controller { public function __construct( private readonly ProductService $products, + private readonly CollectionService $collections, ) {} - public function show(string $locale, Collection $collection) + public function show(string $locale, int $collection) { + $collectionData = $this->collections->getById($collection); + abort_if($collectionData === null, Response::HTTP_NOT_FOUND); + $perPage = 12; $page = (int) request('page', 1); @@ -22,7 +27,7 @@ public function show(string $locale, Collection $collection) // real LengthAwarePaginator of plain arrays (already localized/flattened), // not Product models. $products = $this->products->list( - filters: new ProductFilters(collectionId: $collection->id), + filters: new ProductFilters(collectionId: $collectionData['id']), perPage: $perPage, page: $page, )->through(fn (array $product) => [ @@ -33,7 +38,7 @@ public function show(string $locale, Collection $collection) ]); return view('category.show', [ - 'collection' => $collection, + 'collection' => $collectionData, 'products' => $products, ]); } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 14a0b27..b468bf9 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers; use Illuminate\Http\Response; -use Lunar\Models\Collection; use Modules\Core\Catalog\Services\ProductService; class ProductController extends Controller @@ -16,7 +15,6 @@ public function show(string $locale, int $id) abort_if($product === null, Response::HTTP_NOT_FOUND); $collection = $product['collections'][0] ?? null; - $collectionModel = $collection !== null ? Collection::find($collection['id']) : null; $variantsData = collect($product['variants']) ->map(fn (array $variant) => [ @@ -30,12 +28,8 @@ public function show(string $locale, int $id) $firstVariant = $product['variants'][0] ?? null; $option = $firstVariant['options'][0]['option'] ?? null; - // temp categories here - $categories = Collection::orderBy('_lft')->get(); - return view('product.show', [ - 'categories' => $categories, - 'collection' => $collectionModel, + 'collection' => $collection, 'product' => $product, 'option' => $option, 'variantsData' => $variantsData, diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 85bd5ff..c31fa40 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -6,9 +6,14 @@ use App\Models\Staff; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\URL; +use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; +use Illuminate\View\View as ViewInstance; use Lunar\Facades\ModelManifest; use Lunar\Facades\Telemetry; +use Modules\Core\Catalog\DTOs\CollectionFilters; +use Modules\Core\Catalog\Enums\CollectionSort; +use Modules\Core\Catalog\Services\CollectionService; class AppServiceProvider extends ServiceProvider { @@ -16,6 +21,17 @@ public function boot(): void { Telemetry::optOut(); + // header.blade.php's category dropdown — root collections only, resolved + // per-request so the composer runs after `locale` middleware has already + // set App::getLocale(), which CollectionService's name resolution depends on. + View::composer('components.header', function (ViewInstance $view) { + $view->with('categories', app(CollectionService::class)->list( + filters: new CollectionFilters(rootOnly: true), + perPage: 100, + sort: CollectionSort::Position, + )->items()); + }); + if ($this->app->environment('production')) { URL::forceScheme('https'); } diff --git a/config/lunar/cart.php b/config/lunar/cart.php index f9f77b8..92c113f 100644 --- a/config/lunar/cart.php +++ b/config/lunar/cart.php @@ -54,6 +54,7 @@ */ 'cart_lines' => [ Lunar\Pipelines\CartLine\GetUnitPrice::class, + Modules\Core\Cart\Pipelines\ZeroSavedForLaterPrice::class, ], ], diff --git a/config/lunar/cart_session.php b/config/lunar/cart_session.php index 3fd80bb..8b4d10a 100644 --- a/config/lunar/cart_session.php +++ b/config/lunar/cart_session.php @@ -44,5 +44,5 @@ | Determines whether the cart sholud be soft deleted when the user logs out. | */ - 'delete_on_forget' => true, + 'delete_on_forget' => false, ]; diff --git a/resources/views/category/show.blade.php b/resources/views/category/show.blade.php index 06cf2cf..705dd99 100644 --- a/resources/views/category/show.blade.php +++ b/resources/views/category/show.blade.php @@ -1,17 +1,17 @@ @extends('layouts.app') -@section('title', $collection->translateAttribute('name') . ' — ' . config('app.name')) -@section('description', strip_tags($collection->translateAttribute('description') ?? '')) +@section('title', $collection['name'] . ' — ' . config('app.name')) +@section('description', strip_tags($collection['description'] ?? '')) @section('content')