update flat voucher
This commit is contained in:
@@ -589,19 +589,15 @@ class TeamStoreController extends Controller
|
||||
$m = new TeamStoreModel;
|
||||
$UserModel = new UserModel;
|
||||
$array_address_book = null;
|
||||
|
||||
if(!Auth::guest()){
|
||||
|
||||
if (!Auth::guest()) {
|
||||
$userId = Auth::user()->id;
|
||||
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
|
||||
if (count($array_address_book) <= 0) {
|
||||
$array_address_book = null;
|
||||
}
|
||||
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
|
||||
if (count($array_address_book) <= 0) {
|
||||
$array_address_book = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
$items = $m->myCart($cartKey);
|
||||
$getSubtotal = $m->getSubtotal($cartKey);
|
||||
@@ -651,19 +647,21 @@ class TeamStoreController extends Controller
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
|
||||
} else {
|
||||
//Flat voucher computation here..
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
|
||||
// var_dump($voucherData['totalValue']);
|
||||
}
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
}
|
||||
|
||||
if($cartKey != null) {
|
||||
|
||||
if ($cartKey != null) {
|
||||
$shippingFee = app(\App\Http\Controllers\paypal\PaypalController::class)->getShippingFee($cartKey);
|
||||
$tax = app(\App\Http\Controllers\paypal\PaypalController::class)->getTax($cartKey);
|
||||
}else{
|
||||
} else {
|
||||
$shippingFee = 0;
|
||||
$tax = [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
return view('merchbay.cart')
|
||||
->with('item_group', $items_group)
|
||||
@@ -680,6 +678,7 @@ class TeamStoreController extends Controller
|
||||
public function addVoucher(Request $request)
|
||||
{
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
if ($cartKey == "") {
|
||||
return false;
|
||||
@@ -694,6 +693,14 @@ class TeamStoreController extends Controller
|
||||
$store_array = $TeamStoreModel->selectTeamStore('Id', $grouped_item[0]->StoreId);
|
||||
$getSubtotal = $TeamStoreModel->getSubtotal($cartKey);
|
||||
|
||||
if ($cartKey != null) {
|
||||
$shippingFee = app(\App\Http\Controllers\paypal\PaypalController::class)->getShippingFee($cartKey);
|
||||
$tax = app(\App\Http\Controllers\paypal\PaypalController::class)->getTax($cartKey);
|
||||
} else {
|
||||
$shippingFee = 0;
|
||||
$tax = [];
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'store_id' => $store_id,
|
||||
'voucher' => $vocher
|
||||
@@ -726,6 +733,25 @@ class TeamStoreController extends Controller
|
||||
'message' => 'This voucher has expired.'
|
||||
));
|
||||
}
|
||||
|
||||
if ($getVoucher[0]->VoucherType === "Flat") {
|
||||
|
||||
$isUsed = $TeamStoreModel->checkVoucher($userId, $getVoucher[0]->Id);
|
||||
|
||||
if (count($isUsed) >= 1) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'You already used this voucher.',
|
||||
));
|
||||
}
|
||||
|
||||
if ($getSubtotal[0]->Subtotal <= $getVoucher[0]->VoucherValue) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'Please add more item to redeem this voucher.',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// insert vocuher to cart_tmp
|
||||
@@ -770,12 +796,13 @@ class TeamStoreController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// voucher computation
|
||||
if ($voucherData['type'] == "Percentage") {
|
||||
$getPercentageValue = $voucherData['totalValue'] / 100;
|
||||
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
|
||||
} else {
|
||||
//Flat voucher computation here..
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
|
||||
}
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
@@ -787,6 +814,8 @@ class TeamStoreController extends Controller
|
||||
$offData = $getVoucher[0]->VoucherValue . ' ' . $store_array[0]->StoreCurrency;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$message = '<div class="btn-group mb-2">
|
||||
<button type="button" class="btn btn-black btn-sm dropdown-toggle" data-bs-toggle="dropdown">' . $getVoucher[0]->VoucherCode . ' ' . $offData . ' OFF</button>
|
||||
<ul class="dropdown-menu">
|
||||
@@ -798,7 +827,7 @@ class TeamStoreController extends Controller
|
||||
return response()->json(array(
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'subtotal' => number_format($finalSubTotal, 2)
|
||||
'subtotal' => number_format($finalSubTotal + $shippingFee + $tax["tax"], 2)
|
||||
));
|
||||
} else {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user