23-01-2026

This commit is contained in:
Kevin Adametz 2026-01-23 17:35:23 +01:00
parent a939cd51ef
commit a8b395e20d
248 changed files with 29342 additions and 4805 deletions

View file

@ -1,15 +1,10 @@
<?php
namespace App\Cron;
use Yard;
use App\User;
use stdClass;
use App\Services\Shop;
use App\Models\Product;
use App\Models\UserAbo;
use App\Models\ShoppingOrder;
use App\Services\UserService;
use App\Models\ShippingCountry;
use App\Models\ShoppingOrderItem;
use App\Http\Controllers\Pay\PayoneController;
use App\Services\AboOrderCart;
@ -42,7 +37,7 @@ class UserMakeOrder
return $ret;
}
//preise prüfen, ob sie sich geändert haben?
foreach($this->userAbo->items as $item){
foreach ($this->userAbo->items as $item) {
$ret[] = [
'product_id' => $item->product_id,
'comp' => $item->comp,
@ -61,18 +56,20 @@ class UserMakeOrder
return $ret;
}
public function makePayment()
public function makePayment($testmode = false)
{
Log::info('Starte Zahlungsvorgang für UserAbo ID: ' . $this->userAbo->id);
try {
$this->pay = new PayoneController();
$this->pay->init($this->shopping_user, $this->shopping_order);
$amount = $this->shopping_order->subtotal_ws * 100;
$this->pay->setAboPayment($this->userAbo, $amount, 'EUR');
$this->pay->setPersonalData();
$response = $this->pay->ResponseData(true);
$response = $this->pay->onlyPaymentResponse();
\Log::info('Response: ' . json_encode($response));
//$response = $this->pay->ResponseData(true);
Log::info('Zahlungsvorgang abgeschlossen für UserAbo ID: ' . $this->userAbo->id . ', Status: ' . ($response->status ?? 'unbekannt'));
return $response;
} catch (\Exception $e) {
@ -84,13 +81,13 @@ class UserMakeOrder
public function getShoppingPayment()
{
Log::info('Rufe Zahlungsinformationen ab für UserAbo ID: ' . $this->userAbo->id);
if($this->pay){
if ($this->pay) {
$payment = $this->pay->getShoppingPayment();
Log::info('Zahlungsinformationen abgerufen: ' . ($payment ? 'erfolgreich' : 'nicht verfügbar'));
return $payment;
}
Log::warning('Keine Zahlungsinformationen verfügbar für UserAbo ID: ' . $this->userAbo->id);
return false;
}
@ -99,20 +96,20 @@ class UserMakeOrder
{
Log::info('Erstelle Shopping-User für UserAbo ID: ' . $this->userAbo->id);
//hier muss der letzte shopping_user verwendet werden
try {
$this->shopping_user = AboOrderCart::makeCustomerDetail($this->userAbo);
$this->shopping_user->created_at = now();
$this->shopping_user->updated_at = now();
$this->shopping_user->save();
Log::info('Shopping-User erstellt für UserAbo ID: ' . $this->userAbo->id . ', Neue User-ID: ' . $this->shopping_user->id);
return $this->shopping_user;
} catch (\Exception $e) {
Log::error('Fehler beim Erstellen des Shopping-Users für UserAbo ID: ' . $this->userAbo->id . ': ' . $e->getMessage());
throw $e;
}
try {
$this->shopping_user = AboOrderCart::makeCustomerDetail($this->userAbo);
$this->shopping_user->created_at = now();
$this->shopping_user->updated_at = now();
$this->shopping_user->save();
Log::info('Shopping-User erstellt für UserAbo ID: ' . $this->userAbo->id . ', Neue User-ID: ' . $this->shopping_user->id);
return $this->shopping_user;
} catch (\Exception $e) {
Log::error('Fehler beim Erstellen des Shopping-Users für UserAbo ID: ' . $this->userAbo->id . ': ' . $e->getMessage());
throw $e;
}
Log::warning('Kein Shopping-User verfügbar für UserAbo ID: ' . $this->userAbo->id);
return false;
}
@ -120,19 +117,48 @@ class UserMakeOrder
public function makeShoppingOrder()
{
Log::info('Erstelle Bestellung für UserAbo ID: ' . $this->userAbo->id);
try {
if (!$this->shopping_user) {
Log::error('Kein Shopping-User verfügbar für Bestellerstellung, UserAbo ID: ' . $this->userAbo->id);
return false;
}
AboOrderCart::initYard($this->userAbo, $this->shopping_user);
// WICHTIG: Yard komplett leeren vor jedem Abo, um sicherzustellen, dass keine Produkte
// aus vorherigen Abos im Cart bleiben
Yard::instance('shopping')->destroy();
// initYard akzeptiert nur einen Parameter (user_abo)
AboOrderCart::initYard($this->userAbo);
// Nochmalige Sicherheitsprüfung: Yard sollte leer sein
$yardBefore = Yard::instance('shopping');
$itemsBefore = $yardBefore->content();
if ($itemsBefore->count() > 0) {
Log::warning('UserMakeOrder: Yard war nicht leer nach initYard für Abo ID: ' . $this->userAbo->id . ', Items: ' . $itemsBefore->count());
$yardBefore->destroy(); // Erzwinge Leerung
}
//hier wird die Bestellung erstellt inkl aktueller Preise
AboOrderCart::makeOrderYard($this->userAbo);
$yard = Yard::instance('shopping');
// Debug: Logge welche Produkte im Cart sind
$items = $yard->content();
Log::info('UserMakeOrder: Produkte im Cart nach makeOrderYard für Abo ID: ' . $this->userAbo->id, [
'abo_id' => $this->userAbo->id,
'item_count' => $items->count(),
'items' => $items->map(function ($item) {
return [
'product_id' => $item->id,
'name' => $item->name,
'qty' => $item->qty,
'rowId' => $item->rowId
];
})->toArray()
]);
if (!$this->userAbo->shopping_user || !$this->userAbo->shopping_user->shopping_order || !$this->userAbo->shopping_user->shopping_order->user_shop) {
Log::error('Fehlende Beziehungsdaten für Bestellerstellung, UserAbo ID: ' . $this->userAbo->id);
return false;
@ -155,7 +181,7 @@ class UserMakeOrder
'points' => $yard->points(),
'weight' => $yard->weight(),
'is_abo' => 1,
'abo_interval' => 0,
'abo_interval' => $this->userAbo->abo_interval ?? 0,
'txaction' => 'prev',
'mode' => $this->userAbo->shopping_user->shopping_order->mode,
]);
@ -164,9 +190,9 @@ class UserMakeOrder
$items = $yard->getContentByOrder();
$itemCount = 0;
foreach ($items as $item) {
if (!ShoppingOrderItem::where('shopping_order_id', $this->shopping_order->id)->where('row_id', $item->rowId)->count()){
if (!ShoppingOrderItem::where('shopping_order_id', $this->shopping_order->id)->where('row_id', $item->rowId)->count()) {
$price_net = $yard->rowPriceNet($item, 2, '.', '');
$tax = $item->price - $price_net;
$data = [
@ -188,16 +214,16 @@ class UserMakeOrder
$itemCount++;
}
}
Log::info('Bestellpositionen hinzugefügt für UserAbo ID: ' . $this->userAbo->id . ', Anzahl: ' . $itemCount);
$this->shopping_order->makeTaxSplit();
Log::info('Steueraufteilung für Bestellung abgeschlossen, UserAbo ID: ' . $this->userAbo->id);
return $this->shopping_order;
} catch (\Exception $e) {
Log::error('Fehler bei Bestellerstellung für UserAbo ID: ' . $this->userAbo->id . ': ' . $e->getMessage());
throw $e;
}
}
}
}