diff --git a/app/Http/Controllers/designer/DesignerController.php b/app/Http/Controllers/designer/DesignerController.php index ed27076..f5c6928 100755 --- a/app/Http/Controllers/designer/DesignerController.php +++ b/app/Http/Controllers/designer/DesignerController.php @@ -470,7 +470,7 @@ class DesignerController extends Controller { $newDesignerModel = new DesignerModel; $post = $request->all(); $clientId = Auth::user()->id; - $design_name = $post['design_name']; + $design_name = str_replace(array("\r", "\n"), '', $post['design_name']); $tempDecode = json_decode($_POST['templateDetails']); $getTemPlateCode = $tempDecode[0]->templateCode; diff --git a/app/Http/Controllers/paypal/PaypalController.php b/app/Http/Controllers/paypal/PaypalController.php index b7b16fb..049bcfa 100755 --- a/app/Http/Controllers/paypal/PaypalController.php +++ b/app/Http/Controllers/paypal/PaypalController.php @@ -30,7 +30,7 @@ class PaypalController extends Controller public function __construct() { - $paypal_env = "live"; + $paypal_env = "sandbox"; $paypal_apiUrl = 'https://api.paypal.com'; // default if ($paypal_env == 'live') { @@ -323,7 +323,7 @@ class PaypalController extends Controller ); $m->updateVoucherValueInCart($data, $item_id); - } else { + } else if ($voucher[0]->VoucherType == "Percentage") { $data = array( 'Price' => round($totalValue * -1, 2) ); @@ -333,6 +333,8 @@ class PaypalController extends Controller // 'totalValue' => $totalValue, // 'type' => 'Flat' // ); + } else if ($voucher[0]->VoucherType == "Shipping") { + return $shippingFee = 0; } } // var_dump($item->ShippingCostId); diff --git a/app/Http/Controllers/teamstore/TeamStoreController.php b/app/Http/Controllers/teamstore/TeamStoreController.php index ed6b264..116ae63 100755 --- a/app/Http/Controllers/teamstore/TeamStoreController.php +++ b/app/Http/Controllers/teamstore/TeamStoreController.php @@ -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 { diff --git a/resources/views/merchbay/cart.blade.php b/resources/views/merchbay/cart.blade.php index 71a844c..c94566a 100755 --- a/resources/views/merchbay/cart.blade.php +++ b/resources/views/merchbay/cart.blade.php @@ -349,7 +349,7 @@ {{ number_format($tax['order_grandtotal'], 2) . ' ' . $store_array[0]->StoreCurrency }}
Shipping Fee: - {{ number_format($shipping_fee, 2) . ' ' . $store_array[0]->StoreCurrency }} + {{ number_format($shipping_fee, 2) }} {{ $store_array[0]->StoreCurrency }}
Tax: {{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }} diff --git a/resources/views/merchbay_main.blade.php b/resources/views/merchbay_main.blade.php index 65c4342..d0362d0 100755 --- a/resources/views/merchbay_main.blade.php +++ b/resources/views/merchbay_main.blade.php @@ -471,6 +471,7 @@ form.validate().resetForm(); form[0].reset(); $('#my_subtotal').text(response.subtotal); + $('#shippingFee').text(response.shippingFee); } else { $("#error_voucher").html(response.message).fadeIn().delay(5000).fadeOut('slow',