Files
3dealer/app/Providers/CheckoutModuleServiceProvider.php
T

54 lines
2.2 KiB
PHP
Raw Normal View History

2026-09-04 19:39:37 +03:00
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View as ViewInstance;
use Modules\Core\Cart\Services\CartService;
/**
* The seam for the (currently in-repo) cart + checkout module.
*
* Everything the module needs to boot inside a host app lives here: its view /
* component namespaces, its routes, and the composer that feeds the
* always-present cart drawer. Strings (__('checkout.cart.*')) are NOT wired up
* here — same as storefront.* elsewhere in this app, they resolve through
* Lunar's DB-backed translation UI (spatie/laravel-translation-loader), added
* manually there rather than shipped as lang/ files. The module's own files
* (resources/views/checkout/**, resources/js/checkout/**, resources/css/checkout.css,
* routes/checkout.php, app/Http/Controllers/Checkout/**) contain nothing
* 3dealer-specific.
*
* When the module is extracted to boboko-core, this class is deleted and its
* body becomes the package's own ServiceProvider. The only other host wiring
* is the one registerCheckout() call in resources/js/app.js and the two lines
* in the layout (the checkout.css @vite entry and @include('checkout::drawer')).
*/
class CheckoutModuleServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->loadViewsFrom(resource_path('views/checkout'), 'checkout');
Blade::anonymousComponentNamespace('checkout::components', 'checkout');
Route::middleware('web')->group(base_path('routes/checkout.php'));
// The drawer is rendered on every page (from the layout) and its body
// partial is re-rendered on every cart mutation — both need the current
// cart without a controller in the loop.
View::composer(
['checkout::drawer', 'checkout::partials.cart-body'],
function (ViewInstance $view) {
$service = app(CartService::class);
$cart = $service->current();
$view->with('cart', $cart);
$view->with('lines', $cart ? $service->activeLines($cart) : collect());
},
);
}
}