checkout, register, payment,

checkout correction,
register wizard,
payment packege,
This commit is contained in:
Kevin Adametz 2019-03-02 00:08:11 +01:00
parent 6e3adac4d7
commit 446bc4561b
48 changed files with 2580 additions and 1493 deletions

View file

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Models\SfGuardUser;
use App\Models\ShoppingPayment;
use App\User;
use Auth;
use Carbon\Carbon;
@ -69,7 +69,7 @@ class HomeController extends Controller
abort(404);
}
public function checkLogin($identify, $token)
/* public function checkLogin($identify, $token)
{
if($identify){
//user find by $identify
@ -110,6 +110,7 @@ class HomeController extends Controller
}
return abort(404);
}
*/
public function legalDataProtected()
{
@ -131,7 +132,9 @@ class HomeController extends Controller
if ( ! $user)
{
return redirect('/status/not/found');
// return redirect('/status/not/found');
return redirect('/home');
}
$user->confirmed = 1;
@ -144,7 +147,7 @@ class HomeController extends Controller
//Login!
Auth::login($user);
return redirect('/status/verify');
return redirect('/home');
}
public function statusRegister(){
@ -177,7 +180,27 @@ class HomeController extends Controller
}
}
return json_encode(true);
}
public function blocked()
{
return view('status.user_blocked');
}
public function backToShop($reference = ""){
if($reference){
$ShoppingPayment = ShoppingPayment::where('reference', $reference)->first();
if($ShoppingPayment->status == 'success'){
$user = Auth::user();
$user->wizard = 4;
$user->save();
return redirect(route('wizard', [4]));
}else{
\Session()->flash('alert-error', "Es ist ein Fehler bei der Bestellung aufgetreten");
return redirect(route('wizard'));
}
}
}
}

View file

@ -47,6 +47,10 @@ class LeadController extends Controller
if($id == "new"){
$user = new User();
$user->account = new UserAccount();
$user->account->same_as_billing = 1;
$user->account->country_id = 1;
$user->account->shipping_country_id = 1;
$user->id = "new";
}else{
$user = User::findOrFail($id);
if(!$user->account){
@ -66,52 +70,66 @@ class LeadController extends Controller
*/
public function store(Request $request)
{
$data = Input::all();
if ($data['user_id'] == "new") {
$user = new User();
$user->id = "new";
$user->account = new UserAccount();
$user->account->company_country_id = isset($data['company_country_id']) ? $data['company_country_id'] : 0;
$user->account->salutation = isset($data['salutation']) ? $data['salutation'] : 0;
$data = Input::all();
if ($data['user_id'] == "new" || $data['user_id'] == 0) {
$rules = array(
'salutation' => 'required',
'last_name' => 'required|max:255',
'country_id' => 'required|integer|min:1',
'first_name'=>'required',
'last_name'=>'required',
'email' => 'required|string|email|max:255|unique:users',
'email-confirm' => 'required|same:email',
);
} else {
$user = User::findOrFail($data['user_id']);
if(!$user->account){
$user->account = new UserAccount();
}
}else{
$rules = array(
'salutation' => 'required',
'last_name' => 'required|max:255',
'country_id' => 'required|integer|min:1',
'first_name'=>'required',
'last_name'=>'required',
'address'=>'required',
'zipcode'=>'required',
'city' => 'required',
'email' => 'required|string|email|max:255|exists:users,email',
'email-confirm' => 'required|same:email',
);
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'
]);
}
}
if(Input::get('company') == 1){
$rules['company_name'] = 'required|max:255';
$rules['company_country_id'] = 'required|integer|min:1';
}
$data = [
'user' => $user,
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return view('admin.lead_edit', $data)->withErrors($validator);
} else {
$data = Input::all();
$this->userRepo->update(Input::all());
if ($data['user_id'] == "new" || $data['user_id'] == 0) {
$user_id = "new";
}else{
$user = User::findOrFail($data['user_id']);
$user_id = $user->id;
}
return redirect(route('admin_lead_edit', [$user_id]))->withErrors($validator)->withInput(Input::all());
}else{
if ($data['user_id'] == "new" || $data['user_id'] == 0) {
$user = new User();
$user->id = "new";
$user->account = new UserAccount();
}else {
$user = User::findOrFail($data['user_id']);
if(!$user->account){
$user->account = new UserAccount();
}
}
$this->userRepo->update($data);
if(isset($data['contact_verify'])){
@ -135,7 +153,12 @@ class LeadController extends Controller
}
\Session()->flash('alert-save', true);
return redirect('/admin/leads');
return redirect(route('admin_leads'));
}
}
}

View file

@ -11,6 +11,7 @@ use App\Models\ShoppingOrder;
use App\Models\ShoppingOrderItem;
use App\Models\ShoppingPayment;
use App\Models\ShoppingUser;
use App\User;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
@ -37,7 +38,7 @@ class CheckoutController extends Controller
public function checkout(){
$user_shop = Util::getUserShop();
// $user_shop = Util::getUserShop();
if(Input::get('selected_country')){
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
@ -46,7 +47,42 @@ class CheckoutController extends Controller
// $selected_country = $ShippingCountry->id;
}
$shopping_user = ShoppingUser::findOrNew($this->getPayments('shopping_user_id'));
if(!$this->getPayments('shopping_user_id') && Util::getAuthUser()){
$user = Util::getAuthUser();
$user->email;
$account = $user->account;
$shopping_user = new ShoppingUser();
$shopping_user->auth_user_id = $user->id;
$shopping_user->billing_salutation = $user->account->salutation;
$shopping_user->billing_company = $user->account->company;
$shopping_user->billing_firstname = $user->account->first_name;
$shopping_user->billing_lastname = $user->account->last_name;
$shopping_user->billing_address = $user->account->address;
$shopping_user->billing_address_2 = $user->account->address_2;
$shopping_user->billing_zipcode = $user->account->zipcode;
$shopping_user->billing_city = $user->account->city;
$shopping_user->billing_country_id = $user->account->country_id;
$shopping_user->billing_phone = $user->account->phone;
$shopping_user->billing_email = $user->email;
$shopping_user->accepted_data_checkbox = 1;
$shopping_user->same_as_billing = $user->account->same_as_billing;
$shopping_user->shipping_salutation = $user->account->shipping_salutation;
$shopping_user->shipping_company = $user->account->shipping_company;
$shopping_user->shipping_firstname = $user->account->shipping_firstname;
$shopping_user->shipping_lastname = $user->account->shipping_lastname;
$shopping_user->shipping_address = $user->account->shipping_address;
$shopping_user->shipping_address_2 = $user->account->shipping_address_2;
$shopping_user->shipping_zipcode = $user->account->shipping_zipcode;
$shopping_user->shipping_city = $user->account->shipping_city;
$shopping_user->shipping_country_id = $user->account->shipping_country_id;
$shopping_user->shipping_phone = $user->account->shipping_phone;
$shopping_user->save();
$this->putPayments('shopping_user_id', $shopping_user->id);
}else{
$shopping_user = ShoppingUser::findOrNew($this->getPayments('shopping_user_id'));
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = true;
}
@ -59,7 +95,7 @@ class CheckoutController extends Controller
public function checkoutFinal(){
/*
$rules = array(
'billing_salutation' => 'required',
'billing_firstname'=>'required',
@ -86,7 +122,7 @@ class CheckoutController extends Controller
if ($validator->fails()) {
return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all());
}
*/
$data = Input::all();
//make User
@ -203,15 +239,16 @@ class CheckoutController extends Controller
$data = [
'key' => '698fb2555f8b2efc74f60b2121421f45',
'txaction' => 'appointed',
'clearingtype' => 'vor',
'userid' => '157787236',
'txid' => '319655873',
'price' => '13.80',
'param' => '6', //$this->shopping_order->id,
'reference' => '15c76c0d470cf9',
'txaction' => 'paid',
'clearingtype' => 'wlt',
'userid' => '158006846',
'txid' => '320267294',
'price' => '59.00',
'param' => '18', //$this->shopping_order->id,
'reference' => '15c79ba77992e2',
];
if(!isset($data['key']) || !isset($data['param']) || !isset($data['userid']) || !isset($data['txid']) || !isset($data['reference']) || !isset($data['price'])){
\Log::channel('payone')->error('PaymentStatus: parameter incomplete: '.json_encode($data));
abort(404);
@ -274,6 +311,28 @@ class CheckoutController extends Controller
if($data['txaction'] == 'paid'){
$shopping_order->paid = true;
$shopping_order->save();
//if product has actions
if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){
foreach($shopping_order->shopping_order_items as $shopping_order_item){
if($shopping_order_item->product){
if($shopping_order_item->product->action){
$user = User::findOrFail($shopping_order->auth_user_id);
foreach ($shopping_order_item->product->action as $do){
if($shopping_order_item->product->getActionName($do) == 'payment_for_account'){
$user->payment_account = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
if($shopping_order_item->product->getActionName($do) == 'payment_for_shop'){
$user->payment_shop = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
$user->save();
}
}
}
}
}
}
if($data['txaction'] == 'appointed'){
@ -321,6 +380,7 @@ class CheckoutController extends Controller
$data = [
'shopping_user_id' => $shopping_user->id,
'auth_user_id' => $shopping_user->auth_user_id,
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'user_shop_id' => $user_shop->id,
'total' => Yard::instance('shopping')->total(2, '.', ','),

View file

@ -26,8 +26,8 @@ class SiteController extends Controller
$products = ['aloe-vera-gel-99', 'aloe-vera-saft-500-ml', 'aloe-vera-lippenbalsam'];
$set_products = ['aloe-vera-cleaner-set', 'aloe-vera-koerper-set', 'aloe-vera-repair-set'];
$data = [
'products' => Product::whereIn('slug', $products)->get(),
'set_products' => Product::whereIn('slug', $set_products)->get(),
'products' => Product::whereIn('slug', $products)->where('active', true)->where('show_at', '<=', 1)->get(),
'set_products' => Product::whereIn('slug', $set_products)->where('active', true)->where('show_at', '<=', 1)->get(),
'user_shop' => Util::getUserShop(),
];
return view('web.index', $data);
@ -36,12 +36,12 @@ class SiteController extends Controller
public function site($site, $subsite = false, $product_slug = false)
{
$subsite = trim($subsite, '/');
$product_slug = trim($product_slug, '/');
$subsite = trim($subsite, '/');
$product_slug = trim($product_slug, '/');
if($product_slug){
$category = Category::where('slug', $subsite)->where('active', true)->first();
$product = Product::where('slug', $product_slug)->where('active', true)->first();
$product = Product::where('slug', $product_slug)->where('active', true)->where('show_at', '<=', 1)->first();
if ($category && $product) {
$data = [
@ -49,7 +49,7 @@ class SiteController extends Controller
'subsite' => $subsite,
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
'product' => $product,
'p_count' => Product::where('active', true)->count(),
'p_count' => Product::where('active', true)->where('show_at', '<=', 1)->count(),
];
return view('web.templates.produkte-show', $data);
@ -57,7 +57,6 @@ class SiteController extends Controller
}
if($site == 'produkte'){
if($subsite || $subsite != 'alle-produkte') {
$category = Category::where('slug', $subsite)->where('active', true)->first();
if ($category) {
@ -68,8 +67,8 @@ class SiteController extends Controller
'products' => Product::whereHas('categories', function ($query) use ($category) {
$query->where('category_id', '=', $category->id);
})->where('active', true)->orderBy('pos', 'DESC')->get(),
'p_count' => Product::where('active', true)->count(),
})->where('active', true)->where('show_at', '<=', 1)->orderBy('pos', 'DESC')->get(),
'p_count' => Product::where('active', true)->where('show_at', '<=', 1)->count(),
];
return view('web.templates.' . $site, $data);
@ -80,8 +79,8 @@ class SiteController extends Controller
'user_shop' => Util::getUserShop(),
'subsite' => 'alle-produkte',
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->orderBy('pos', 'ASC')->get(),
'p_count' => Product::where('active', true)->count(),
'products' => Product::where('active', true)->where('show_at', '<=', 1)->orderBy('pos', 'ASC')->get(),
'p_count' => Product::where('active', true)->where('show_at', '<=', 1)->count(),
];
return view('web.templates.'.$site, $data);
}

View file

@ -0,0 +1,199 @@
<?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]));
}
}
}