10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserHistory;
|
||||
use App\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
|
@ -21,7 +23,7 @@ class Util
|
|||
$uuid = (string) Str::uuid();
|
||||
$e_uuid = explode('-', $uuid);
|
||||
if (isset($e_uuid[0]) && $e_uuid[1]) {
|
||||
return $e_uuid[0] . '-' . $e_uuid[1];
|
||||
return $e_uuid[0].'-'.$e_uuid[1];
|
||||
}
|
||||
|
||||
return $uuid;
|
||||
|
|
@ -76,7 +78,7 @@ class Util
|
|||
if (strlen($str) > $length) {
|
||||
$str = substr($str, 0, $length);
|
||||
// $str = substr($str, 0, strrpos($str, " "));
|
||||
$str = $str . ' ...';
|
||||
$str = $str.' ...';
|
||||
}
|
||||
|
||||
return $str;
|
||||
|
|
@ -329,9 +331,9 @@ class Util
|
|||
public static function getMyMivitaShopUrl($add_url = '')
|
||||
{
|
||||
if (\Session::has('user_shop_domain')) {
|
||||
$url = \Session::get('user_shop_domain') . $add_url;
|
||||
$url = \Session::get('user_shop_domain').$add_url;
|
||||
if (! str_starts_with($url, 'http')) {
|
||||
$url = 'https://' . ltrim($url, '/');
|
||||
$url = 'https://'.ltrim($url, '/');
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
|
@ -339,22 +341,124 @@ class Util
|
|||
// alois sein shop
|
||||
$user = \App\User::find(6);
|
||||
if ($user && $user->shop) {
|
||||
return config('app.protocol') . $user->shop->slug . '.' . config('app.domain') . config('app.tld_care') . $add_url;
|
||||
return config('app.protocol').$user->shop->slug.'.'.config('app.domain').config('app.tld_care').$add_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vollständige URL zum Warenkorb (User-Shop) nach „Nachbestellen“ im Portal.
|
||||
* Verhindert Weiterleitung auf Portal/CRM/Checkout, wo /user/card/show nicht existiert (404).
|
||||
*/
|
||||
public static function getCustomerReorderCartUrl(?ShoppingOrder $shoppingOrder = null): string
|
||||
{
|
||||
$cartPath = '/user/card/show';
|
||||
$candidates = [];
|
||||
|
||||
if ($shoppingOrder?->member?->shop) {
|
||||
$candidates[] = config('app.protocol').$shoppingOrder->member->shop->slug.'.'.config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
if (\Auth::guard('customers')->check()) {
|
||||
$stored = \Auth::guard('customers')->user()->user_shop_domain;
|
||||
if ($stored) {
|
||||
$candidates[] = $stored;
|
||||
}
|
||||
}
|
||||
|
||||
if (\Session::has('user_shop_domain')) {
|
||||
$candidates[] = \Session::get('user_shop_domain');
|
||||
}
|
||||
|
||||
$user = User::find(6);
|
||||
if ($user?->shop) {
|
||||
$candidates[] = config('app.protocol').$user->shop->slug.'.'.config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
$defaultSlug = config('domains.domains.shop.default_user_shop', 'aloevera');
|
||||
$candidates[] = config('app.protocol').$defaultSlug.'.'.config('app.domain').config('app.tld_care');
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
$normalized = self::normalizeShopBaseUrl($candidate);
|
||||
if ($normalized === null || self::isShopBaseUrlInvalidForUserCard($normalized)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $normalized.$cartPath;
|
||||
}
|
||||
|
||||
return config('domains.protocol').config('domains.domains.shop.host').$cartPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Portal, CRM und Checkout hosten keine User-Shop-Warenkorb-Route unter /user/card/show.
|
||||
*/
|
||||
public static function isShopBaseUrlInvalidForUserCard(?string $baseUrl): bool
|
||||
{
|
||||
if ($baseUrl === null || $baseUrl === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$host = self::extractHostFromUrl($baseUrl);
|
||||
if ($host === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$host = strtolower($host);
|
||||
|
||||
$invalidHosts = array_filter([
|
||||
config('domains.domains.portal.host'),
|
||||
config('domains.domains.crm.host'),
|
||||
config('domains.domains.checkout.host'),
|
||||
]);
|
||||
|
||||
foreach ($invalidHosts as $invalid) {
|
||||
if ($invalid !== null && $invalid !== '' && strtolower($invalid) === $host) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function normalizeShopBaseUrl(?string $url): ?string
|
||||
{
|
||||
if ($url === null || trim($url) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$u = trim($url);
|
||||
if (! str_starts_with($u, 'http')) {
|
||||
$u = 'https://'.ltrim($u, '/');
|
||||
}
|
||||
|
||||
return rtrim($u, '/');
|
||||
}
|
||||
|
||||
private static function extractHostFromUrl(string $url): ?string
|
||||
{
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (! empty($host)) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
$stripped = preg_replace('#^https?://#i', '', $url);
|
||||
$parts = explode('/', $stripped, 2);
|
||||
|
||||
return $parts[0] !== '' ? $parts[0] : null;
|
||||
}
|
||||
|
||||
public static function getMyMivitaPortalUrl($protocol = true)
|
||||
{
|
||||
$pro = $protocol ? config('app.protocol') : '';
|
||||
|
||||
return $pro . config('app.pre_url_portal') . config('app.domain') . config('app.tld_care');
|
||||
return $pro.config('app.pre_url_portal').config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
public static function getMyMivitaUrl($protocol = true)
|
||||
{
|
||||
$pro = $protocol ? config('app.protocol') : '';
|
||||
|
||||
return $pro . config('app.pre_url_crm') . config('app.domain') . config('app.tld_care');
|
||||
return $pro.config('app.pre_url_crm').config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
public static function getUserPaymentFor($instance = 'shopping')
|
||||
|
|
@ -377,11 +481,11 @@ class Util
|
|||
return \Session::get('user_shop_domain');
|
||||
}
|
||||
if ($user_shop = \Session::get('user_shop')) {
|
||||
return config('app.protocol') . $user_shop->slug . '.' . config('app.domain') . config('app.tld_care') . '/back/to/shop/' . $reference;
|
||||
return config('app.protocol').$user_shop->slug.'.'.config('app.domain').config('app.tld_care').'/back/to/shop/'.$reference;
|
||||
}
|
||||
}
|
||||
|
||||
return config('app.protocol') . config('app.domain') . config('app.tld_care');
|
||||
return config('app.protocol').config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
public static function getUserCardBackUrl($uri, $instance = 'shopping')
|
||||
|
|
@ -393,36 +497,36 @@ class Util
|
|||
return \Session::get('back_link');
|
||||
}
|
||||
if (self::getUserPaymentFor($instance) === 3) {
|
||||
return \Session::get('user_shop_domain') . '/user/membership';
|
||||
return \Session::get('user_shop_domain').'/user/membership';
|
||||
}
|
||||
if (self::getUserPaymentFor($instance) === 2) {
|
||||
return \Session::get('user_shop_domain') . '/user/orders';
|
||||
return \Session::get('user_shop_domain').'/user/orders';
|
||||
}
|
||||
|
||||
return \Session::get('user_shop_domain');
|
||||
}
|
||||
if ($user_shop = \Session::get('user_shop')) {
|
||||
return config('app.protocol') . $user_shop->slug . '.' . config('app.domain') . config('app.tld_care') . $uri;
|
||||
return config('app.protocol').$user_shop->slug.'.'.config('app.domain').config('app.tld_care').$uri;
|
||||
}
|
||||
}
|
||||
|
||||
return config('app.protocol') . config('app.domain') . config('app.tld_care');
|
||||
return config('app.protocol').config('app.domain').config('app.tld_care');
|
||||
}
|
||||
|
||||
public static function isMivitaShop()
|
||||
{
|
||||
if (Request::getHost() === 'checkout.' . config('app.domain') . config('app.tld_care')) {
|
||||
if (Request::getHost() === 'checkout.'.config('app.domain').config('app.tld_care')) {
|
||||
if ($user_shop = \Session::get('user_shop')) {
|
||||
if ($user_shop->slug === 'aloevera' || $user_shop->slug === 'naturcosmetic') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Request::getHost() === 'naturcosmetic.' . config('app.domain') . config('app.tld_care')) {
|
||||
if (Request::getHost() === 'naturcosmetic.'.config('app.domain').config('app.tld_care')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return \Config::get('app.url') === config('app.domain') . config('app.tld_shop');
|
||||
return \Config::get('app.url') === config('app.domain').config('app.tld_shop');
|
||||
}
|
||||
|
||||
public static function isTestSystem($dev = false)
|
||||
|
|
@ -445,7 +549,7 @@ class Util
|
|||
$base = log($size) / log(1024);
|
||||
$suffixes = [' bytes', ' KB', ' MB', ' GB', ' TB'];
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
return round(pow(1024, $base - floor($base)), $precision).$suffixes[floor($base)];
|
||||
} else {
|
||||
return $size;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue