update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
311
dev/app-bak/Http/Controllers/Portal/AboController.php
Normal file
311
dev/app-bak/Http/Controllers/Portal/AboController.php
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use Auth;
|
||||
use Yard;
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\UserAbo;
|
||||
use App\Services\AboHelper;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class AboController extends Controller
|
||||
{
|
||||
private $instance = 'subscription';
|
||||
private $yard;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
$this->yard = Yard::instance($this->instance);
|
||||
}
|
||||
|
||||
|
||||
public function myAbo()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
return view('portal.abo.my_abo_create', [
|
||||
'user' => $user,
|
||||
'no_shopping_user' => true,
|
||||
'step' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$user_abo = UserAbo::where('email', $shopping_user->billing_email)
|
||||
->where('status', '>', 1)
|
||||
->first();
|
||||
|
||||
return $user_abo
|
||||
? view('portal.abo.my_abo', ['user_abo' => $user_abo])
|
||||
: view('portal.abo.my_abo_create', [
|
||||
'shopping_user' => $shopping_user,
|
||||
'step' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function myAboCreate($step)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
|
||||
if (!$user->shopping_user_id) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$data = $this->prepareAboCreateData($shopping_user, $step);
|
||||
if(isset($data['checkout_url'])){
|
||||
return redirect($data['checkout_url']);
|
||||
}
|
||||
return view('portal.abo.my_abo_create', $data);
|
||||
}
|
||||
|
||||
private function prepareAboCreateData($shopping_user, $step)
|
||||
{
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'basis_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['12'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'upgrade_products' => Product::where('active', true)
|
||||
->whereJsonContains('show_on', ['13'])
|
||||
->orderBy('pos', 'ASC')
|
||||
->get(),
|
||||
'step' => 0,
|
||||
];
|
||||
if(Request::get('action') == 'back') {
|
||||
$step = $step - 2;
|
||||
}
|
||||
|
||||
switch ($step) {
|
||||
case 0:
|
||||
$data['step'] = 0;
|
||||
break;
|
||||
case 1:
|
||||
$this->initYard($shopping_user);
|
||||
$data['step'] = 1;
|
||||
break;
|
||||
case 2:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
$data['step'] = 2;
|
||||
break;
|
||||
case 3:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'next'){
|
||||
if (!$this->checkBasisProduct()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 2;
|
||||
} else {
|
||||
$data['step'] = 3;
|
||||
}
|
||||
}else{
|
||||
$data['step'] = 3;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
$this->upgradeProductToCart();
|
||||
$data['step'] = 4;
|
||||
break;
|
||||
case 5:
|
||||
//chekout verarbeiten
|
||||
UserService::setInstance($this->instance);
|
||||
UserService::initCustomerYard($shopping_user, 'abo-ot-customer');
|
||||
if(Request::get('action') == 'checkout'){
|
||||
//checkout verarbeiten
|
||||
if (!$this->preCheckCheckout()) {
|
||||
$data['error'] = __('abo.abo_error_basis_product');
|
||||
$data['step'] = 4;
|
||||
} else {
|
||||
$data['checkout_url'] = $this->processCheckout();
|
||||
}
|
||||
}
|
||||
$data['step'] = 4;
|
||||
break;
|
||||
default:
|
||||
abort(404, 'Page not found.');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function initYard($shopping_user)
|
||||
{
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
if (!$delivery_country) {
|
||||
abort(404, 'No delivery country found, please edit your personal data.');
|
||||
}
|
||||
|
||||
\Session::put('user_init_country', strtolower($delivery_country->code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower(\App::getLocale()));
|
||||
|
||||
Shop::initUserShopLang($delivery_country, $this->instance);
|
||||
}
|
||||
|
||||
private function preCheckCheckout(){
|
||||
$result = false;
|
||||
//alle inhlate des warenkorb
|
||||
$cartItems = $this->yard->content();
|
||||
foreach($cartItems as $item){
|
||||
if(in_array(12, $item->options->show_on)){
|
||||
$result = true;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkBasisProduct()
|
||||
{
|
||||
$data = Request::all();
|
||||
$result = false;
|
||||
|
||||
if (!isset($data['base_product_qty'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data['base_product_qty'] as $product_id => $quantity) {
|
||||
$product = Product::find($product_id);
|
||||
|
||||
if (!$product || intval($quantity) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result = true;
|
||||
$this->addProductToCart($product, $quantity);
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function upgradeProductToCart(){
|
||||
$data = Request::all();
|
||||
$result = false;
|
||||
|
||||
if (!isset($data['upgrade_product_qty'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data['upgrade_product_qty'] as $product_id => $quantity) {
|
||||
$product = Product::find($product_id);
|
||||
|
||||
if (!$product) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = true;
|
||||
$this->addProductToCart($product, $quantity);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function addProductToCart($product, $quantity)
|
||||
{
|
||||
// Suche nach dem Produkt im Warenkorb
|
||||
$cartItems = $this->yard->search(function($item) use ($product) {
|
||||
return $item->id === $product->id;
|
||||
});
|
||||
|
||||
// Wenn die Menge 0 ist, entferne das Produkt
|
||||
if ($quantity <= 0) {
|
||||
foreach ($cartItems as $item) {
|
||||
$this->yard->remove($item->rowId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$image = $product->images->first()->slug ?? '';
|
||||
$price = $product->getPriceWith(
|
||||
$this->yard->getUserTaxFree(),
|
||||
false,
|
||||
$this->yard->getUserCountry()
|
||||
);
|
||||
|
||||
// Wenn das Produkt bereits im Warenkorb ist, aktualisiere die Menge
|
||||
if ($cartItems->count() > 0) {
|
||||
$cartItem = $cartItems->first();
|
||||
$this->yard->update($cartItem->rowId, $quantity);
|
||||
} else {
|
||||
// Wenn das Produkt noch nicht im Warenkorb ist, füge es hinzu
|
||||
$cartItem = $this->yard->add(
|
||||
$product->id,
|
||||
$product->getLang('name'),
|
||||
$quantity,
|
||||
$price,
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'image' => $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
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// $this->setProductTax($cartItem, $product);
|
||||
$this->yard->reCalculateShippingPrice();
|
||||
}
|
||||
|
||||
|
||||
private function processCheckout(){
|
||||
$user_shop = Util::getUserShop();
|
||||
if(!$user_shop){
|
||||
$user_shop = Util::getDefaultUserShop();
|
||||
}
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'shopping';
|
||||
$data['user_price_infos'] = $this->yard->getUserPriceInfos();
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment' => 1, //Customer Shop Payment
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => $this->yard->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
$this->yard->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
if(strpos($path, 'https') === false){
|
||||
$path = str_replace('http', 'https', $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
203
dev/app-bak/Http/Controllers/Portal/Auth/LoginController.php
Executable file
203
dev/app-bak/Http/Controllers/Portal/Auth/LoginController.php
Executable file
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Services\Util;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\ShoppingUser;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Mail\MailOTPCustomer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Models\Customer; // Oder User, je nach Setup
|
||||
use App\Models\OtpToken; // Zum Speichern/Prüfen des OTP
|
||||
use Illuminate\Support\Facades\Hash; // Zum Hashen des Tokens
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
// Zeigt das Formular zur Eingabe der E-Mail an
|
||||
public function showLoginForm()
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if (Auth::guard('user')->check()) {
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann direkt zum Dashboard
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
return view('portal.auth.login'); // Erstelle diese View
|
||||
}
|
||||
|
||||
// Sendet das OTP
|
||||
public function sendOtp(Request $request)
|
||||
{
|
||||
$request->validate(['email' => 'required|email']);
|
||||
$email = $request->input('email');
|
||||
|
||||
// 1. Prüfen, ob die E-Mail im System bekannt ist über Kunden-Tabelle)
|
||||
$customer = Customer::firstOrCreate(['email' => $email]); // Erstellt Kunden, wenn nicht vorhanden
|
||||
if ($customer && $customer->language) {
|
||||
\App::setLocale($customer->language);
|
||||
}
|
||||
|
||||
// if (!$customerExists && !$orderExists) { // Oder nur eine Prüfung, je nach Logik
|
||||
if (!$customer) { // Prüfung anhand des Customer-Models
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.failed_customer'), // Generische Fehlermeldung
|
||||
]);
|
||||
}
|
||||
// 2. Alten Token löschen (optional, aber empfohlen)
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
||||
// 3. OTP generieren (z.B. 6-stellige Zahl)
|
||||
$otp = random_int(100000, 999999);
|
||||
$expiresAt = Carbon::now()->addMinutes(10); // Gültigkeit z.B. 10 Minuten
|
||||
|
||||
// 4. OTP (gehasht!) speichern
|
||||
DB::table('otp_tokens')->insert([
|
||||
'email' => $email,
|
||||
'token' => Hash::make((string)$otp), // WICHTIG: Token hashen!
|
||||
'expires_at' => $expiresAt,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
// 5. OTP per E-Mail senden (Notification oder Mailable verwenden)
|
||||
try {
|
||||
Mail::to($email)->locale(\App::getLocale())->send(new MailOTPCustomer($otp, $email));
|
||||
} catch (\Exception $e) {
|
||||
// Logge den Fehler
|
||||
\Log::error('OTP Send Error: ' . $e->getMessage());
|
||||
// Gib eine Fehlermeldung zurück, ohne Details preiszugeben
|
||||
return back()->withErrors(['email' => 'Konnte E-Mail nicht senden. Bitte versuchen Sie es später erneut.'])->withInput();
|
||||
}
|
||||
|
||||
|
||||
// 6. Zum OTP-Eingabeformular weiterleiten (E-Mail in Session speichern oder als Parameter übergeben)
|
||||
session(['otp_email' => $email]); // Explizit in Session speichern
|
||||
return redirect()->route('portal.login.otp.form', ['email' => $email]); // E-Mail auch als Parameter übergeben
|
||||
}
|
||||
|
||||
// Zeigt das Formular zur Eingabe des OTP an
|
||||
public function showOtpForm(Request $request, $email = null, $otp = null)
|
||||
{
|
||||
//wenn als Berater eingeloggt, dann zum Login wechseln
|
||||
if (Auth::guard('user')->check()) {
|
||||
return redirect()->route('portal.change_login');
|
||||
}
|
||||
//wenn als Kunde eingeloggt, dann zum Dashboard wechseln
|
||||
if (Auth::guard('customers')->check()) {
|
||||
return redirect()->route('portal.dashboard');
|
||||
}
|
||||
// E-Mail aus der Session holen (oder als Request-Parameter erwarten)
|
||||
if ($email) {
|
||||
$email = $email;
|
||||
} else {
|
||||
$email = session('otp_email', $request->query('email'));
|
||||
}
|
||||
if (!$email) {
|
||||
return redirect()->route('portal.login.form')->withErrors(['message' => 'Sitzung abgelaufen oder E-Mail fehlt.']);
|
||||
}
|
||||
|
||||
// CSRF-Token regenerieren für neue Session
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
// Übergebe sowohl 'email' als auch 'otp' an die View
|
||||
return view('portal.auth.verify-otp', ['email' => $email, 'otp_value' => $otp]); // Variable umbenannt zu otp_value für Klarheit
|
||||
}
|
||||
|
||||
// Validiert das OTP und loggt den Kunden ein
|
||||
public function verifyOtpAndLogin(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email',
|
||||
'otp' => 'required|numeric|digits:6', // An die Länge deines OTPs anpassen
|
||||
]);
|
||||
|
||||
$email = $request->input('email');
|
||||
$otpInput = $request->input('otp');
|
||||
|
||||
// 1. Gespeicherten OTP-Eintrag finden
|
||||
$otpRecord = DB::table('otp_tokens')->where('email', $email)->first();
|
||||
|
||||
// 2. Prüfen ob Eintrag existiert, nicht abgelaufen ist und das OTP (Hash) übereinstimmt
|
||||
if (!$otpRecord || Carbon::now()->gt($otpRecord->expires_at) || !Hash::check($otpInput, $otpRecord->token)) {
|
||||
// Ungültiges oder abgelaufenes OTP
|
||||
DB::table('otp_tokens')->where('email', $email)->delete(); // Ungültigen Token löschen
|
||||
return back()->withErrors(['otp' => 'Ungültiges oder abgelaufenes Einmalpasswort.'])->withInput(['email' => $email]);
|
||||
}
|
||||
// 3. Kunden-Objekt finden (basierend auf dem Provider-Model)
|
||||
$customer = Customer::where('email', $email)->first(); // Oder User::where('email', $email)->where('role','customer')->first();
|
||||
|
||||
if (!$customer) {
|
||||
// Sollte eigentlich nicht passieren, wenn sendOtp korrekt funktioniert hat
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
return back()->withErrors(['otp' => __('auth.failed')])->withInput(['email' => $email]);
|
||||
}
|
||||
// 4. Kunden einloggen über den 'customers'-Guard
|
||||
Auth::guard('customers')->login($customer); // Loggt den gefundenen Kunden ein
|
||||
|
||||
// 5. Explizite Session-Speicherung
|
||||
$request->session()->save();
|
||||
|
||||
// 6. OTP-Eintrag löschen
|
||||
DB::table('otp_tokens')->where('email', $email)->delete();
|
||||
|
||||
// 7. Session Token regenerieren (statt komplette Session)
|
||||
$request->session()->regenerate();
|
||||
|
||||
// 8. customer DB aktualisieren
|
||||
$shopping_user = ShoppingUser::where('billing_email', $email)->latest()->first();
|
||||
if ($shopping_user) {
|
||||
$data = [
|
||||
'name' => $shopping_user->billing_firstname . ' ' . $shopping_user->billing_lastname,
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'member_id' => $shopping_user->member_id,
|
||||
'number' => $shopping_user->number,
|
||||
'language' => session('locale') ?? 'de',
|
||||
];
|
||||
$customer->update($data);
|
||||
} else {
|
||||
$data = [
|
||||
'name' => __('portal.guest'),
|
||||
'shopping_user_id' => null,
|
||||
'member_id' => null,
|
||||
'number' => null,
|
||||
'language' => session('locale') ?? 'de',
|
||||
];
|
||||
$customer->update($data);
|
||||
}
|
||||
|
||||
|
||||
// 10. Zum Kunden-Dashboard weiterleiten
|
||||
return redirect()->intended(route('portal.dashboard')); // intended() leitet zur ursprünglich angefragten Seite weiter
|
||||
}
|
||||
|
||||
// Logout für Kunden
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$url = Util::getMyMivitaShopUrl();
|
||||
Auth::guard('customers')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
// Logout für Berater
|
||||
public function logoutChange(Request $request)
|
||||
{
|
||||
//$url = Util::getMyMivitaShopUrl();
|
||||
$user_shop_domain = session('user_shop_domain');
|
||||
$locale = session('locale');
|
||||
Auth::guard('user')->logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
session(['user_shop_domain' => $user_shop_domain]);
|
||||
session(['locale' => $locale]);
|
||||
return redirect()->route('portal.login.form');
|
||||
}
|
||||
}
|
||||
99
dev/app-bak/Http/Controllers/Portal/CustomerController.php
Normal file
99
dev/app-bak/Http/Controllers/Portal/CustomerController.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
public function myDataEdit()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
}else{
|
||||
$shopping_user = new ShoppingUser();
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
];
|
||||
return view('portal.customer.edit', $data);
|
||||
|
||||
}
|
||||
|
||||
public function myDataStore(){
|
||||
$user = Auth::guard('customers')->user();
|
||||
$data = Request::all();
|
||||
|
||||
|
||||
if($data['action'] === 'shopping-user-store-new' || $data['action']==='shopping-user-store'){
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
|
||||
if(!Request::get('same_as_billing')){
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
$data['language'] = \App::getLocale();
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
}else{
|
||||
$data['billing_email'] = $user->email;
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
$user->shopping_user_id = $shopping_user->id;
|
||||
$user->save();
|
||||
//kundenhoheit
|
||||
CustomerPriority::checkOne(ShoppingUser::find($shopping_user->id), true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('portal.my_data.edit'));
|
||||
}
|
||||
|
||||
}
|
||||
132
dev/app-bak/Http/Controllers/Portal/InController.php
Executable file
132
dev/app-bak/Http/Controllers/Portal/InController.php
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Config;
|
||||
use Request;
|
||||
use Storage;
|
||||
use Util;
|
||||
|
||||
class InController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(Auth::guard('user')->check()){
|
||||
return redirect(route('portal.change_login'));
|
||||
}
|
||||
if(!Auth::guard('customers')->check()){ // if () {
|
||||
return redirect(route('portal.login.form'));
|
||||
}
|
||||
return redirect(route('portal.dashboard'));
|
||||
|
||||
}
|
||||
|
||||
public function changeLogin(){
|
||||
if(Auth::guard('customers')->check()){
|
||||
return redirect(route('portal.dashboard'));
|
||||
}
|
||||
if(Auth::guard('user')->check()){
|
||||
return view('portal.auth.change');
|
||||
|
||||
}
|
||||
return redirect(route('portal.login.form'));
|
||||
|
||||
}
|
||||
|
||||
public function dashboard()
|
||||
{
|
||||
if(!Auth::guard('customers')->check()){
|
||||
return redirect(route('portal.login.form'));
|
||||
}
|
||||
$data = [
|
||||
'user' => Auth::guard('customers')->user(),
|
||||
'now' => Carbon::now(),
|
||||
];
|
||||
return view('portal.dashboard', $data);
|
||||
}
|
||||
|
||||
public function loadingModal(){
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
$response = "";
|
||||
$status = false;
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'user-order-show-product'){
|
||||
$product = Product::find($data['id']); //current user form order
|
||||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render();
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
}
|
||||
}
|
||||
|
||||
$data = Request::get('data');
|
||||
$target = Request::get('target');
|
||||
if($data === "data_protection"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => true,
|
||||
'isMivitaShop' => false,
|
||||
];
|
||||
$response = view('legal.data_protect_de', $data)->render();
|
||||
}
|
||||
if($data === "imprint"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.imprint_de', $data)->render();
|
||||
}
|
||||
if($data === "shop_term_of_use"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.shop_term_of_use_de', $data)->render();
|
||||
}
|
||||
if($data === "agb"){
|
||||
$data = [
|
||||
'modal' => true,
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
$response = view('legal.agb_de', $data)->render();
|
||||
}
|
||||
if(Request::ajax()) {
|
||||
return response()->json(['response' => $response, 'target'=>$target]);
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* public function goToShop(){
|
||||
|
||||
if(!Auth::guard('customers')->check()){
|
||||
return redirect(config('app.protocol') . config('app.domain') . config('app.tld_shop'));
|
||||
}
|
||||
$customer = Auth::guard('customers')->user();
|
||||
//subdmain for member
|
||||
$member = User::where('email', $customer->email)->first();
|
||||
if($member){
|
||||
return redirect(config('app.protocol') . $member->subdomain . config('app.tld_care'));
|
||||
}
|
||||
// $customer->member_id
|
||||
|
||||
// return redirect(config('app.protocol') . config('app.domain') . config('app.tld_shop'));
|
||||
}*/
|
||||
}
|
||||
116
dev/app-bak/Http/Controllers/Portal/OrderController.php
Normal file
116
dev/app-bak/Http/Controllers/Portal/OrderController.php
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Portal;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
private $instance = 'webshop';
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth:customers');
|
||||
}
|
||||
|
||||
|
||||
public function myOrders()
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
if($user->shopping_user_id){
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_orders = $shopping_user->getAllOrdersByMember();
|
||||
}else{
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_orders = [];
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'shopping_orders' => $shopping_orders,
|
||||
];
|
||||
return view('portal.order.my_orders', $data);
|
||||
|
||||
}
|
||||
|
||||
public function myOrderShow($id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->shopping_user_id != $user->shopping_user_id){
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
return view('portal.order.my_order_show', [
|
||||
'shopping_order' => $shopping_order,
|
||||
'shopping_user' => $shopping_user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function myOrderCreate($id)
|
||||
{
|
||||
$user = Auth::guard('customers')->user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->shopping_user_id != $user->shopping_user_id){
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
$shopping_user = ShoppingUser::findOrFail($user->shopping_user_id);
|
||||
$delivery_country = $shopping_user->getDeliveryCountry(true);
|
||||
|
||||
\Session::put('user_init_country', strtolower($delivery_country->code));
|
||||
\Session::forget('user_init_country_options');
|
||||
\Session::put('locale', strtolower(\App::getLocale()));
|
||||
|
||||
Shop::initUserShopLang($delivery_country, $this->instance);
|
||||
|
||||
//init Yard
|
||||
|
||||
foreach($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
if($shopping_order_item->product){
|
||||
$this->addToCard($shopping_order_item->product_id, $shopping_order_item->qty);
|
||||
}
|
||||
}
|
||||
$url = Util::getMyMivitaShopUrl("/user/card/show");
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
|
||||
private function addToCard($id, $quantity = 1)
|
||||
{
|
||||
$product = Product::find($id);
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance($this->instance)
|
||||
->add($product->id, $product->getLang('name'), $quantity,
|
||||
$product->getPriceWith(Yard::instance($this->instance)->getUserTaxFree(), false, Yard::instance($this->instance)->getUserCountry()), false, false,
|
||||
['image' => $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(Yard::instance($this->instance)->getUserTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance($this->instance)->getUserCountry()));
|
||||
}
|
||||
Yard::instance($this->instance)->reCalculateShippingPrice();
|
||||
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue