Berater Bestellungen
This commit is contained in:
parent
a5db985ae8
commit
bde1095014
26 changed files with 1524 additions and 577 deletions
|
|
@ -4,12 +4,14 @@
|
|||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\Payment;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
|
||||
class OrderController extends Controller
|
||||
|
|
@ -17,10 +19,9 @@ class OrderController extends Controller
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.shop');
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
|
|
@ -47,22 +48,23 @@ class OrderController extends Controller
|
|||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
|
||||
/*if (Request::isMethod('post')) {
|
||||
$data = Request::all();
|
||||
if($data['switchers-radio-is-for'] === 'is-for-member'){
|
||||
return redirect(route('user_order_my_list', ['me']));
|
||||
}
|
||||
if($data['switchers-radio-is-for'] === 'is-for-customer'){
|
||||
//check ist customer
|
||||
return redirect(route('user_order_my_list', ['ot', $id]));
|
||||
}
|
||||
}*/
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
if($for === 'ot'){
|
||||
$shopping_user = $this->checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
if(!$this->checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')){
|
||||
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
}
|
||||
|
||||
if(Request::get('action') === 'next'){
|
||||
Yard::instance('shopping')->destroy();
|
||||
if(Request::get('switchers-radio-is-for') === 'ot'){
|
||||
$delivery_id = $id;
|
||||
}
|
||||
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
@ -78,19 +80,26 @@ class OrderController extends Controller
|
|||
public function list($for, $id=null)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
|
||||
if($for === 'ot'){
|
||||
$shopping_user = $this->checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
}
|
||||
//$data = Request::all();
|
||||
//dd(session('switchers-radio-is-for'));
|
||||
//$shopping_user = new ShoppingUser();
|
||||
//$shopping_user->id = "new";
|
||||
//$shopping_user->same_as_billing = true;
|
||||
$shipping_country_id = $this->checkShoppingCountry($for, $id);
|
||||
if(!$shipping_country_id){
|
||||
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
|
||||
|
||||
$comp_products = null;
|
||||
if($for === 'me'){
|
||||
$comp_products = Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
|
||||
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'user' => $user,
|
||||
|
|
@ -98,11 +107,129 @@ class OrderController extends Controller
|
|||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'delivery_id' => $delivery_id,
|
||||
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
return view('user.order.list', $data);
|
||||
}
|
||||
|
||||
public function payment($for, $id=null){
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
$user = User::find(Auth::user()->id);
|
||||
$rules = array(
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_state' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
||||
// Yard::instance('shopping')->destroy();
|
||||
|
||||
return back()->withInput(Request::all());
|
||||
|
||||
if($for === 'ot' && $id){
|
||||
dd($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
if($user->same_as_billing){
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
}
|
||||
if($for === 'ot' && $id){
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->same_as_billing){
|
||||
$country_id = $shopping_user->billing_country_id;
|
||||
}else{
|
||||
$country_id = $shopping_user->shipping_country_id;
|
||||
}
|
||||
}
|
||||
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkShoppingUser($id, $user){
|
||||
if($id === null){
|
||||
abort(403, 'Error: Keine User ID');
|
||||
|
|
@ -129,27 +256,22 @@ class OrderController extends Controller
|
|||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('add_card', function (Product $product) {
|
||||
return '<a href="#" class="btn btn-sm btn-md-extra btn-secondary">
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith().'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</a>';
|
||||
|
||||
/*'<a href="javascript:void(0)" class="btn btn-secondary btn-sm my-1 mx-2">
|
||||
<i class="ion ion-md-add"></i> <i class="ion ion-md-basket"></i>
|
||||
</a><br>
|
||||
<a href="javascript:void(0)" class="btn btn-outline-secondary btn-sm my-1 mx-2">
|
||||
<i class="ion ion-md-remove"></i> <i class="ion ion-md-basket"></i>
|
||||
</a>'*/;
|
||||
</button>';
|
||||
})
|
||||
->addColumn('quantity', function (Product $product) {
|
||||
//return '<input type="text" class="form-control text-center" value="0" style="width: 4em">';
|
||||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<div class="no-line-break input-group-min-w">
|
||||
<div class="input-group d-inline-flex w-auto">
|
||||
<span class="input-group-prepend">
|
||||
<button class="btn btn-secondary icon-btn md-btn-extra" type="button">-</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control text-center input-extra" value="0">
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
|
||||
<span class="input-group-append">
|
||||
<button class="btn btn-secondary icon-btn md-btn-extra" type="button">+</button>
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
|
|
@ -161,22 +283,27 @@ class OrderController extends Controller
|
|||
}
|
||||
return "";
|
||||
})
|
||||
->addColumn('price', function (Product $product) {
|
||||
return $product->getFormattedPriceWith();
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(true, true). " €";
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, true). " €";
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, false). " €";
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price', 'price $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price_vk_gross $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
->rawColumns(['add_card', 'quantity', 'picture', 'action'])
|
||||
|
|
@ -184,4 +311,82 @@ class OrderController extends Controller
|
|||
}
|
||||
|
||||
|
||||
public function performRequest(){
|
||||
|
||||
if(Request::ajax()) {
|
||||
$data = Request::all();
|
||||
if($data['action'] === 'updateCart' && isset($data['product_id'])){
|
||||
if($product = Product::find($data['product_id'])){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
//get the card item
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(false, true), ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points]);
|
||||
Yard::setTax($cartItem->rowId, $product->tax);
|
||||
|
||||
if(isset($data['qty']) && $data['qty'] > 0){
|
||||
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
|
||||
}else{
|
||||
//if 0 get the item by qty:1 and remove it
|
||||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
}
|
||||
$this->updateCompProduct($data);
|
||||
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html'=>'']);
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'updateShippingCountry') {
|
||||
if(isset($data['shipping_country_id'])){
|
||||
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot';
|
||||
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$this->updateCompProduct($data);
|
||||
}
|
||||
}
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
|
||||
}
|
||||
if($data['action'] === 'updateCompProduct'){
|
||||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$html = view("user.order.yard_view_form", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html'=>$html]);
|
||||
|
||||
}
|
||||
return response()->json(['response' => false, 'data'=>$data]);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateCompProduct($data){
|
||||
//clear old
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
if($row->options->comp) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
}
|
||||
if(isset($data['comp_product_id'])) {
|
||||
if ($product = Product::find($data['comp_product_id'])) {
|
||||
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, ['image' => $image, 'slug' => $product->slug, 'weight' => 0, 'points' => 0, 'comp' => $product->id]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue