added shipping fee voucher code
This commit is contained in:
@@ -710,19 +710,20 @@ class TeamStoreController extends Controller
|
||||
|
||||
$getVoucher = $TeamStoreModel->selectVoucher($data);
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($getVoucher) {
|
||||
$items = $TeamStoreModel->myCart($cartKey);
|
||||
|
||||
// check if if voucher is already in used;
|
||||
foreach ($items as $item) {
|
||||
|
||||
if( $item->VoucherId) {
|
||||
if ($item->VoucherId) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'You can only apply one voucher per order.'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
if ($getVoucher[0]->Id == $item->VoucherId) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
@@ -770,6 +771,33 @@ class TeamStoreController extends Controller
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if ($getVoucher[0]->VoucherType === "Shipping") {
|
||||
|
||||
if (Auth::guest()) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'Log-in first to use this voucher.',
|
||||
));
|
||||
}
|
||||
|
||||
$userId = Auth::user()->id;
|
||||
// $isUsed = $TeamStoreModel->checkVoucher($userId, $getVoucher[0]->Id);
|
||||
|
||||
if ($getVoucher[0]->UserId != $userId) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'Invalid voucher.',
|
||||
));
|
||||
}
|
||||
|
||||
// if ($getSubtotal[0]->Subtotal <= $getVoucher[0]->VoucherValue) {
|
||||
// return response()->json(array(
|
||||
// 'success' => false,
|
||||
// 'message' => 'Please add another item to redeem this voucher.',
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// insert vocuher to cart_tmp
|
||||
@@ -806,11 +834,17 @@ class TeamStoreController extends Controller
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Percentage'
|
||||
);
|
||||
} else {
|
||||
} else if ($voucher->VoucherType == "Flat") {
|
||||
$voucherData = array(
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Flat'
|
||||
);
|
||||
} else {
|
||||
$voucherData = array(
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Shipping'
|
||||
);
|
||||
$shippingFee = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -819,8 +853,10 @@ class TeamStoreController extends Controller
|
||||
$getPercentageValue = $voucherData['totalValue'] / 100;
|
||||
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
|
||||
} else {
|
||||
} else if ($voucherData['type'] == "Flat") {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
}
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
@@ -845,6 +881,7 @@ class TeamStoreController extends Controller
|
||||
return response()->json(array(
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'shippingFee' => number_format($shippingFee, 2),
|
||||
'subtotal' => number_format($finalSubTotal + $shippingFee + $tax["tax"], 2)
|
||||
));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user