20-02-2026
This commit is contained in:
parent
a8b395e20d
commit
a00c42e770
252 changed files with 28785 additions and 8907 deletions
|
|
@ -2,24 +2,20 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use Yard;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Product;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAboOrder;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAboItem;
|
||||
use App\User;
|
||||
use Yard;
|
||||
|
||||
class AboOrderCart
|
||||
{
|
||||
private static $user_abo;
|
||||
private static $is_for;
|
||||
private static $customer_detail;
|
||||
|
||||
private static $is_for;
|
||||
|
||||
private static $customer_detail;
|
||||
|
||||
public static function initYard($user_abo)
|
||||
{
|
||||
|
|
@ -37,12 +33,12 @@ class AboOrderCart
|
|||
|
||||
\Log::info('AboOrderCart::initYard: Yard geleert', [
|
||||
'abo_id' => $user_abo->id,
|
||||
'items_vor_destroy' => $itemsBeforeDestroy
|
||||
'items_vor_destroy' => $itemsBeforeDestroy,
|
||||
]);
|
||||
$itemsAfterDestroy = $yard->content()->count();
|
||||
\Log::info('AboOrderCart::initYard: Yard geleert', [
|
||||
'abo_id' => $user_abo->id,
|
||||
'items_after_destroy' => $itemsAfterDestroy
|
||||
'items_after_destroy' => $itemsAfterDestroy,
|
||||
]);
|
||||
|
||||
self::$customer_detail = self::makeCustomerDetail($user_abo);
|
||||
|
|
@ -56,6 +52,7 @@ class AboOrderCart
|
|||
if ($country_id && $shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
|
||||
if ($shipping_country->shipping && $shipping_country->shipping->active) {
|
||||
UserService::initUserYard($user_abo->user, $shipping_country->id, 'abo-me');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +61,7 @@ class AboOrderCart
|
|||
if ($user_abo->is_for === 'ot') {
|
||||
self::$is_for = 'abo-ot-customer';
|
||||
UserService::initCustomerYard(self::$customer_detail, 'abo-ot-customer');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +88,7 @@ class AboOrderCart
|
|||
if ($itemsBefore > 0) {
|
||||
\Log::warning('AboOrderCart::makeOrderYard: Yard war nicht leer vor makeOrderYard und wurde geleert', [
|
||||
'abo_id' => $user_abo->id,
|
||||
'items_before' => $itemsBefore
|
||||
'items_before' => $itemsBefore,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -105,9 +103,9 @@ class AboOrderCart
|
|||
'id' => $item->id,
|
||||
'product_id' => $item->product_id,
|
||||
'qty' => $item->qty,
|
||||
'comp' => $item->comp
|
||||
'comp' => $item->comp,
|
||||
];
|
||||
})->toArray()
|
||||
})->toArray(),
|
||||
]);
|
||||
|
||||
foreach ($abo_items as $abo_item) {
|
||||
|
|
@ -141,10 +139,11 @@ class AboOrderCart
|
|||
'weight' => 0,
|
||||
'points' => 0,
|
||||
'comp' => $item->comp,
|
||||
'product_id' => $product->id
|
||||
'product_id' => $product->id,
|
||||
]
|
||||
);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
if (self::$is_for === 'ot-customer' || self::$is_for === 'abo-ot-customer') {
|
||||
|
|
@ -153,10 +152,10 @@ class AboOrderCart
|
|||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$item->qty,
|
||||
round($product->getPriceWith($tax_free, false, $user_country, false, self::$user_abo->user), 1),
|
||||
round($product->getPriceWith($tax_free, false, $user_country, false, self::$user_abo->user), 1),
|
||||
false,
|
||||
false,
|
||||
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
} else {
|
||||
$cartItem = Yard::instance('shopping')
|
||||
|
|
@ -164,10 +163,10 @@ class AboOrderCart
|
|||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$item->qty,
|
||||
$product->getPriceWith($tax_free, true, $user_country, false, self::$user_abo->user),
|
||||
$product->getPriceWith($tax_free, true, $user_country, false, self::$user_abo->user),
|
||||
false,
|
||||
false,
|
||||
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]
|
||||
['image' => '', 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]
|
||||
);
|
||||
}
|
||||
if ($tax_free) {
|
||||
|
|
@ -189,7 +188,7 @@ class AboOrderCart
|
|||
return true;
|
||||
}
|
||||
|
||||
//need to add
|
||||
// need to add
|
||||
if (count($UserAboItems) < $needNumComp) {
|
||||
$product = Product::whereActive(true)->where('shipping_addon', true)->whereJsonContains('show_on', '12')->orderBy('pos', 'DESC')->first();
|
||||
for ($i = count($UserAboItems); $i <= $needNumComp; $i++) {
|
||||
|
|
@ -200,13 +199,15 @@ class AboOrderCart
|
|||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
AboItemHistoryService::logSystemCompAdded($user_abo, $UserAboItem);
|
||||
self::addProductToCart($UserAboItem);
|
||||
}
|
||||
}
|
||||
//need to remove
|
||||
// need to remove
|
||||
if (count($UserAboItems) > $needNumComp) {
|
||||
foreach ($UserAboItems as $UserAboItem) {
|
||||
if ($UserAboItem->comp > $needNumComp) {
|
||||
AboItemHistoryService::logSystemCompRemoved($user_abo, $UserAboItem);
|
||||
$UserAboItem->delete();
|
||||
}
|
||||
}
|
||||
|
|
@ -230,20 +231,20 @@ class AboOrderCart
|
|||
{
|
||||
|
||||
if ($user_abo->is_for === 'me') {
|
||||
//only on Abo!
|
||||
// only on Abo!
|
||||
$user = $user_abo->user;
|
||||
|
||||
// WICHTIG: Wenn bereits ein shopping_user existiert, diesen replizieren um alle Felder zu behalten
|
||||
// Ansonsten neues Objekt erstellen
|
||||
if ($user_abo->shopping_user) {
|
||||
$shopping_user = $user_abo->shopping_user->replicate();
|
||||
\Log::info('AboOrderCart::makeCustomerDetail: ShoppingUser repliziert für Abo ID: ' . $user_abo->id, [
|
||||
\Log::info('AboOrderCart::makeCustomerDetail: ShoppingUser repliziert für Abo ID: '.$user_abo->id, [
|
||||
'abo_id' => $user_abo->id,
|
||||
'original_shopping_user_id' => $user_abo->shopping_user->id
|
||||
'original_shopping_user_id' => $user_abo->shopping_user->id,
|
||||
]);
|
||||
} else {
|
||||
$shopping_user = new ShoppingUser();
|
||||
\Log::info('AboOrderCart::makeCustomerDetail: Neuer ShoppingUser erstellt für Abo ID: ' . $user_abo->id);
|
||||
$shopping_user = new ShoppingUser;
|
||||
\Log::info('AboOrderCart::makeCustomerDetail: Neuer ShoppingUser erstellt für Abo ID: '.$user_abo->id);
|
||||
}
|
||||
|
||||
// Account-Daten überschreiben/aktualisieren
|
||||
|
|
@ -258,9 +259,10 @@ class AboOrderCart
|
|||
$shopping_user->billing_country_id = $user->account->country_id;
|
||||
$shopping_user->billing_phone = $user->account->phone;
|
||||
$shopping_user->billing_email = $user->email ?? null;
|
||||
$shopping_user->language = $user->account->getLocale();
|
||||
|
||||
// Auth User ID setzen falls noch nicht gesetzt
|
||||
if (!$shopping_user->auth_user_id) {
|
||||
if (! $shopping_user->auth_user_id) {
|
||||
$shopping_user->auth_user_id = $user->id;
|
||||
}
|
||||
if ($user->account->same_as_billing) {
|
||||
|
|
@ -293,9 +295,10 @@ class AboOrderCart
|
|||
}
|
||||
|
||||
if ($user_abo->is_for === 'ot') {
|
||||
//look for the primary user of this abo
|
||||
// look for the primary user of this abo
|
||||
$shopping_user = $user_abo->shopping_user->replicate();
|
||||
}
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue