199 lines
No EOL
6 KiB
PHP
Executable file
199 lines
No EOL
6 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\ShoppingInstance;
|
|
use App\Models\UserAccount;
|
|
use App\Services\Util;
|
|
use Auth;
|
|
use Hash;
|
|
use Input;
|
|
use Validator;
|
|
use Yard;
|
|
|
|
class WizardController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
|
|
public function show($step = 0)
|
|
{
|
|
|
|
if(!Auth::check()){
|
|
return redirect('login');
|
|
}
|
|
$user = Auth::user();
|
|
if(!$user->account){
|
|
$account = UserAccount::create([]);
|
|
$user->account_id = $account->id;
|
|
$user->save();
|
|
return redirect(route('wizard'));
|
|
}
|
|
|
|
$step = (!$user->wizard ? 0 : $user->wizard );
|
|
if($step == 10){
|
|
return redirect('/');
|
|
}
|
|
$data = [
|
|
'user' => Auth::user(),
|
|
'step' => $step,
|
|
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
|
|
];
|
|
|
|
return view('user.wizard.show', $data);
|
|
}
|
|
|
|
|
|
public function store($step = 0)
|
|
{
|
|
|
|
if(!Auth::check()){
|
|
return redirect('login');
|
|
}
|
|
|
|
$user = Auth::user();
|
|
if(!$user->account){
|
|
$user->account = new UserAccount();
|
|
}
|
|
|
|
if($step == 0){
|
|
$rules = array(
|
|
'accepted_data_protection' => 'required',
|
|
'accepted_active' => 'required',
|
|
);
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
if ($validator->fails()) {
|
|
$data = [
|
|
'user' => Auth::user(),
|
|
'step' => $step,
|
|
];
|
|
return view('user.wizard.show', $data)->withErrors($validator);
|
|
}
|
|
$account = $user->account;
|
|
$account->data_protection = now();
|
|
$account->save();
|
|
$user->agreement = now();
|
|
$user->wizard = 1;
|
|
$user->save();
|
|
|
|
return redirect(route('wizard', [1]));
|
|
}
|
|
if($step == 1){
|
|
|
|
if($user->isPasswort()){
|
|
$user->wizard = 2;
|
|
$user->save();
|
|
return redirect(route('wizard', [2]));
|
|
}
|
|
$rules = array(
|
|
'password' => 'required|string|min:6|confirmed',
|
|
);
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
if ($validator->fails()) {
|
|
$data = [
|
|
'user' => Auth::user(),
|
|
'step' => $step,
|
|
];
|
|
return view('user.wizard.show', $data)->withErrors($validator);
|
|
}else{
|
|
$user->fill([
|
|
'password' => Hash::make(Input::get('password'))
|
|
])->save();
|
|
$user->wizard = 2;
|
|
$user->save();
|
|
return redirect(route('wizard', [2]));
|
|
|
|
|
|
|
|
}
|
|
}
|
|
if($step == 2){
|
|
$rules = array(
|
|
'salutation' => 'required',
|
|
'first_name'=>'required',
|
|
'last_name'=>'required',
|
|
'address'=>'required',
|
|
'zipcode'=>'required',
|
|
'city' => 'required',
|
|
);
|
|
|
|
if(!Input::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'
|
|
|
|
]);
|
|
}
|
|
$validator = Validator::make(Input::all(), $rules);
|
|
if ($validator->fails()) {
|
|
return redirect(route('wizard', [2]))->withErrors($validator)->withInput(Input::all());
|
|
}else{
|
|
$data = Input::all();
|
|
$data['same_as_billing'] = Input::get('same_as_billing') == NULL ? 0 : 1;
|
|
$user->account->fill($data)->save();
|
|
$user->wizard = 3;
|
|
$user->active_date = now();
|
|
$user->active = 1;
|
|
$user->save();
|
|
return redirect(route('wizard', [3]));
|
|
|
|
}
|
|
}
|
|
|
|
if($step == 3){
|
|
|
|
|
|
if(Input::get('switchers-package-wizard')){
|
|
Yard::instance('shopping')->destroy();
|
|
$product = Product::find(Input::get('switchers-package-wizard'));
|
|
if($product && $product->active && $product->show_at == 3){
|
|
$image = "";
|
|
if($product->images->count()){
|
|
$image = $product->images->first()->slug;
|
|
}
|
|
Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
|
|
|
|
do {
|
|
$identifier = Util::getToken();
|
|
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
|
|
|
ShoppingInstance::create([
|
|
'identifier' => $identifier,
|
|
'user_shop_id' => 1, //is first faker shop!
|
|
'auth_user_id' => $user->id,
|
|
'subdomain' => url('/'),
|
|
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
|
|
|
]);
|
|
Yard::instance('shopping')->store($identifier);
|
|
|
|
//add to DB
|
|
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
|
//$path = str_replace('http', 'https', $path);
|
|
return redirect()->secure($path);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
\Session()->flash('alert-error', "Fehler beim Produkt");
|
|
return redirect(route('wizard', [3]));
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} |