added shipping fee voucher code

This commit is contained in:
franknstayn
2022-02-26 20:20:43 +08:00
parent c15e614c3e
commit b25f55dbdd
5 changed files with 48 additions and 8 deletions

View File

@@ -470,7 +470,7 @@ class DesignerController extends Controller {
$newDesignerModel = new DesignerModel; $newDesignerModel = new DesignerModel;
$post = $request->all(); $post = $request->all();
$clientId = Auth::user()->id; $clientId = Auth::user()->id;
$design_name = $post['design_name']; $design_name = str_replace(array("\r", "\n"), '', $post['design_name']);
$tempDecode = json_decode($_POST['templateDetails']); $tempDecode = json_decode($_POST['templateDetails']);
$getTemPlateCode = $tempDecode[0]->templateCode; $getTemPlateCode = $tempDecode[0]->templateCode;

View File

@@ -30,7 +30,7 @@ class PaypalController extends Controller
public function __construct() public function __construct()
{ {
$paypal_env = "live"; $paypal_env = "sandbox";
$paypal_apiUrl = 'https://api.paypal.com'; // default $paypal_apiUrl = 'https://api.paypal.com'; // default
if ($paypal_env == 'live') { if ($paypal_env == 'live') {
@@ -323,7 +323,7 @@ class PaypalController extends Controller
); );
$m->updateVoucherValueInCart($data, $item_id); $m->updateVoucherValueInCart($data, $item_id);
} else { } else if ($voucher[0]->VoucherType == "Percentage") {
$data = array( $data = array(
'Price' => round($totalValue * -1, 2) 'Price' => round($totalValue * -1, 2)
); );
@@ -333,6 +333,8 @@ class PaypalController extends Controller
// 'totalValue' => $totalValue, // 'totalValue' => $totalValue,
// 'type' => 'Flat' // 'type' => 'Flat'
// ); // );
} else if ($voucher[0]->VoucherType == "Shipping") {
return $shippingFee = 0;
} }
} }
// var_dump($item->ShippingCostId); // var_dump($item->ShippingCostId);

View File

@@ -710,13 +710,14 @@ class TeamStoreController extends Controller
$getVoucher = $TeamStoreModel->selectVoucher($data); $getVoucher = $TeamStoreModel->selectVoucher($data);
$now = Carbon::now(); $now = Carbon::now();
if ($getVoucher) { if ($getVoucher) {
$items = $TeamStoreModel->myCart($cartKey); $items = $TeamStoreModel->myCart($cartKey);
// check if if voucher is already in used; // check if if voucher is already in used;
foreach ($items as $item) { foreach ($items as $item) {
if( $item->VoucherId) { if ($item->VoucherId) {
return response()->json(array( return response()->json(array(
'success' => false, 'success' => false,
'message' => 'You can only apply one voucher per order.' 'message' => 'You can only apply one voucher per order.'
@@ -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 // insert vocuher to cart_tmp
@@ -806,11 +834,17 @@ class TeamStoreController extends Controller
'totalValue' => $totalValue, 'totalValue' => $totalValue,
'type' => 'Percentage' 'type' => 'Percentage'
); );
} else { } else if ($voucher->VoucherType == "Flat") {
$voucherData = array( $voucherData = array(
'totalValue' => $totalValue, 'totalValue' => $totalValue,
'type' => 'Flat' 'type' => 'Flat'
); );
} else {
$voucherData = array(
'totalValue' => $totalValue,
'type' => 'Shipping'
);
$shippingFee = 0;
} }
} }
@@ -819,8 +853,10 @@ class TeamStoreController extends Controller
$getPercentageValue = $voucherData['totalValue'] / 100; $getPercentageValue = $voucherData['totalValue'] / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue); $getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue; $finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
} else { } else if ($voucherData['type'] == "Flat") {
$finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue']; $finalSubTotal = $getSubtotal[0]->Subtotal - $voucherData['totalValue'];
} else {
$finalSubTotal = $getSubtotal[0]->Subtotal;
} }
} else { } else {
$finalSubTotal = $getSubtotal[0]->Subtotal; $finalSubTotal = $getSubtotal[0]->Subtotal;
@@ -845,6 +881,7 @@ class TeamStoreController extends Controller
return response()->json(array( return response()->json(array(
'success' => true, 'success' => true,
'message' => $message, 'message' => $message,
'shippingFee' => number_format($shippingFee, 2),
'subtotal' => number_format($finalSubTotal + $shippingFee + $tax["tax"], 2) 'subtotal' => number_format($finalSubTotal + $shippingFee + $tax["tax"], 2)
)); ));
} else { } else {

View File

@@ -349,7 +349,7 @@
<small>{{ number_format($tax['order_grandtotal'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small> <small>{{ number_format($tax['order_grandtotal'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small>
</h5> </h5>
<h5>Shipping Fee: <h5>Shipping Fee:
<small>{{ number_format($shipping_fee, 2) . ' ' . $store_array[0]->StoreCurrency }}</small> <small> <span id="shippingFee">{{ number_format($shipping_fee, 2) }}</span> {{ $store_array[0]->StoreCurrency }}</small>
</h5> </h5>
<h5>Tax: <h5>Tax:
<small>{{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small> <small>{{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }}</small>

View File

@@ -471,6 +471,7 @@
form.validate().resetForm(); form.validate().resetForm();
form[0].reset(); form[0].reset();
$('#my_subtotal').text(response.subtotal); $('#my_subtotal').text(response.subtotal);
$('#shippingFee').text(response.shippingFee);
} else { } else {
$("#error_voucher").html(response.message).fadeIn().delay(5000).fadeOut('slow', $("#error_voucher").html(response.message).fadeIn().delay(5000).fadeOut('slow',