2026-07-03 13:46:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\Staff;
|
2026-09-28 17:09:04 +03:00
|
|
|
use App\Services\StoicSettings;
|
2026-07-03 13:46:54 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2026-09-28 19:42:35 +03:00
|
|
|
use Illuminate\Mail\Events\MessageSending;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
2026-07-03 13:46:54 +00:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2026-08-29 00:17:34 +03:00
|
|
|
use Illuminate\Support\Facades\View;
|
2026-07-03 13:46:54 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2026-08-29 00:17:34 +03:00
|
|
|
use Illuminate\View\View as ViewInstance;
|
2026-07-03 13:46:54 +00:00
|
|
|
use Lunar\Facades\ModelManifest;
|
|
|
|
|
use Lunar\Facades\Telemetry;
|
2026-09-28 19:42:35 +03:00
|
|
|
use Lunar\Models\CollectionGroup;
|
2026-08-29 00:17:34 +03:00
|
|
|
use Modules\Core\Catalog\DTOs\CollectionFilters;
|
|
|
|
|
use Modules\Core\Catalog\Enums\CollectionSort;
|
|
|
|
|
use Modules\Core\Catalog\Services\CollectionService;
|
2026-09-28 19:42:35 +03:00
|
|
|
use Modules\Core\Store\Services\StoreDetailsService;
|
|
|
|
|
use Symfony\Component\Mime\Address;
|
2026-07-03 13:46:54 +00:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2026-09-28 17:09:04 +03:00
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
$this->app->scoped(StoicSettings::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 13:46:54 +00:00
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
Telemetry::optOut();
|
|
|
|
|
|
2026-09-28 19:42:35 +03:00
|
|
|
// header.blade.php's category dropdown — root collections of the catalog
|
|
|
|
|
// group only, so merchandising groups (e.g. "Homepage") stay out of the
|
|
|
|
|
// nav. Resolved per-request so the composer runs after `locale` middleware
|
|
|
|
|
// has already set App::getLocale(), which CollectionService's name
|
|
|
|
|
// resolution depends on. The group is looked up by handle, not id, since
|
|
|
|
|
// ids can differ between environments.
|
2026-08-29 00:17:34 +03:00
|
|
|
View::composer('components.header', function (ViewInstance $view) {
|
2026-09-28 19:42:35 +03:00
|
|
|
$groupId = CollectionGroup::where('handle', 'shopify')->value('id');
|
|
|
|
|
|
|
|
|
|
$view->with('categories', $groupId === null ? [] : app(CollectionService::class)->list(
|
|
|
|
|
filters: new CollectionFilters(groupId: $groupId, rootOnly: true),
|
2026-08-29 00:17:34 +03:00
|
|
|
perPage: 100,
|
|
|
|
|
sort: CollectionSort::Position,
|
|
|
|
|
)->items());
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-28 17:09:04 +03:00
|
|
|
// Site-wide settings edited in Stoic (settings.md): default meta
|
|
|
|
|
// description, social links for the footer, emails and schema.org.
|
|
|
|
|
View::composer(
|
|
|
|
|
['layouts.app', 'components.footer', 'emails.layout', 'home'],
|
|
|
|
|
fn (ViewInstance $view) => $view->with('stoicSettings', app(StoicSettings::class)),
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-28 19:42:35 +03:00
|
|
|
// INTERIM, belongs in boboko-core's Store module: the sender name on
|
|
|
|
|
// outgoing emails comes from Store Details' "Mail from name", with
|
|
|
|
|
// MAIL_FROM_NAME as the fallback when it's empty. Done per message
|
|
|
|
|
// rather than by setting config at boot, so a long-running queue
|
|
|
|
|
// worker picks up a changed name without a restart. Only the default
|
|
|
|
|
// from address is renamed; a mailable with its own from is left alone.
|
|
|
|
|
Event::listen(MessageSending::class, function (MessageSending $event) {
|
|
|
|
|
$name = app(StoreDetailsService::class)->current()->mail_from_name;
|
|
|
|
|
|
|
|
|
|
if (blank($name)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$defaultAddress = config('mail.from.address');
|
|
|
|
|
|
|
|
|
|
$event->message->from(...array_map(
|
|
|
|
|
fn (Address $from) => $from->getAddress() === $defaultAddress
|
|
|
|
|
? new Address($from->getAddress(), $name)
|
|
|
|
|
: $from,
|
|
|
|
|
$event->message->getFrom(),
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-03 13:46:54 +00:00
|
|
|
if ($this->app->environment('production')) {
|
|
|
|
|
URL::forceScheme('https');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->app->booted(function () {
|
|
|
|
|
ModelManifest::replace(
|
|
|
|
|
\Lunar\Models\Contracts\Customer::class,
|
|
|
|
|
Customer::class,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->app['config']->set(
|
|
|
|
|
'auth.providers.staff.model',
|
|
|
|
|
Staff::class,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Relation::morphMap([
|
|
|
|
|
'staff' => \Lunar\Admin\Models\Staff::class,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|