239 lines
10 KiB
PHP
Executable file
239 lines
10 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
|
|
use Yard;
|
|
use Request;
|
|
use App\Models\IqSite;
|
|
use App\Services\Shop;
|
|
use App\Services\Util;
|
|
use App\Models\Product;
|
|
use App\Models\Category;
|
|
use App\Models\ProductCategory;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class SiteController extends Controller
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
// GPT-5 v3.1: Optimiertes Session-Debug-Logging
|
|
if (config('app.debug')) {
|
|
\Log::info('SiteController: index() - GPT-5 v3.1 Session Status', [
|
|
'session_id' => \Session::getId(),
|
|
'user_shop_id' => session('shop.id'),
|
|
'user_shop_slug' => session('shop.slug'),
|
|
'user_init_country' => session('user_init_country'),
|
|
'locale' => session('locale'),
|
|
'request_host' => request()->getHost(),
|
|
'domain_context' => request()->attributes->get('domain_context')?->type,
|
|
'gpt5_v3_status' => 'active'
|
|
]);
|
|
}
|
|
|
|
$this->setIPInfo();
|
|
$products = ['aloe-vera-gel-99', 'aloe-vera-saft-500-ml', 'aloe-vera-lippenbalsam'];
|
|
// $set_products = ['aloe-vera-cleaner-set', 'aloe-vera-koerper-set', 'aloe-vera-repair-set'];
|
|
$set_products = ['aloe-vera-koerper-set', 'baby-set', 'aloe-vera-gel-set'];
|
|
$data = [
|
|
'products' => Product::whereIn('slug', $products)->where('active', true)->whereJsonContains('show_on', '1')->get(),
|
|
'set_products' => Product::whereIn('slug', $set_products)->where('active', true)->whereJsonContains('show_on', '1')->get(),
|
|
'user_shop' => Util::getUserShop(),
|
|
'mylangs' => Shop::getLangChange('webshop'),
|
|
'site' => IqSite::find(1),
|
|
'yard_instance' => 'webshop',
|
|
];
|
|
|
|
return view('web.index', $data);
|
|
}
|
|
|
|
public function domainCheck()
|
|
{
|
|
die("checked");
|
|
}
|
|
|
|
public function changeLang()
|
|
{
|
|
$data = Request::all();
|
|
|
|
if (isset($data['change_country_id'])) {
|
|
$mylangs = Shop::getLangChange('webshop');
|
|
|
|
foreach ($mylangs as $code => $country) {
|
|
if (strtolower($data['change_country_id']) === strtolower($code)) {
|
|
$countryCode = strtolower($code); //lieferland
|
|
$localeCode = strtolower($data['change_locale_id'] ?? $countryCode); //sprache
|
|
|
|
// Optimierte Session-Schreibvorgänge
|
|
\Session::put('user_init_country', $countryCode); //lieferland
|
|
\Session::forget('user_init_country_options'); // Land löschen, da es vom User gesetzt wurde
|
|
\Session::put('locale', $localeCode); //sprache
|
|
|
|
|
|
// Sprache für Laravel setzen
|
|
\App::setLocale($localeCode);
|
|
// UserShop-Sprache initialisieren für Checkout
|
|
Shop::initUserShopLang($country, 'webshop');
|
|
|
|
// Session bereinigen und speichern (wichtig für Domain-Wechsel)
|
|
\App\Services\SessionCleaner::cleanAndSave('SiteController::changeLang');
|
|
|
|
// Debug-Logging für changeLang
|
|
if (config('app.debug')) {
|
|
\Log::info('SiteController: changeLang() - Sprache/Land geändert', [
|
|
'country_code' => $countryCode,
|
|
'locale_code' => $localeCode,
|
|
'session_id' => \Session::getId(),
|
|
'user_shop_id' => session('shop.id'),
|
|
'checkout_ready' => true,
|
|
'request_host' => request()->getHost()
|
|
]);
|
|
}
|
|
|
|
return back();
|
|
}
|
|
}
|
|
}
|
|
|
|
return back()->withError('Ungültiges Land/Sprache ausgewählt');
|
|
}
|
|
|
|
private function setIPInfo()
|
|
{
|
|
// GPT-5 v3.1: Cache-Check - wurde schon gesetzt?
|
|
if (\Session::has('user_init_country')) {
|
|
return;
|
|
}
|
|
|
|
$country = 'de'; // Default-Wert für DACH-Region
|
|
|
|
// IP-basierte Länder-Erkennung
|
|
if (config('app.ipinfo')) {
|
|
$ipCountry = strtolower(Shop::getIPDatabaseInfo());
|
|
if ($ipCountry === 'error') {
|
|
$country = 'de'; // Fallback bei IP-Service-Fehlern
|
|
} else {
|
|
$country = $ipCountry;
|
|
}
|
|
}
|
|
|
|
// Sprache setzen (mit Validation)
|
|
if (array_key_exists($country, \App\Services\UserService::getTransChange())) {
|
|
\Session::put('user_init_country', $country);
|
|
\Session::put('locale', $country);
|
|
\App::setLocale($country);
|
|
} else {
|
|
// Default: Deutschland
|
|
\Session::put('user_init_country', 'de');
|
|
\Session::put('locale', 'de');
|
|
\App::setLocale('de');
|
|
$country = 'de'; // Für nachfolgende Logik
|
|
}
|
|
|
|
// Option für den Init setzen, hier wird das Lieferland für die Auswahl im Sidepanel gesetzt
|
|
if (array_key_exists($country, Shop::getLangChange('webshop'))) {
|
|
\Session::put('user_init_country_options', $country);
|
|
} else {
|
|
\Session::put('user_init_country_options', 'de');
|
|
}
|
|
|
|
// GPT-5 v3.1: Session bereinigen und speichern für Domain-Wechsel-Stabilität
|
|
\App\Services\SessionCleaner::cleanAndSave('SiteController::setIPInfo');
|
|
|
|
// GPT-5 v3.1: Optimiertes Debug-Logging
|
|
if (config('app.debug')) {
|
|
\Log::info('SiteController: setIPInfo() - Länder/Sprache initialisiert', [
|
|
'detected_country' => $country,
|
|
'user_init_country' => \Session::get('user_init_country'),
|
|
'locale' => \Session::get('locale'),
|
|
'delivery_country' => \Session::get('user_init_country_options'),
|
|
'session_id' => \Session::getId(),
|
|
'user_shop_id' => session('shop.id'),
|
|
'user_shop_slug' => session('shop.slug'),
|
|
'checkout_ready' => true,
|
|
'ip_detection' => config('app.ipinfo') ? 'enabled' : 'disabled'
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function site($site, $subsite = false, $product_slug = false)
|
|
{
|
|
$this->setIPInfo();
|
|
$subsite = trim($subsite, '/');
|
|
$product_slug = trim($product_slug, '/');
|
|
if ($product_slug) {
|
|
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
|
$product = Product::where('slug', $product_slug)->where('active', true)->whereJsonContains('show_on', '1')->first();
|
|
if ($category && $product) {
|
|
$data = [
|
|
'user_shop' => Util::getUserShop(),
|
|
'mylangs' => Shop::getLangChange('webshop'),
|
|
'subsite' => $subsite,
|
|
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
|
|
'product' => $product,
|
|
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
|
'yard_instance' => 'webshop',
|
|
];
|
|
return view('web.templates.produkte-show', $data);
|
|
}
|
|
}
|
|
if ($site == 'produkte') {
|
|
if ($subsite && $subsite !== 'alle-produkte') {
|
|
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
|
if ($category) {
|
|
$headline_image = false;
|
|
if ($category->headline_image_id && $category->iq_image && $category->iq_image->active) {
|
|
$headline_image = $category->iq_image;
|
|
}
|
|
|
|
$product_categories = ProductCategory::where('category_id', $category->id)->whereHas('product', function ($query) use ($category) {
|
|
$query->where('active', true)->whereJsonContains('show_on', '1');
|
|
})->orderBy('pos', 'DESC')->get();
|
|
|
|
$data = [
|
|
'user_shop' => Util::getUserShop(),
|
|
'mylangs' => Shop::getLangChange('webshop'),
|
|
'subsite' => $subsite,
|
|
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
|
'products' => false,
|
|
'product_categories' => $product_categories,
|
|
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
|
'headline' => $category->getLang('headline'),
|
|
'headline_image' => $headline_image,
|
|
'yard_instance' => 'webshop',
|
|
];
|
|
return view('web.templates.' . $site, $data);
|
|
}
|
|
}
|
|
$data = [
|
|
'user_shop' => Util::getUserShop(),
|
|
'mylangs' => Shop::getLangChange('webshop'),
|
|
'subsite' => 'alle-produkte',
|
|
'categories' => Category::where('active', true)->orderBy('pos', 'DESC')->get(),
|
|
'products' => Product::where('active', true)->whereJsonContains('show_on', '1')->orderBy('pos', 'DESC')->get(),
|
|
'product_categories' => false,
|
|
'p_count' => Product::where('active', true)->whereJsonContains('show_on', '1')->count(),
|
|
'headline' => __('website.productworld'),
|
|
'headline_image' => false,
|
|
'yard_instance' => 'webshop',
|
|
];
|
|
return view('web.templates.' . $site, $data);
|
|
}
|
|
$data = [
|
|
'user_shop' => Util::getUserShop(),
|
|
'mylangs' => Shop::getLangChange('webshop'),
|
|
'yard_instance' => 'webshop',
|
|
];
|
|
if ($subsite) {
|
|
if (!view()->exists('web.templates.' . $subsite)) {
|
|
abort(404);
|
|
}
|
|
return view('web.templates.' . $subsite, $data);
|
|
}
|
|
if (!view()->exists('web.templates.' . $site)) {
|
|
abort(404);
|
|
}
|
|
return view('web.templates.' . $site, $data);
|
|
}
|
|
}
|