API Shopping Order backend
This commit is contained in:
parent
7a040c3e19
commit
d01b4bd560
24 changed files with 1584 additions and 34 deletions
|
|
@ -26,7 +26,7 @@ class ShoppingUserController extends Controller
|
|||
|
||||
|
||||
protected $successStatus = 200;
|
||||
protected $member_id = 3; //thomas.krummel@gmail.com
|
||||
protected $member_id = 3; //service@aloe-vera.bio
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -363,12 +363,12 @@ class ShoppingUserController extends Controller
|
|||
$wp_advertising = isset($request->wp_advertising) ? $request->wp_advertising : '';
|
||||
$wp_incentives = isset($request->wp_incentives) ? $request->wp_incentives : '';
|
||||
|
||||
$wp_notice = [
|
||||
$api_notice = [
|
||||
'wp_advertising' => $wp_advertising,
|
||||
'wp_incentives' => $wp_incentives,
|
||||
];
|
||||
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path, $wp_notice);
|
||||
$wp_order = $this->prepareOrder($wp_order, $shopping_user, $wp_invoice_path, $api_notice);
|
||||
|
||||
if ($wp_order){
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
|
|
@ -573,7 +573,7 @@ class ShoppingUserController extends Controller
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $wp_notice){
|
||||
private function prepareOrder($wp_shopping_order, $shopping_user, $wp_invoice_path, $api_notice){
|
||||
Yard::instance('shopping')->destroy();
|
||||
$ret = [];
|
||||
|
||||
|
|
@ -593,7 +593,8 @@ class ShoppingUserController extends Controller
|
|||
if ($order->price != ($product->price * 100)) {
|
||||
$error[] = "different price: " . ($product->price * 100);
|
||||
}
|
||||
Yard::instance('shopping')->add($product->id, $product->name, (int) $order->qty, $product->price, false, false, ['image' => [], 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission]);
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->name, (int) $order->qty, $product->price, false, false, ['image' => [], 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission]);
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith());
|
||||
}
|
||||
}
|
||||
$order->message = $error;
|
||||
|
|
@ -604,7 +605,7 @@ class ShoppingUserController extends Controller
|
|||
if($ShippingCountry){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($ShippingCountry->id);
|
||||
}
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice);
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user, $wp_invoice_path, $api_notice);
|
||||
$this->orderStatusSendMail($shopping_order);
|
||||
|
||||
$shopping_user->shopping_order = $shopping_order;
|
||||
|
|
@ -613,7 +614,7 @@ class ShoppingUserController extends Controller
|
|||
return $ret;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $wp_notice){
|
||||
private function makeShoppingOrder($shopping_user, $wp_invoice_path, $api_notice){
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
|
|
@ -634,7 +635,8 @@ class ShoppingUserController extends Controller
|
|||
'paid' => true,
|
||||
'txaction' => 'extern',
|
||||
'wp_invoice_path' => $wp_invoice_path,
|
||||
'wp_notice' => $wp_notice,
|
||||
'api_notice' => $api_notice,
|
||||
'api_status' => 0,
|
||||
'mode' => $shopping_user->mode,
|
||||
];
|
||||
$shopping_order = $shopping_user->shopping_order;
|
||||
|
|
|
|||
|
|
@ -53,11 +53,27 @@ class ModalController extends Controller
|
|||
$ret = view("admin.modal.show_product", compact('product', 'data'))->render();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if($data['action'] === 'shop-user-order-detail'){
|
||||
|
||||
$user = \Auth::user();
|
||||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
if($shopping_order->member_id !== $user->id){
|
||||
abort(404);
|
||||
}
|
||||
$isAdmin = false;
|
||||
$ret = view("user.shop.sales.modal_api_order_detail", compact('shopping_order', 'isAdmin', 'data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'user-order-my-delivery-show'){
|
||||
$user = \Auth::user();
|
||||
$ret = view("admin.modal.show_user_customers", compact('user', 'data'))->render();
|
||||
}
|
||||
|
||||
|
||||
if($data['action'] === 'user-order-my-delivery-add'){
|
||||
$user = \Auth::user();
|
||||
|
||||
|
|
|
|||
180
app/Http/Controllers/User/ShopApiController.php
Normal file
180
app/Http/Controllers/User/ShopApiController.php
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Repositories\ShopApiRepository;
|
||||
|
||||
|
||||
class ShopApiController extends Controller
|
||||
{
|
||||
|
||||
private $api_action = [0 => 'bitte wählen', 'order' => 'markierte bestellen', 'remove' => 'markierte entfernen', 'reset' => 'markierte zurücksetzen/offen'];
|
||||
private $filter_show = [10 => 'alle anzeigen', 1 => 'offen', 2 => 'bestellt', 5 => 'entfernt'];
|
||||
protected $shopApiRepository;
|
||||
|
||||
public function __construct(ShopApiRepository $shopApiRepository)
|
||||
{
|
||||
$this->middleware('active.shop');
|
||||
$this->shopApiRepository = $shopApiRepository;
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$data = [
|
||||
'api_action' => $this->api_action,
|
||||
'filter_show' => $this->filter_show,
|
||||
];
|
||||
return view('user.shop.sales.api_orders', $data);
|
||||
}
|
||||
|
||||
public function action(){
|
||||
$data = Request::all();
|
||||
|
||||
if(isset($data['user_shop_api_orders_action'])){
|
||||
switch($data['user_shop_api_orders_action']){
|
||||
case 'order':
|
||||
$shopApiOrderCart = $this->shopApiRepository->order($data);
|
||||
|
||||
/*$user = User::find(Auth::user()->id);
|
||||
$shipping_country = ShippingCountry::whereCountryId($user->account->country_id)->first();
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country->id);*/
|
||||
|
||||
//card_info = UserService::getYardInfo();
|
||||
return view('user.shop.sales.api_order_list', compact('shopApiOrderCart', 'data'));
|
||||
break;
|
||||
case 'remove':
|
||||
$this->shopApiRepository->remove($data);
|
||||
break;
|
||||
case 'reset':
|
||||
$this->shopApiRepository->reset($data);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return redirect(route('user_shop_api_orders'));
|
||||
}
|
||||
|
||||
public function checkout(){
|
||||
|
||||
$data = Request::all();
|
||||
$shopApiOrderCart = $this->shopApiRepository->checkout($data);
|
||||
//TODO store in ShopApiOrderCart
|
||||
//TO checkout
|
||||
dd($shopApiOrderCart);
|
||||
|
||||
|
||||
return redirect(route('user_shop_api_orders'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
if(!session('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => 1]);
|
||||
}
|
||||
if(Request::get('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => Request::get('user_shop_api_orders_filter')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function initSearch($archive = false, $request = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')
|
||||
->where('shopping_orders.member_id', $user->id)
|
||||
->where('shopping_orders.payment_for', 7); //7 payment for extern
|
||||
|
||||
|
||||
if(Request::get('user_shop_api_orders_filter')){
|
||||
if(Request::get('user_shop_api_orders_filter') < 10){
|
||||
if(Request::get('user_shop_api_orders_filter') == 1){
|
||||
$query->where(function($query) {
|
||||
return $query->where('shopping_orders.api_status', 0)
|
||||
->orWhere('shopping_orders.api_status', 1)
|
||||
->orWhereNull('shopping_orders.api_status');
|
||||
});
|
||||
}else{
|
||||
$query->where('shopping_orders.api_status', Request::get('user_shop_api_orders_filter'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function ordersDatatable(){
|
||||
|
||||
$query = $this->initSearch();
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn icon-btn btn-sm btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="'.route('modal_load').'"><span class="far fa-eye"></span></button>';
|
||||
})
|
||||
->addColumn('api_status', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getAPIStatusColor().'">'.$ShoppingOrder->getAPIStatusType().'</span>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
|
||||
->addColumn('api_action', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<label class="custom-control custom-checkbox m-0">
|
||||
<input type="checkbox" class="custom-control-input" name="api_action_list['.$ShoppingOrder->id.']" id="api_action_list_'.$ShoppingOrder->id.'">
|
||||
<span class="custom-control-label"></span>
|
||||
</label>';
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
})
|
||||
->addColumn('orders', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getPaymentForColor().'">'.$ShoppingOrder->getPaymentForType().'</span>';
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>
|
||||
';
|
||||
})
|
||||
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('api_action', 'id $1')
|
||||
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('user_shop_id', 'user_shop_id $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
|
||||
->rawColumns(['id', 'api_status', 'txaction', 'user_shop_id', 'api_action', 'shipped', 'total_shipping', 'payment_for'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ class ShopSalesController extends Controller
|
|||
public function ordersDatatable(){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('member_id', $user->id);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.member_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
|
|
@ -64,19 +64,21 @@ class ShopSalesController extends Controller
|
|||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getPaymentForColor().'">'.$ShoppingOrder->getPaymentForType().'</span>';
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>
|
||||
';
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('user_shop_id', 'user_shop_id $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
|
||||
|
||||
->rawColumns(['id', 'txaction', 'user_shop_id', 'total_shipping', 'invoice', 'payment_for'])
|
||||
->rawColumns(['id', 'txaction', 'user_shop_id', 'total_shipping', 'invoice', 'shipped', 'payment_for'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue