mivita/routes/shared/common.php
2025-08-12 18:01:59 +02:00

201 lines
8.7 KiB
PHP

<?php
/*
|--------------------------------------------------------------------------
| Geteilte Routen (Shared Routes)
|--------------------------------------------------------------------------
|
| Diese Routen sind auf allen Domains verfügbar, die die 'web' Middleware-Gruppe
| verwenden. Sie werden vom RouteServiceProvider geladen.
|
*/
// Rechtliche und Kontakt-Routen - Umleitung zur Shop-Domain für checkout.*
$context = app(\App\Domain\DomainContext::class);
if ($context->type === 'checkout') {
// Für Checkout-Domain: Umleitung zur Shop-Domain
Route::get('/datenschutz', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/datenschutz');
return redirect()->away($shopUrl);
})->name('legal.data-protected');
Route::get('/impressum', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/impressum');
return redirect()->away($shopUrl);
})->name('legal.imprint');
Route::get('/agb', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/agb');
return redirect()->away($shopUrl);
})->name('legal.agb');
Route::get('/kontakt', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/kontakt');
return redirect()->away($shopUrl);
})->name('contact.create');
Route::get('/zahlungsarten', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/zahlungsarten');
return redirect()->away($shopUrl);
})->name('zahlungsarten');
Route::get('/versandkosten', function () {
$domainService = app(\App\Services\DomainService::class);
$shopUrl = $domainService->buildUrl('main-shop', '/versandkosten');
return redirect()->away($shopUrl);
})->name('versandkosten');
} else {
// Für alle anderen Domains: normale Controller-Routen
Route::get('/datenschutz', 'HomeController@legalDataProtected')->name('legal.data-protected');
Route::get('/impressum', 'HomeController@legalImprint')->name('legal.imprint');
Route::get('/agb', 'HomeController@legalAGB')->name('legal.agb');
Route::get('/kontakt', 'Web\ContactController@create')->name('contact.create');
Route::post('/kontakt', 'Web\ContactController@store')->name('contact.store');
Route::get('/zahlungsarten', 'HomeController@zahlungsarten')->name('zahlungsarten');
Route::get('/versandkosten', 'HomeController@versandkosten')->name('versandkosten');
}
//debug subdomain
Route::get('/debug-subdomain', function () {
$domainContext = app(\App\Domain\DomainContext::class);
$domainService = app(\App\Services\DomainService::class);
return response()->json([
'host' => request()->getHost(),
'headers' => [
'X-Forwarded-Host' => request()->header('X-Forwarded-Host'),
'X-Subdomain' => request()->header('X-Subdomain'),
'Host' => request()->header('Host'),
],
'url' => request()->url(),
'full_url' => request()->fullUrl(),
'server' => [
'HTTP_HOST' => $_SERVER['HTTP_HOST'] ?? 'not set',
'SERVER_NAME' => $_SERVER['SERVER_NAME'] ?? 'not set',
],
'domain_context' => [
'type' => $domainContext->type,
'host' => $domainContext->host,
'subdomain' => $domainContext->subdomain,
'cloudflare_subdomain' => $domainContext->cloudflareSubdomain,
'effective_subdomain' => $domainContext->getEffectiveSubdomain(),
'is_cloudflare' => $domainContext->isCloudflareSubdomain(),
'is_user_shop' => $domainContext->isUserShop(),
'user_shop_slug' => $domainContext->getUserShopSlug(),
],
'parsed_domain' => $domainService->parseDomain(request()->getHost(), request()->header('X-Subdomain'))
]);
});
// Sprachwechsler
Route::post('/change_website_lang', 'Web\SiteController@changeLang')->name('language.change');
// Route für den Sprachwechsel (aus alter utility.php wiederhergestellt)
Route::get('translation/{locale}', function ($locale) {
app()->setLocale($locale);
session()->put('locale', $locale);
// Optional: Sprache für eingeloggte Benutzer speichern
if (auth()->guard('user')->check()) {
auth()->guard('user')->user()->update(['lang' => $locale]);
}
if (auth()->guard('customers')->check()) {
auth()->guard('customers')->user()->update(['language' => $locale]);
}
return redirect()->back();
})->name('translation');
// Bild-Routen (aus alter utility.php wiederhergestellt)
Route::get('/product/image/{slug}', function ($slug = null) {
if ($image = \App\Models\ProductImage::where('slug', 'like', $slug)->first()) {
$path = storage_path('app/public') . '/images/product' . '/' . $image->product_id . '/' . $image->filename;
if (file_exists($path)) {
return response()->file($path);
}
}
abort(404);
})->name('product_image');
Route::get('storage/images/{from}/{slug}', function ($from = null, $slug = null) {
if ($from == 'shop') {
if ($image = \App\Models\UserShop::where('filename', $slug)->first()) {
$path = storage_path('app/public') . '/images/shop' . '/' . $image->filename;
if (file_exists($path)) {
return Response::file($path);
}
}
}
})->name('storage_images');
Route::get('/iq/image/{slug}', function ($slug = null) {
if ($image = \App\Models\IqImage::where('slug', $slug)->first()) {
$path = storage_path('app/public') . '/images/iq_images/' . $image->filename;
if (file_exists($path)) {
return Response::file($path);
}
}
})->name('iq_image');
Route::get('/user_shop/image/{slug}', function ($slug = null) {
if ($image = \App\Models\UserShopOnSite::where('slug', $slug)->first()) {
$path = storage_path('app/public') . '/images/user_shop' . '/' . $image->user_shop_id . '/' . $image->filename;
if (file_exists($path)) {
return Response::file($path);
}
}
})->name('user_shop_image');
Route::get('/shop/product/image/{slug}', function ($slug = null) {
if ($image = \App\Models\ProductImage::where('slug', $slug)->first()) {
$path = storage_path('app/public') . '/images/product' . '/' . $image->product_id . '/' . $image->filename;
if (file_exists($path)) {
return Response::file($path);
}
}
})->name('shop_product_image');
// Alias für /home, damit auch /home erreichbar ist
// Checkout-Weiterleitung nur für Domains, die NICHT checkout.* sind
$context = app(\App\Domain\DomainContext::class);
if ($context->type !== 'checkout') {
Route::get('/checkout/card/{identifier?}', function ($identifier = null) {
$domainService = app(\App\Services\DomainService::class);
$checkoutUrl = $domainService->buildUrl('checkout', '/checkout/card/' . $identifier, null);
return redirect()->away($checkoutUrl);
})->name('checkout.checkout_card');
Route::post('/checkout/card/final', function () {
$domainService = app(\App\Services\DomainService::class);
$checkoutUrl = $domainService->buildUrl('checkout', '/checkout/card/final', null);
return redirect()->away($checkoutUrl);
})->name('checkout.checkout_card_final');
// Weiterleitung für Transaktionsstatus
Route::get('/transaction/status/{status?}/{reference?}', function ($status = null, $reference = null) {
$domainService = app(\App\Services\DomainService::class);
$checkoutUrl = $domainService->buildUrl('checkout', "/transaction/status/{$status}/{$reference}", null);
return redirect()->away($checkoutUrl);
})->name('checkout.transaction_status');
Route::post('/transaction/status/{status?}/{reference?}', function ($status = null, $reference = null) {
$domainService = app(\App\Services\DomainService::class);
$checkoutUrl = $domainService->buildUrl('checkout', "/transaction/status/{$status}/{$reference}", null);
return redirect()->away($checkoutUrl);
})->name('checkout.transaction_status_post');
Route::get('/transaction/approved/{transactionId}/{reference}', function ($transactionId, $reference) {
$domainService = app(\App\Services\DomainService::class);
$checkoutUrl = $domainService->buildUrl('checkout', "/transaction/approved/{$transactionId}/{$reference}", null);
return redirect()->away($checkoutUrl);
})->name('checkout.transaction_approved');
}