add currency for teamstore

This commit is contained in:
Frank John Begornia
2019-08-19 21:37:47 +08:00
parent e60bb3baf8
commit b7e81adf31
68 changed files with 9977 additions and 442 deletions

View File

@@ -278,13 +278,12 @@ class TeamStoreController extends Controller {
$cartKey = $cartKey = $request->session()->get('cartkey');
}
$product_array = $m->selectTeamStoreProducts('Id', $product_id);
$ProductPrice = $product_array[0]->ProductPrice;
$ProductURL = $product_array[0]->ProductURL;
$product_form = $product_array[0]->ProductForm;
$design_code = $product_array[0]->DesignCode;
$product_name = $product_array[0]->ProductName;
$ProductPrice = $product_array[0]->ProductPrice;
$ProductURL = $product_array[0]->ProductURL;
$product_form = $product_array[0]->ProductForm;
$design_code = $product_array[0]->DesignCode;
$product_name = $product_array[0]->ProductName;
if($product_form == "jersey-and-shorts-form"){
$order_names = $post['order_names'];
@@ -412,13 +411,34 @@ class TeamStoreController extends Controller {
'Quantity' => 1
);
}
}elseif($product_form == "name-name2-size-form"){
$order_names = $post['order_names'];
$order_names2 = $post['order_names2'];
$order_size = $post['order_size'];
foreach($order_names as $key => $val){
$items[] = array(
'ProductId' => $product_id,
'StoreURL' => $store_url,
'StoreId' => $store_id,
'FormUsed' => $product_form,
'CartKey' => $cartKey,
'DesignCode' => $design_code,
'ProductURL' => $ProductURL,
'ProductName' => $product_name,
'Name' => $order_names[$key],
'Name2' => $order_names2[$key],
'Size' => $order_size[$key],
'Price' => $ProductPrice,
'Quantity' => 1
);
}
}
$i = $m->insertToCart($items);
if($i){
if($i['i']){
return response()->json(array(
'success' => true
));
@@ -428,25 +448,197 @@ class TeamStoreController extends Controller {
return response()->json(array(
'success' => false,
'message' => "Something went wrong. Please refresh the page."
));
));
}
public function cart(Request $request){
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey);
$items_group = $m->myCartGroup($cartKey);
$items_group = $m->myCartGroup($cartKey);
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
if($grouped_item){
$defId = $grouped_item[0]->StoreId;
}else{
$defId = 0;
}
$item_thumbs = $m->selectDisplayCartThumb();
$store_array = $m->selectTeamStore('Id', $defId);
// var_dump($$grouped_item[0]->StoreId);
$voucherIds = array();
foreach($items as $item){
if($item->VoucherId != null){
$voucherIds[] = $item->VoucherId;
}
}
$vouchers = $m->selectVoucherWhereIn($voucherIds);
$totalValue = 0;
if(!empty($vouchers)){
foreach($vouchers as $voucher){
$totalValue = $totalValue + $voucher->VoucherValue;
if($voucher->VoucherType == "Percentage"){
$voucherData = array(
'totalValue'=> $totalValue,
'type'=>'Percentage'
);
}else{
$voucherData = array(
'totalValue'=> $totalValue,
'type'=>'Flat'
);
}
}
if($voucherData['type'] == "Percentage"){
$getPercentageValue = $voucherData['totalValue'] / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
}else{
//Flat voucher computation here..
}
}else{
$finalSubTotal = $getSubtotal[0]->Subtotal;
}
return view('sublayouts.cart')
->with('item_group', $items_group)
->with('row', $items)
->with('img_thumb', $item_thumbs)
->with('getSubtotal', $getSubtotal);
->with('item_group', $items_group)
->with('row', $items)
->with('img_thumb', $item_thumbs)
->with('getSubtotal', $finalSubTotal)
->with('store_array', $store_array);
}
public function addVoucher(Request $request){
$cartKey = $request->session()->get('cartkey');
if($cartKey == ""){
return false;
}
$TeamStoreModel = new TeamStoreModel;
$post = $request->all();
$grouped_item = $TeamStoreModel->selectTeamStoreGroupByCartKey($cartKey);
$store_id = $grouped_item[0]->StoreId;
$vocher = $post['voucher'];
$store_array = $TeamStoreModel->selectTeamStore('Id', $grouped_item[0]->StoreId);
$getSubtotal = $TeamStoreModel->getSubtotal($cartKey);
$data = array(
'store_id' => $store_id,
'voucher' => $vocher
);
$getVoucher = $TeamStoreModel->selectVoucher($data);
if($getVoucher){
$items = $TeamStoreModel->myCart($cartKey);
// check if if voucher is already in used;
foreach($items as $item){
if($getVoucher[0]->Id == $item->VoucherId){
return response()->json(array(
'success' => false,
'message' => 'This voucher is already in used.'
));
}
}
// insert vocuher to cart_tmp
$voucherData = array(
'VoucherId' => $getVoucher[0]->Id,
'StoreURL' => $store_array[0]->StoreUrl,
'StoreId' => $store_array[0]->Id,
'CartKey' => $cartKey,
'ProductName' => $getVoucher[0]->VoucherCode,
'Price' => '00.00',
'Quantity' => 1
);
$i = $TeamStoreModel->insertToCart($voucherData);
$lastId = $i['lastId'];
$removeItemURL = url('removeitem') . '/' . $lastId;
//get all voucher used.
$updated_items = $TeamStoreModel->myCart($cartKey);
foreach($updated_items as $item){
if($item->VoucherId != null){
$voucherIds[] = $item->VoucherId;
}
}
$vouchers = $TeamStoreModel->selectVoucherWhereIn($voucherIds);
$totalValue = 0;
if(!empty($vouchers)){
foreach($vouchers as $voucher){
$totalValue = $totalValue + $voucher->VoucherValue;
if($voucher->VoucherType == "Percentage"){
$voucherData = array(
'totalValue'=> $totalValue,
'type'=>'Percentage'
);
}else{
$voucherData = array(
'totalValue'=> $totalValue,
'type'=>'Flat'
);
}
}
if($voucherData['type'] == "Percentage"){
$getPercentageValue = $voucherData['totalValue'] / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
}else{
//Flat voucher computation here..
}
}else{
$finalSubTotal = $getSubtotal[0]->Subtotal;
}
if($getVoucher[0]->VoucherType == "Percentage"){
$offData = $getVoucher[0]->VoucherValue . '%';
}else{
$offData = $getVoucher[0]->VoucherValue . ' ' . $store_array[0]->StoreCurrency;
}
$message = '<div class="btn-group">
<button type="button" class="btn btn-default btn-xs">'.$getVoucher[0]->VoucherCode. ' ' .$offData. ' OFF</button>
<button type="button" class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only"></span>
</button>
<ul class="dropdown-menu">
<li><a href="'.$removeItemURL.'"><i class="fa fa-times"></i> Remove</a></li>
</ul>
</div>';
// return success
return response()->json(array(
'success' => true,
'message' => $message,
'subtotal' =>$finalSubTotal
));
}else{
return response()->json(array(
'success' => false,
'message' => "Sorry, the voucher code is invalid. Please try again."
));
}
}
public function checkout(Request $request)