cart responsive, Checkout from cart

This commit is contained in:
Kevin Adametz 2020-08-14 18:32:41 +02:00
parent bde1095014
commit fb27009339
17 changed files with 501 additions and 319 deletions

View file

@ -90,6 +90,7 @@ class CustomerController extends Controller
if(old('switcher-without-email') === 'true'){
$step = 1;
$shopping_user->same_as_billing = true;
$shopping_user->faker_mail = true;
$billing_email = time()."@faker-mivita.care";
}
}
@ -170,6 +171,7 @@ class CustomerController extends Controller
}
}
$data['faker_mail'] = isset($data['faker_mail']) ? true : false;
$data['has_buyed'] = isset($data['has_buyed']) ? true : false;
$data['subscribed'] = isset($data['subscribed']) ? true : false;
//subscribed can only true when has_buyed ist active

View file

@ -5,8 +5,11 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\Product;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;
use App\Models\UserHistory;
use App\Services\Util;
use App\User;
use Auth;
use Request;
@ -113,7 +116,6 @@ class OrderController extends Controller
}
public function payment($for, $id=null){
$data = Request::all();
$user = User::find(Auth::user()->id);
@ -131,79 +133,39 @@ class OrderController extends Controller
return back()->withErrors($validator)->withInput(Request::all());
}
if($for === 'me'){
if(Request::get('switchers-comp-product')) {
$product = Product::find(Request::get('switchers-comp-product'));
Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, ['image' => '', 'slug' => $product->slug, 'weight' => 0]);
}
do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
$data['is_from'] = 'user_order';
$data['is_for'] = $for;
$data['shopping_user_id'] = $id;
unset($data['quantity']);
unset($data['_token']);
}
// Yard::instance('shopping')->destroy();
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => 1, //is first faker shop for buy intern
'auth_user_id' => Auth::user()->id,
'payment' => 2, //Berater Shop
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'shopping_data' => $data,
'back' => url()->previous(),
return back()->withInput(Request::all());
if($for === 'ot' && $id){
dd($data);
}
]);
Yard::instance('shopping')->store($identifier);
Yard::instance('shopping')->destroy();
$product = Product::find(Request::get('switchers-package-wizard'));
$showAboOptions = false;
if(Request::get('abo_options')){
$showAboOptions = true;
$user->abo_options = true;
$user->save();
}
//add to DB
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'user_order_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier, 'abo_options'=>0]);
//$path = str_replace('http', 'https', $path);
return redirect()->secure($path);
if($product && $product->active && $product->show_at == 3){
//set membership product
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
}
//set onboarding products
if(Request::get('products_on_board')){
foreach (Request::get('products_on_board') as $product_on_board_id){
$product_on_board = Product::find($product_on_board_id);
$image = "";
if($product_on_board->images->count()){
$image = $product_on_board->images->first()->slug;
}
Yard::instance('shopping')->add($product_on_board->id, $product_on_board->getLang('name'), 1, $product_on_board->price, ['image' => $image, 'slug' => $product_on_board->slug, 'weight' => $product_on_board->weight]);
}
}
do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => 1, //is first faker shop for buy intern
'auth_user_id' => Auth::user()->id,
'payment' => 4, //Berater Wizard
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
]);
Yard::instance('shopping')->store($identifier);
//add to DB
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
UserHistory::create(['user_id' => $user->id, 'action'=>'wizard_payment', 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
//$path = str_replace('http', 'https', $path);
return redirect()->secure($path);
}
\Session()->flash('alert-error', "Fehler beim Produkt");
return back();
}
private function checkShoppingCountry($for, $id=null){
$country_id = null;
if($for === 'me'){
$user = User::find(\Auth::user()->id);

View file

@ -101,12 +101,17 @@ class CardController extends Controller
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
$data = [];
$data['is_from'] = 'shopping';
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => $user_shop->id,
'payment' => 1,
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'shopping_data' => $data,
'back' => url()->previous(),
]);
Yard::instance('shopping')->store($identifier);

View file

@ -37,31 +37,117 @@ class CheckoutController extends Controller
public function checkout(){
// dd("back");
// $user_shop = Util::getUserShop();
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
$is_from = isset($shopping_data['is_from']) ? $shopping_data['is_from'] : 'shopping';
$is_for = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : false;
$shopping_user = null;
if($shopping_data && $is_from !== 'shopping'){
//$shopping_user_id = isset($shopping_data['shopping_user_id']) ? $shopping_data['shopping_user_id'] : false;
$shopping_user = $this->shoppingUserAuthData($is_from, $is_for, $shopping_data);
}elseif($is_from === 'shopping') {
$shopping_user = new ShoppingUser();
$shopping_user->is_for = $is_for;
$shopping_user->is_from = $is_from;
}
if(Request::get('selected_country')){
Yard::instance('shopping')->setShippingCountryWithPrice(Request::get('selected_country'));
//Yard::instance('shopping')->setShippingCountryWithPrice(Request::get('selected_country'), $is_for);
}else{
$shopping_user->billing_state = Yard::instance('shopping')->getShippingCountryId();
$shopping_user->shipping_state = Yard::instance('shopping')->getShippingCountryId();
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
// $selected_country = $ShippingCountry->id;
}
if(!$this->getPayments('shopping_user_id') && Util::getAuthUser()){
$user = Util::getAuthUser();
$user->email;
$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;
//$user->email;
// $shopping_user->save();
// $this->putPayments('shopping_user_id', $shopping_user->id);
}else{
//$shopping_user = ShoppingUser::findOrNew($this->getPayments('shopping_user_id'));
}
if(Util::getAuthUser()){
$shopping_user->abo_options = Util::getUserHistoryValue('abo_options');
//$shopping_user->save();
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = true;
}
$data = [
'is_from' => $is_from,
'is_for' => $is_for,
'user_shop' => Util::getUserShop(),
'shopping_user' => $shopping_user,
'shopping_mode' => Util::getUserShoppingMode(),
];
return view('web.templates.checkout', $data);
}
private function shoppingUserAuthData($is_from, $is_for, $data = []){
$user = Util::getAuthUser();
$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->faker_mail = false;
$shopping_user->accepted_data_checkbox = 1;
$shopping_user->is_for = $is_for;
$shopping_user->is_from = $is_from;
//Lieferadresse
if($is_from === 'user_order'){
if(isset($data['shopping_user_id']) && $data['is_for'] === 'ot'){
$s_user = ShoppingUser::findOrFail($data['shopping_user_id']);
$shopping_user->billing_salutation = $s_user->billing_salutation;
$shopping_user->billing_company = $s_user->billing_company;
$shopping_user->billing_firstname = $s_user->billing_firstname;
$shopping_user->billing_lastname = $s_user->billing_lastname;
$shopping_user->billing_address = $s_user->billing_address;
$shopping_user->billing_address_2 = $s_user->billing_address_2;
$shopping_user->billing_zipcode = $s_user->billing_zipcode;
$shopping_user->billing_city = $s_user->billing_city;
$shopping_user->billing_country_id = $s_user->billing_country_id;
$shopping_user->billing_phone = $s_user->billing_phone;
$shopping_user->billing_email = $s_user->billing_email;
$shopping_user->faker_mail = $s_user->faker_mail;
$shopping_user->shopping_user_id = $data['shopping_user_id'];
$shopping_user->member_id = $s_user->member_id;
}
$shopping_user->same_as_billing = false;
$shopping_user->shipping_salutation = isset($data['shipping_salutation']) ? $data['shipping_salutation'] : '';
$shopping_user->shipping_company = isset($data['shipping_company']) ? $data['shipping_company'] : '';
$shopping_user->shipping_firstname = isset($data['shipping_firstname']) ? $data['shipping_firstname'] : '';
$shopping_user->shipping_lastname = isset($data['shipping_lastname']) ? $data['shipping_lastname'] : '';
$shopping_user->shipping_address = isset($data['shipping_address']) ? $data['shipping_address'] : '';
$shopping_user->shipping_address_2 = isset($data['shipping_address_2']) ? $data['shipping_address_2'] : '';
$shopping_user->shipping_zipcode = isset($data['shipping_zipcode']) ? $data['shipping_zipcode'] : '';
$shopping_user->shipping_city = isset($data['shipping_city']) ? $data['shipping_city'] : '';
$shopping_user->shipping_country_id = isset($data['shipping_state']) ? $data['shipping_state'] : '';
$shopping_user->shipping_phone = isset($data['shipping_phone']) ? $data['shipping_phone'] : '';
}else{
$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;
@ -73,29 +159,28 @@ class CheckoutController extends Controller
$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(Util::getAuthUser()){
$shopping_user->abo_options = Util::getUserHistoryValue('abo_options');
$shopping_user->save();
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = true;
}
$data = [
'user_shop' => Util::getUserShop(),
'shopping_user' => $shopping_user,
'shopping_mode' => Util::getUserShoppingMode(),
];
return view('web.templates.checkout', $data);
return $shopping_user;
}
public function checkoutFinal(){
$data = Request::all();
if(isset($data['selected_country']) && $data['selected_country'] === 'change'){
if(Request::get('same_as_billing')){
Yard::instance('shopping')->setShippingCountryWithPrice($data['billing_state'], $data['is_for']);
}else{
Yard::instance('shopping')->setShippingCountryWithPrice($data['shipping_state'], $data['is_for']);
}
return back()->withInput(Request::all());
}
dd('ads');
$rules = array(
'billing_salutation' => 'required',
'billing_firstname'=>'required',
@ -299,8 +384,6 @@ class CheckoutController extends Controller
private function makeShoppingUser($data){
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
$data['accepted_data_checkbox'] = isset($data['accepted_data_checkbox']) ? true : false;

View file

@ -36,10 +36,17 @@ class Checkout
\Session::put('auth_user', $shopping_instance->auth_user);
}
}
if($shopping_instance->back){
\Session::put('back_link', $shopping_instance->back);
}
Yard::instance('shopping')->destroy();
//restore yard
Yard::instance('shopping')->restore($request->route('identifier'));
Yard::instance('shopping')->setShippingCountryWithPrice($shopping_instance->country_id);
Yard::instance('shopping')->putYardExtra('shopping_data', $shopping_instance->shopping_data);
$is_for = isset($shopping_instance->shopping_data['is_for']) ? $shopping_instance->shopping_data['is_for'] : 'ot';
Yard::instance('shopping')->setShippingCountryWithPrice($shopping_instance->country_id, $is_for);
ShoppingInstance::where('identifier', $request->route('identifier'))->delete();
$request->route()->forgetParameter('identifier');

View file

@ -43,9 +43,10 @@ class ShoppingInstance extends Model
protected $table = 'shopping_instances';
protected $casts = ['shopping_data' => 'array'];
protected $fillable = [
'identifier', 'user_shop_id', 'auth_user_id', 'payment', 'subdomain', 'country_id'
'identifier', 'user_shop_id', 'auth_user_id', 'payment', 'subdomain', 'country_id', 'shopping_data', 'back'
];
public function user_shop()

View file

@ -129,6 +129,7 @@ class ShoppingUser extends Model
'billing_country_id',
'billing_phone',
'billing_email',
'faker_mail',
'accepted_data_checkbox',
'same_as_billing',
'shipping_salutation',
@ -145,6 +146,9 @@ class ShoppingUser extends Model
'subscribed',
'notice',
'mode',
'is_for',
'is_from',
'shopping_user_id',
'wp_order_number',
'wp_order_date',
];
@ -152,6 +156,7 @@ class ShoppingUser extends Model
protected $casts = [
'notice' => 'array',
'is_like' => 'bool',
'faker_mail' => 'bool',
'accepted_data_checkbox' => 'bool',
'same_as_billing' => 'bool',
'has_buyed' => 'bool',

View file

@ -317,4 +317,15 @@ class HTMLHelper
}
return $ret;
}
public static function getOptionRange($select, $from=1, $to=50){
$values = range($from, $to);
$ret = "";
foreach ($values as $value){
$attr = ($value == $select) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value.'" '.$attr.'>'.$value.'</option>\n';
}
return $ret;
}
}

View file

@ -181,7 +181,9 @@ class Util
if(\Session::has('user_shop')){
if(\Session::has('user_shop_domain')){
if(\Session::has('back_link')){
return \Session::get('back_link');
}
if(self::getUserPaymentFor() === 3){
return \Session::get('user_shop_domain')."/user/membership";
}

View file

@ -21,25 +21,26 @@ class Yard extends Cart
private $shipping_is_for;
private $ysession;
private $yinstance;
private $shopping_data = [];
public function __construct(SessionManager $session, Dispatcher $events)
{
$this->ysession = $session;
$this->yinstance = sprintf('%s.%s', 'cart', 'shipping_extras');
if($this->getShippingExtra('shipping_price')){
$this->shipping_price = (float) ($this->getShippingExtra('shipping_price'));
if($this->getYardExtra('shipping_price')){
$this->shipping_price = (float) ($this->getYardExtra('shipping_price'));
}
if($this->getShippingExtra('shipping_tax')){
$this->shipping_tax = (float) ($this->getShippingExtra('shipping_tax'));
if($this->getYardExtra('shipping_tax')){
$this->shipping_tax = (float) ($this->getYardExtra('shipping_tax'));
}
if($this->getShippingExtra('shipping_country_id')){
$this->shipping_country_id = $this->getShippingExtra('shipping_country_id');
if($this->getYardExtra('shipping_country_id')){
$this->shipping_country_id = $this->getYardExtra('shipping_country_id');
}
if($this->getShippingExtra('shipping_is_for')){
$this->shipping_is_for = $this->getShippingExtra('shipping_is_for');
if($this->getYardExtra('shipping_is_for')){
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
}
@ -62,14 +63,14 @@ class Yard extends Cart
return config('cart.tax');
}
public function putShippingExtra($key, $value){
public function putYardExtra($key, $value){
$content = $this->getYContent();
$content->put($key, $value);
$this->ysession->put($this->yinstance, $content);
}
public function getShippingExtra($key){
public function getYardExtra($key){
$content = $this->getYContent();
if ($content->has($key)){
return $content->get($key);
@ -116,10 +117,10 @@ class Yard extends Cart
public function setShippingCountryWithPrice($shipping_country_id, $shipping_is_for = 'ot')
{
$this->shipping_country_id = $shipping_country_id;
$this->putShippingExtra('shipping_country_id', $shipping_country_id);
$this->putYardExtra('shipping_country_id', $shipping_country_id);
$this->shipping_is_for = $shipping_is_for;
$this->putShippingExtra('shipping_is_for', $shipping_is_for);
$this->putYardExtra('shipping_is_for', $shipping_is_for);
$this->calculateShippingPrice();
@ -160,10 +161,10 @@ class Yard extends Cart
$this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2);
$this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2);
$this->putShippingExtra('shipping_price', $this->shipping_price);
$this->putShippingExtra('shipping_tax_rate', $this->shipping_tax_rate);
$this->putShippingExtra('shipping_tax', $this->shipping_tax);
$this->putShippingExtra('shipping_price_net', $this->shipping_price_net);
$this->putYardExtra('shipping_price', $this->shipping_price);
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
$this->putYardExtra('shipping_tax', $this->shipping_tax);
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
}
}