Promotion Frontend dynamic

This commit is contained in:
Kevin Adametz 2021-11-26 18:23:10 +01:00
parent c9e1545693
commit 1cc8e025a1
29 changed files with 551 additions and 163 deletions

View file

@ -91,7 +91,6 @@ class PromotionController extends Controller
public function load(){
$data = Request::all();
if(Request::ajax()) {
if(isset($data['action']) && $data['action'] === 'validate_url'){
$rules = array(

View file

@ -9,6 +9,7 @@ use App\Services\Util;
use App\Models\Product;
use App\Models\PaymentMethod;
use App\Models\PromotionUser;
use App\Services\PromotionCart;
use App\Http\Controllers\Controller;
@ -31,16 +32,16 @@ class PromotionController extends Controller
if(!$PromotionUser){
abort(402);
}
if($PromotionUser->checkOutOfStock()){
if(!$PromotionUser->promotion_admin->isActive() || $PromotionUser->checkOutOfStock()){
$data = [
'promotion_user' => $PromotionUser,
];
return view('web.promotion.outofstock', $data);
}
PromotionCart::initYard();
$data = [
'promotion_user' => $PromotionUser,
'shop_products' => Product::where('active', true)->whereJsonContains('show_on', ['1', '2', '3'])->orderBy('pos', 'ASC')->get(),
'shop_products' => Product::where('active', true)->whereJsonContains('show_on', ['3'])->orderBy('pos', 'ASC')->get(),
'user_payment_methods' => PaymentMethod::getDefaultAsArray()->toArray(),
];
return view('web.promotion.index', $data);
@ -93,6 +94,32 @@ class PromotionController extends Controller
$product = Product::find($data['id']); //current user form order
$ret = view("web.promotion.show_product", compact('product', 'data'))->render();
}
if($data['action'] === 'switch-free-product'){
\App\Services\PromotionCart::updateFeeProduct($data);
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
if($data['action'] === 'add-shop-product'){
$data['qty'] = \App\Services\PromotionCart::updateProduct($data, true);
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
if($data['action'] === 'update-shop-product'){
$data['qty'] = \App\Services\PromotionCart::updateProduct($data);
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
if($data['action'] === 'remove-shop-product'){
\App\Services\PromotionCart::updateProduct($data);
$data['qty'] = 0;
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
if($data['action'] === 'clear-cart'){
\App\Services\PromotionCart::clearCart($data);
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
if($data['action'] === 'switch-shipping'){
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
}