commit 08-2025

This commit is contained in:
Kevin Adametz 2025-08-12 18:01:59 +02:00
parent 9ae662f63e
commit 480fdc65ed
404 changed files with 65310 additions and 2600431 deletions

View file

@ -24,6 +24,7 @@ use Yard;
class CheckoutController extends Controller
{
private $checkoutRepo;
private $instance = 'checkout';
/**
* Create a new controller instance.
@ -42,7 +43,15 @@ class CheckoutController extends Controller
*/
public function checkout()
{
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
/*
@if(Auth::guard('customers')->check())
<a href="{{ route('portal.logout') }}" class="btn btn-sm btn-default mt-3"><i class="fa fa-power-off"></i> {{ __('navigation.logout') }} </a>
@else
<a href="{{ Util::getMyMivitaPortalUrl() }}" class="btn btn-primary btn-block mt-3 faa-parent animated-hover"><i class="fa fa-sign-in"></i> {{ __('website.to_customer_portal') }} </a>
@endif
@if(Auth::guard('user')->check())
*/
$shopping_data = Yard::instance($this->instance)->getYardExtra('shopping_data');
$is_from = $shopping_data['is_from'] ?? 'shopping';
$is_for = $shopping_data['is_for'] ?? false;
$is_abo = isset($shopping_data['is_abo']) ? (bool) $shopping_data['is_abo'] : false;
@ -53,7 +62,6 @@ class CheckoutController extends Controller
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
$is_from = 'shopping';
}
Util::setInstanceStatus(1, true); // link_check
if ($is_abo) {
$instance_status = Util::getInstanceStatus();
@ -61,29 +69,11 @@ class CheckoutController extends Controller
return $this->redirectToIsFinal($instance_status);
}
}
if (Session::has('new_session')) {
$this->checkoutRepo->sessionDestroy();
Session::forget('new_session');
}
if (!$this->checkoutRepo->getSessionPayments('shopping_user_id')) {
if ($shopping_data && $is_from !== 'shopping') {
$shopping_user = $this->checkoutRepo->shoppingUserAuthData($is_from, $is_for, $shopping_data);
$shopping_user->save();
$this->checkoutRepo->putSessionPayments('shopping_user_id', $shopping_user->id);
} elseif ($is_from === 'shopping' && ($is_for !== 'ot-customer' && $is_for !== 'abo-ot-customer')) {
$shopping_user = $this->initializeShoppingUser($is_for, $is_from, $homeparty_id);
} elseif ($is_from === 'shopping' && ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer')) {
$shopping_user = $this->checkoutRepo->makeCustomerShoppingUser($shopping_data);
$shopping_user->is_for = $is_for;
$shopping_user->is_from = $is_from;
$shopping_user->mode = 'prev';
$shopping_user->language = \App::getLocale();
}
} else {
$shopping_user = $this->getExistingShoppingUser();
}
}
$shopping_user = $this->initializeShoppingUserSession($is_from, $is_for, $shopping_data, $homeparty_id);
$this->prepareShoppingUserData($shopping_user);
$payment_methods = $this->checkoutRepo->getPaymentsMethods($is_from, $is_abo);
@ -101,46 +91,14 @@ class CheckoutController extends Controller
'payment_methods_active' => $payment_methods['active'],
'payment_data' => $payment_methods['data'],
'instance_status' => $instance_status ?? false,
'is_checkout' => true,
'yard_instance' => $this->instance,
];
return view('web.templates.checkout', $data);
}
/**
* Initialisiert einen neuen ShoppingUser
*
* @param string $is_for
* @param string $is_from
* @param int|null $homeparty_id
* @return ShoppingUser
*/
private function initializeShoppingUser($is_for, $is_from, $homeparty_id = null)
{
$shopping_user = new ShoppingUser();
$shopping_user->is_for = $is_for;
$shopping_user->is_from = $is_from;
$shopping_user->homeparty_id = $homeparty_id;
$shopping_user->mode = 'prev';
$shopping_user->language = \App::getLocale();
return $shopping_user;
}
/**
* Holt den existierenden ShoppingUser und bereitet ihn vor
*
* @return ShoppingUser
*/
private function getExistingShoppingUser()
{
$shopping_user = ShoppingUser::findOrFail($this->checkoutRepo->getSessionPayments('shopping_user_id'));
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; // reinvert
return $shopping_user;
}
/**
* Bereitet die ShoppingUser-Daten vor
*
@ -152,25 +110,23 @@ class CheckoutController extends Controller
if ($shopping_user->same_as_billing === NULL) {
$shopping_user->same_as_billing = false;
}
if (!$shopping_user->billing_country_id) {
$shopping_user->billing_country_id = Yard::instance('shopping')->getUserCountryId();
$shopping_user->billing_country_id = Yard::instance($this->instance)->getUserCountryId();
// Die Zeile unten entfernen, da die Relation automatisch geladen wird
// $shopping_user->billing_country = Yard::instance('shopping')->getUserCountry();
// $shopping_user->billing_country = Yard::instance($this->instance)->getUserCountry();
}
if (!$shopping_user->shipping_country_id) {
$shopping_user->shipping_country_id = Yard::instance('shopping')->getUserCountryId();
$shopping_user->shipping_country_id = Yard::instance($this->instance)->getUserCountryId();
// Die Zeile unten entfernen, da die Relation automatisch geladen wird
// $shopping_user->shipping_country = Yard::instance('shopping')->getUserCountry();
// $shopping_user->shipping_country = Yard::instance($this->instance)->getUserCountry();
}
if (old('selected_country') && old('selected_country') === 'change') {
Session::forget('_old_input.selected_country');
$shopping_user->billing_state = old('billing_state');
$shopping_user->shipping_state = old('shipping_state');
} else {
$shopping_user->billing_state = Yard::instance('shopping')->getShippingCountryId();
$shopping_user->shipping_state = Yard::instance('shopping')->getShippingCountryId();
$shopping_user->billing_state = Yard::instance($this->instance)->getShippingCountryId();
$shopping_user->shipping_state = Yard::instance($this->instance)->getShippingCountryId();
}
}
@ -228,9 +184,9 @@ class CheckoutController extends Controller
private function handleCountryChange($data)
{
if (!Request::get('same_as_billing')) {
Yard::instance('shopping')->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
Yard::instance($this->instance)->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
} else {
Yard::instance('shopping')->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
Yard::instance($this->instance)->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
}
return back()->withInput(Request::all());
@ -300,7 +256,7 @@ class CheckoutController extends Controller
// Zahlung vorbereiten
$pay = new PayoneController();
$pay->init($shopping_user, $shopping_order);
$amount = Yard::instance('shopping')->totalWithShipping(2, '.', '') * 100;
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
$reference = $pay->setPrePayment($payment_method, $amount, 'EUR', $result);
$this->checkoutRepo->putSessionPayments('payment_reference', $reference);
$pay->setPersonalData();
@ -345,7 +301,7 @@ class CheckoutController extends Controller
if (is_null(Request::get('mandate_identification'))) {
$pay = new PayoneController();
$pay->init($shopping_user, $shopping_order);
$amount = Yard::instance('shopping')->totalWithShipping(2, '.', '') * 100;
$amount = Yard::instance($this->instance)->totalWithShipping(2, '.', '') * 100;
$ret['elv'] = $pay->checkBankAccount($data, $amount, 'EUR', $shopping_user);
if ($ret['elv']['status'] === 'ERROR' || $ret['elv']['status'] === 'INVALID') {
@ -388,6 +344,8 @@ class CheckoutController extends Controller
{
$data = [
'user_shop' => Util::getUserShop(),
'is_checkout' => true,
'yard_instance' => $this->instance,
];
return view('web.templates.checkout-is-final', $data);
@ -444,8 +402,8 @@ class CheckoutController extends Controller
*/
private function handleSuccessfulTransaction($ShoppingPayment, $reference)
{
Yard::instance('shopping')->destroy();
$this->checkoutRepo->sessionDestroy();
Yard::instance($this->instance)->destroy();
$this->checkoutRepo->sessionDestroy(true);
Util::setInstanceStatus(3, true); // link_pending
// Abo erstellen, falls nötig
@ -458,6 +416,8 @@ class CheckoutController extends Controller
'user_shop' => Util::getUserShop(),
'order_reference' => $reference,
'pay_trans' => $payt,
'is_checkout' => true,
'yard_instance' => $this->instance,
];
return view('web.templates.checkout-final', $data);
@ -476,9 +436,8 @@ class CheckoutController extends Controller
if ($payt->shopping_payment->reference != $reference) {
abort(404);
}
Yard::instance('shopping')->destroy();
$this->checkoutRepo->sessionDestroy();
Yard::instance($this->instance)->destroy();
$this->checkoutRepo->sessionDestroy(true);
Util::setInstanceStatus(3, true); // link_pending
// Abo erstellen, falls nötig
@ -495,6 +454,8 @@ class CheckoutController extends Controller
'user_shop' => Util::getUserShop(),
'order_reference' => $payt->shopping_payment->reference,
'pay_trans' => $payt,
'is_checkout' => true,
'yard_instance' => $this->instance,
];
return view('web.templates.checkout-final', $data);
@ -549,4 +510,57 @@ class CheckoutController extends Controller
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
}
}
/**
* Initialisiert oder ruft einen Shopping-Benutzer ab
*
* @param string|null $is_from = shopping | user_order | user_order_ot | user_order_abo | user_order_abo_ot | user_order_ot_customer | user_order_abo_ot_customer
* @param string|null $is_for = me | ot | abo-me | abo-ot | ot-customer | abo-ot-customer
* @param array|null $shopping_data
* @param int|null $homeparty_id
* @return \App\Models\ShoppingUser
*/
private function initializeShoppingUserSession($is_from, $is_for, $shopping_data = null, $homeparty_id = null)
{
//check if shopping_user_id is set - der user ist bereits angelegt
if ($this->checkoutRepo->getSessionPayments('shopping_user_id')) {
return $this->getExistingShoppingUser();
}
//kommt vom Salescenter
if ($shopping_data && $is_from !== 'shopping') {
$shopping_user = $this->checkoutRepo->shoppingUserAuthData($is_from, $is_for, $shopping_data);
$shopping_user->save();
$this->checkoutRepo->putSessionPayments('shopping_user_id', $shopping_user->id);
return $shopping_user;
}
//kommt aus dem Salescenter mit bestelllink oder aus dem Webshop
if ($is_from === 'shopping') {
//Bestelllink
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
//customer shop mit den Daten aus dem Salescenter shopping_data
return $this->checkoutRepo->makeCustomerShoppingUser($shopping_data, $is_for, $is_from);
}
//Webshop
return $this->checkoutRepo->initShoppingUser($is_for, $is_from, $homeparty_id);
}
return $this->getExistingShoppingUser();
}
/**
* Holt den existierenden ShoppingUser und bereitet ihn vor
*
* @return ShoppingUser
*/
private function getExistingShoppingUser()
{
$shopping_user = ShoppingUser::findOrFail($this->checkoutRepo->getSessionPayments('shopping_user_id'));
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; // reinvert
return $shopping_user;
}
}