updated checkout flow
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
<?php namespace App\Http\Controllers\teamstore;
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\teamstore;
|
||||
|
||||
use App\Http\Requests;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -13,80 +15,80 @@ use Illuminate\Support\Facades\Mail;
|
||||
use Analytics;
|
||||
|
||||
|
||||
class TeamStoreController extends Controller {
|
||||
|
||||
class TeamStoreController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request, $teamStoreURL)
|
||||
{
|
||||
// var_dump($teamStoreURL);
|
||||
$m = new TeamStoreModel;
|
||||
$UserModel = new UserModel;
|
||||
|
||||
|
||||
$store_array = $m->selectTeamStore('StoreUrl', $teamStoreURL);
|
||||
$product_array = $m->selectTeamStoreProducts('TeamStoreId', $store_array[0]->Id);
|
||||
$user_role = '';
|
||||
|
||||
if (Auth::check()){
|
||||
|
||||
if (Auth::check()) {
|
||||
$user_role = Auth::user()->role;
|
||||
$store_id = Auth::user()->store_id;
|
||||
}else{
|
||||
} else {
|
||||
$user_role = null;
|
||||
$store_id = null;
|
||||
}
|
||||
|
||||
|
||||
if($store_array[0]->Password != null){
|
||||
if($request->session()->get('teamstore_data_array') == null){
|
||||
if($store_id != $store_array[0]->Id){
|
||||
|
||||
if ($store_array[0]->Password != null) {
|
||||
if ($request->session()->get('teamstore_data_array') == null) {
|
||||
if ($store_id != $store_array[0]->Id) {
|
||||
return redirect('teamstore');
|
||||
}
|
||||
}else{
|
||||
|
||||
if($user_role != "store_owner"){
|
||||
if($request->session()->get('teamstore_data_array')[0]->StoreUrl != $store_array[0]->StoreUrl){
|
||||
return redirect()->back();
|
||||
} else {
|
||||
|
||||
if ($user_role != "store_owner") {
|
||||
if ($request->session()->get('teamstore_data_array')[0]->StoreUrl != $store_array[0]->StoreUrl) {
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($product_array as $p => $pr_arr) {
|
||||
|
||||
$thumbnails_array = $m->getProductThumbnails($pr_arr->Id);
|
||||
if(!empty($thumbnails_array)){
|
||||
if (!empty($thumbnails_array)) {
|
||||
foreach ($thumbnails_array as $t => $thumb) {
|
||||
|
||||
if($thumb->ImageClass == 'custom'){
|
||||
|
||||
if ($thumb->ImageClass == 'custom') {
|
||||
$displayThumbnails = $thumb->Image;
|
||||
break;
|
||||
}
|
||||
|
||||
if($thumb->ImageClass == 'active'){
|
||||
if ($thumb->ImageClass == 'active') {
|
||||
$displayThumbnails = $thumb->Image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$thumbnails[] = array(
|
||||
'folder' => $store_array[0]->ImageFolder,
|
||||
'product_id' => $pr_arr->Id,
|
||||
'thumb' => $displayThumbnails
|
||||
|
||||
);
|
||||
'folder' => $store_array[0]->ImageFolder,
|
||||
'product_id' => $pr_arr->Id,
|
||||
'thumb' => $displayThumbnails
|
||||
|
||||
}else{
|
||||
);
|
||||
} else {
|
||||
$thumbnails[] = array(
|
||||
'folder' => $store_array[0]->ImageFolder,
|
||||
'product_id' => $pr_arr->Id,
|
||||
'thumb' => "product-image-placeholder.png"
|
||||
'folder' => $store_array[0]->ImageFolder,
|
||||
'product_id' => $pr_arr->Id,
|
||||
'thumb' => "product-image-placeholder.png"
|
||||
);
|
||||
}
|
||||
}
|
||||
$getAnnouncement = $UserModel->getAnnouncement($store_array[0]->Id);
|
||||
|
||||
if(count($getAnnouncement) > 0){
|
||||
if (count($getAnnouncement) > 0) {
|
||||
$data = $getAnnouncement[0];
|
||||
}else{
|
||||
} else {
|
||||
$data = (object) array(
|
||||
'Id' => 0,
|
||||
'StoreId' => "",
|
||||
@@ -97,10 +99,10 @@ class TeamStoreController extends Controller {
|
||||
}
|
||||
|
||||
return view('teamstore-sublayouts.index')
|
||||
->with('store_array', $store_array)
|
||||
->with('product_array', $product_array)
|
||||
->with('announcement', $data)
|
||||
->with('thumbnails', $thumbnails);
|
||||
->with('store_array', $store_array)
|
||||
->with('product_array', $product_array)
|
||||
->with('announcement', $data)
|
||||
->with('thumbnails', $thumbnails);
|
||||
}
|
||||
|
||||
public function storelist(Request $request)
|
||||
@@ -115,87 +117,84 @@ class TeamStoreController extends Controller {
|
||||
|
||||
// foreach($teamstore as $t){
|
||||
// $sad = explode('/', $t);
|
||||
|
||||
|
||||
// if(count($sad) == 4){
|
||||
// $arr_teamstore[] = explode('?', $sad['3'])['0'];
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// var_dump(array_unique($arr_teamstore));
|
||||
|
||||
$m = new TeamStoreModel;
|
||||
$q = $request->input('q');
|
||||
$sort = $request->input('s');
|
||||
|
||||
if(isset($q) && isset($sort)){
|
||||
|
||||
if($sort == "latest"){
|
||||
|
||||
if (isset($q) && isset($sort)) {
|
||||
|
||||
if ($sort == "latest") {
|
||||
$field = "Id";
|
||||
$sort_value = "DESC";
|
||||
}elseif($sort == "al-desc"){
|
||||
$field = "StoreName";
|
||||
$sort_value = "DESC";
|
||||
}elseif($sort == "oldest"){
|
||||
} elseif ($sort == "al-desc") {
|
||||
$field = "StoreName";
|
||||
$sort_value = "DESC";
|
||||
} elseif ($sort == "oldest") {
|
||||
$field = "Id";
|
||||
$sort_value = "ASC";
|
||||
}else{
|
||||
$sort_value = "ASC";
|
||||
} else {
|
||||
$field = "StoreName";
|
||||
$sort_value = "ASC";
|
||||
}
|
||||
|
||||
if($q != ""){
|
||||
// keyword and sort
|
||||
$stores_array = $m->selectTeamstoreSearch($field, $sort_value, $q);
|
||||
}else{
|
||||
// sort only
|
||||
$stores_array = $m->selectTeamstoreFilter($field, $sort_value);
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
if ($q != "") {
|
||||
// keyword and sort
|
||||
$stores_array = $m->selectTeamstoreSearch($field, $sort_value, $q);
|
||||
} else {
|
||||
// sort only
|
||||
$stores_array = $m->selectTeamstoreFilter($field, $sort_value);
|
||||
}
|
||||
} else {
|
||||
$field = "StoreName";
|
||||
$sort_value = "ASC";
|
||||
$sort = "al-asc";
|
||||
$stores_array = $m->selectTeamstoreFilter($field, $sort_value);
|
||||
}
|
||||
|
||||
|
||||
return view('teamstore-sublayouts.stores')
|
||||
->with('stores_array', $stores_array)
|
||||
->with('keyword', $q)
|
||||
->with('filter', $sort);
|
||||
->with('stores_array', $stores_array)
|
||||
->with('keyword', $q)
|
||||
->with('filter', $sort);
|
||||
}
|
||||
|
||||
public function checkTeamStorePassword(Request $request)
|
||||
{
|
||||
$m = new TeamStoreModel;
|
||||
$post = $request->all();
|
||||
|
||||
|
||||
$store_array = $m->checkStorePassword($post['store_id'], $post['password']);
|
||||
|
||||
if($store_array){
|
||||
if ($store_array) {
|
||||
$request->session()->put('teamstore_data_array', $store_array);
|
||||
return redirect('teamstore/'. $store_array[0]->StoreUrl);
|
||||
|
||||
}else{
|
||||
return redirect()->back()->with('errors', 'Invalid Password.');
|
||||
return redirect('teamstore/' . $store_array[0]->StoreUrl);
|
||||
} else {
|
||||
return redirect()->back()->with('errors', 'Invalid Password.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private $teams_array;
|
||||
|
||||
public function productDetails($teamStoreURL, $productURL)
|
||||
{
|
||||
{
|
||||
$m = new TeamStoreModel;
|
||||
$teams_array = array();
|
||||
$store_array = $m->selectTeamStore('StoreUrl', $teamStoreURL);
|
||||
$product_array = $m->selectTeamStoreProducts('ProductURL', $productURL);
|
||||
|
||||
|
||||
$thumbnails_array = $m->getThumbnails($product_array[0]->Id);
|
||||
$teams_array = $m->getTeams($product_array[0]->Id);
|
||||
// $sizes_array = $m->getSizes();
|
||||
|
||||
if(empty($thumbnails_array)){
|
||||
|
||||
if (empty($thumbnails_array)) {
|
||||
|
||||
$data = (object) array(
|
||||
'Image' => 'product-image-placeholder.png',
|
||||
@@ -205,49 +204,48 @@ class TeamStoreController extends Controller {
|
||||
|
||||
$thumbnails_array[] = $data;
|
||||
}
|
||||
|
||||
|
||||
$x = explode(",", $product_array[0]->AvailableSizes );
|
||||
foreach($x as $s){
|
||||
|
||||
$x = explode(",", $product_array[0]->AvailableSizes);
|
||||
foreach ($x as $s) {
|
||||
$h[] = $m->getSizesByBracket($s);
|
||||
}
|
||||
|
||||
foreach($h as $d){
|
||||
foreach($d as $g){
|
||||
foreach ($h as $d) {
|
||||
foreach ($d as $g) {
|
||||
$sizes_array[] = $g;
|
||||
}
|
||||
}
|
||||
|
||||
if($product_array[0]->ProductAvailableQty != null){
|
||||
if ($product_array[0]->ProductAvailableQty != null) {
|
||||
$soldQty = $m->getSoldQty($product_array[0]->Id);
|
||||
$availableQty = $product_array[0]->ProductAvailableQty - $soldQty[0]->SoldQty;
|
||||
}else{
|
||||
} else {
|
||||
// echo 'no qty';
|
||||
$availableQty = null;
|
||||
}
|
||||
// $product_array[0]->ProductAvailableQty
|
||||
|
||||
|
||||
return view('teamstore-sublayouts.product-details')
|
||||
->with('store_array', $store_array)
|
||||
->with('product_array', $product_array)
|
||||
->with('thumbnails_array', $thumbnails_array)
|
||||
->with('teams_array', $teams_array)
|
||||
->with('sizes_array', $sizes_array)
|
||||
->with('available_qty', $availableQty);
|
||||
|
||||
->with('store_array', $store_array)
|
||||
->with('product_array', $product_array)
|
||||
->with('thumbnails_array', $thumbnails_array)
|
||||
->with('teams_array', $teams_array)
|
||||
->with('sizes_array', $sizes_array)
|
||||
->with('available_qty', $availableQty);
|
||||
}
|
||||
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
{
|
||||
return view('teamstore-sublayouts.login');
|
||||
}
|
||||
|
||||
public function clearSession(Request $request)
|
||||
{
|
||||
{
|
||||
$request->session()->forget('teamstore_data_array');
|
||||
return redirect("{{ url('/') }}");
|
||||
}
|
||||
|
||||
|
||||
public function addNewRow(Request $request)
|
||||
{
|
||||
$post = $request->all();
|
||||
@@ -256,47 +254,45 @@ class TeamStoreController extends Controller {
|
||||
$item = $TeamStoreModel->selectTeamStoreProductByIdHash($post['p_id']);
|
||||
$x = explode(",", $item[0]->AvailableSizes);
|
||||
|
||||
foreach($x as $s){
|
||||
foreach ($x as $s) {
|
||||
$h[] = $TeamStoreModel->getSizesByBracket($s);
|
||||
}
|
||||
|
||||
foreach($h as $d){
|
||||
foreach($d as $g){
|
||||
foreach ($h as $d) {
|
||||
foreach ($d as $g) {
|
||||
$sizes_array[] = $g;
|
||||
}
|
||||
}
|
||||
|
||||
if($item[0]->ProductAvailableQty != null){
|
||||
if ($item[0]->ProductAvailableQty != null) {
|
||||
$soldQty = $TeamStoreModel->getSoldQty($item[0]->Id);
|
||||
$availableQty = $item[0]->ProductAvailableQty - $soldQty[0]->SoldQty;
|
||||
}else{
|
||||
} else {
|
||||
// echo 'no qty';
|
||||
$availableQty = null;
|
||||
}
|
||||
|
||||
$handle_form = view('teamstore-sublayouts.forms.' . $item[0]->ProductForm )
|
||||
->with('sizes_array', $sizes_array)
|
||||
->with('availableQty', $availableQty)
|
||||
->render();
|
||||
$handle_form = view('teamstore-sublayouts.forms.' . $item[0]->ProductForm)
|
||||
->with('sizes_array', $sizes_array)
|
||||
->with('availableQty', $availableQty)
|
||||
->render();
|
||||
|
||||
return $handle_form;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function addToCart(Request $request)
|
||||
{
|
||||
$post = $request->all();
|
||||
$m = new TeamStoreModel;
|
||||
$hash_product_id = $post['p_id'];
|
||||
|
||||
if($request->session()->has('cartkey')){
|
||||
|
||||
if ($request->session()->has('cartkey')) {
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
}else{
|
||||
} else {
|
||||
$request->session()->put('cartkey', sha1(time() . str_random(6)));
|
||||
$cartKey = $cartKey = $request->session()->get('cartkey');
|
||||
}
|
||||
|
||||
|
||||
$product_array = $m->selectTeamStoreProductByIdHash($hash_product_id);
|
||||
$product_id = $product_array[0]->Id;
|
||||
$TeamStoreId = $product_array[0]->TeamStoreId;
|
||||
@@ -308,24 +304,24 @@ class TeamStoreController extends Controller {
|
||||
$shipping_cost_id = $product_array[0]->ShippingCostId;
|
||||
|
||||
$teamstore_array = $m->selectTeamStore('Id', $TeamStoreId);
|
||||
|
||||
|
||||
$store_url = $teamstore_array[0]->StoreUrl;
|
||||
$store_id = $teamstore_array[0]->Id;
|
||||
|
||||
if($product_form == "jersey-and-shorts-form"){
|
||||
if ($product_form == "jersey-and-shorts-form") {
|
||||
$order_names = $post['order_names'];
|
||||
$order_number = $post['order_number'];
|
||||
$order_jersey_size = $post['order_jersey_size'];
|
||||
$order_shorts_size = $post['order_shorts_size'];
|
||||
|
||||
foreach($order_names as $key => $val){
|
||||
|
||||
if($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none"){
|
||||
foreach ($order_names as $key => $val) {
|
||||
|
||||
if ($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none") {
|
||||
$final_price = $ProductPrice / 2;
|
||||
}else{
|
||||
} else {
|
||||
$final_price = $ProductPrice;
|
||||
}
|
||||
|
||||
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -344,7 +340,7 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
}elseif($product_form == "tshirt-form"){
|
||||
} elseif ($product_form == "tshirt-form") {
|
||||
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
@@ -360,7 +356,7 @@ class TeamStoreController extends Controller {
|
||||
'Quantity' => $post['quantity'],
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}elseif($product_form == "quantity-form"){
|
||||
} elseif ($product_form == "quantity-form") {
|
||||
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
@@ -375,14 +371,12 @@ class TeamStoreController extends Controller {
|
||||
'Quantity' => $post['quantity'],
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
|
||||
|
||||
}elseif($product_form == "name-number-form"){
|
||||
} elseif ($product_form == "name-number-form") {
|
||||
|
||||
$order_names = $post['order_names'];
|
||||
$order_number = $post['order_number'];
|
||||
|
||||
foreach($order_names as $key => $val){
|
||||
foreach ($order_names as $key => $val) {
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -399,13 +393,13 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
}elseif($product_form == "name-number-size-form"){
|
||||
} elseif ($product_form == "name-number-size-form") {
|
||||
|
||||
$order_names = $post['order_names'];
|
||||
$order_number = $post['order_number'];
|
||||
$order_size = $post['order_size'];
|
||||
|
||||
foreach($order_names as $key => $val){
|
||||
foreach ($order_names as $key => $val) {
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -423,12 +417,11 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
|
||||
}elseif($product_form == "number-form"){
|
||||
} elseif ($product_form == "number-form") {
|
||||
|
||||
$order_number = $post['order_number'];
|
||||
|
||||
foreach($order_number as $key => $val){
|
||||
foreach ($order_number as $key => $val) {
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -444,13 +437,13 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
}elseif($product_form == "name-name2-size-form"){
|
||||
} 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){
|
||||
foreach ($order_names as $key => $val) {
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -468,12 +461,12 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
}elseif($product_form == "name-size-form"){
|
||||
} elseif ($product_form == "name-size-form") {
|
||||
|
||||
$order_names = $post['order_names'];
|
||||
$order_size = $post['order_size'];
|
||||
|
||||
foreach($order_names as $key => $val){
|
||||
foreach ($order_names as $key => $val) {
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -490,18 +483,18 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
}elseif($product_form == "jersey-and-shorts-quantity-form"){
|
||||
} elseif ($product_form == "jersey-and-shorts-quantity-form") {
|
||||
|
||||
$order_shorts_size = $post['order_shorts_size'];
|
||||
$order_jersey_size = $post['order_jersey_size'];
|
||||
$quantity = $post['quantity'];
|
||||
|
||||
foreach($order_jersey_size as $key => $val){
|
||||
if($order_jersey_size[$key] != "none" || $order_shorts_size[$key] != "none"){
|
||||
|
||||
if($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none"){
|
||||
foreach ($order_jersey_size as $key => $val) {
|
||||
if ($order_jersey_size[$key] != "none" || $order_shorts_size[$key] != "none") {
|
||||
|
||||
if ($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none") {
|
||||
$final_price = $ProductPrice / 2;
|
||||
}else{
|
||||
} else {
|
||||
$final_price = $ProductPrice;
|
||||
}
|
||||
|
||||
@@ -521,22 +514,21 @@ class TeamStoreController extends Controller {
|
||||
'ShippingCostId' => $shipping_cost_id
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}elseif($product_form == "number-jersey-shorts-form"){
|
||||
} elseif ($product_form == "number-jersey-shorts-form") {
|
||||
|
||||
$order_number = $post['order_number'];
|
||||
$order_jersey_size = $post['order_jersey_size'];
|
||||
$order_shorts_size = $post['order_shorts_size'];
|
||||
|
||||
foreach($order_number as $key => $val){
|
||||
|
||||
if($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none"){
|
||||
foreach ($order_number as $key => $val) {
|
||||
|
||||
if ($order_jersey_size[$key] == "none" || $order_shorts_size[$key] == "none") {
|
||||
$final_price = $ProductPrice / 2;
|
||||
}else{
|
||||
} else {
|
||||
$final_price = $ProductPrice;
|
||||
}
|
||||
|
||||
|
||||
$items[] = array(
|
||||
'ProductId' => $product_id,
|
||||
'StoreURL' => $store_url,
|
||||
@@ -557,8 +549,8 @@ class TeamStoreController extends Controller {
|
||||
}
|
||||
|
||||
$i = $m->insertToCart($items);
|
||||
|
||||
if($i['i']){
|
||||
|
||||
if ($i['i']) {
|
||||
return response()->json(array(
|
||||
'success' => true
|
||||
));
|
||||
@@ -568,103 +560,133 @@ class TeamStoreController extends Controller {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => "Something went wrong. Please refresh the page."
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
public function cart(Request $request){
|
||||
|
||||
public function cart(Request $request)
|
||||
{
|
||||
|
||||
$m = new TeamStoreModel;
|
||||
$UserModel = new UserModel;
|
||||
$array_address_book = null;
|
||||
|
||||
if(!Auth::guest()){
|
||||
$userId = Auth::user()->id;
|
||||
$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);
|
||||
$items_group = $m->myCartGroup($cartKey);
|
||||
//var_dump($items_group);
|
||||
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
|
||||
if($grouped_item){
|
||||
if ($grouped_item) {
|
||||
$defId = $grouped_item[0]->StoreId;
|
||||
}else{
|
||||
} else {
|
||||
$defId = 0;
|
||||
}
|
||||
|
||||
$item_thumbs = $m->selectDisplayCartThumb();
|
||||
$store_array = $m->selectTeamStore('Id', $defId);
|
||||
|
||||
|
||||
if($items){
|
||||
$item_thumbs = $m->selectDisplayCartThumb();
|
||||
$store_array = $m->selectTeamStore('Id', $defId);
|
||||
|
||||
|
||||
if ($items) {
|
||||
$voucherIds = array();
|
||||
foreach($items as $item){
|
||||
if($item->VoucherId != null){
|
||||
foreach ($items as $item) {
|
||||
if ($item->VoucherId != null) {
|
||||
$voucherIds[] = $item->VoucherId;
|
||||
}
|
||||
}
|
||||
$vouchers = $m->selectVoucherWhereIn($voucherIds);
|
||||
$vouchers = $m->selectVoucherWhereIn($voucherIds);
|
||||
}
|
||||
|
||||
|
||||
$totalValue = 0;
|
||||
if(!empty($vouchers)){
|
||||
foreach($vouchers as $voucher){
|
||||
if (!empty($vouchers)) {
|
||||
foreach ($vouchers as $voucher) {
|
||||
$totalValue = $totalValue + $voucher->VoucherValue;
|
||||
if($voucher->VoucherType == "Percentage"){
|
||||
if ($voucher->VoucherType == "Percentage") {
|
||||
$voucherData = array(
|
||||
'totalValue'=> $totalValue,
|
||||
'type'=>'Percentage'
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Percentage'
|
||||
);
|
||||
}else{
|
||||
} else {
|
||||
$voucherData = array(
|
||||
'totalValue'=> $totalValue,
|
||||
'type'=>'Flat'
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Flat'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if($voucherData['type'] == "Percentage"){
|
||||
|
||||
if ($voucherData['type'] == "Percentage") {
|
||||
$getPercentageValue = $voucherData['totalValue'] / 100;
|
||||
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
|
||||
}else{
|
||||
} else {
|
||||
//Flat voucher computation here..
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
}
|
||||
|
||||
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 = [];
|
||||
}
|
||||
|
||||
|
||||
return view('sublayouts.cart')
|
||||
->with('item_group', $items_group)
|
||||
->with('row', $items)
|
||||
->with('img_thumb', $item_thumbs)
|
||||
->with('getSubtotal', $finalSubTotal)
|
||||
->with('store_array', $store_array);
|
||||
->with('item_group', $items_group)
|
||||
->with('row', $items)
|
||||
->with('img_thumb', $item_thumbs)
|
||||
->with('getSubtotal', $finalSubTotal)
|
||||
->with('store_array', $store_array)
|
||||
->with('store_array', $store_array)
|
||||
->with('shipping_fee', $shippingFee)
|
||||
->with('tax', $tax)
|
||||
->with('address_book', $array_address_book);
|
||||
}
|
||||
|
||||
public function addVoucher(Request $request){
|
||||
public function addVoucher(Request $request)
|
||||
{
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
|
||||
if($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){
|
||||
|
||||
if ($getVoucher) {
|
||||
$items = $TeamStoreModel->myCart($cartKey);
|
||||
|
||||
// check if if voucher is already in used;
|
||||
foreach($items as $item){
|
||||
if($getVoucher[0]->Id == $item->VoucherId){
|
||||
foreach ($items as $item) {
|
||||
if ($getVoucher[0]->Id == $item->VoucherId) {
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => 'This voucher is already in used.'
|
||||
@@ -689,73 +711,69 @@ class TeamStoreController extends Controller {
|
||||
|
||||
//get all voucher used.
|
||||
$updated_items = $TeamStoreModel->myCart($cartKey);
|
||||
foreach($updated_items as $item){
|
||||
if($item->VoucherId != null){
|
||||
foreach ($updated_items as $item) {
|
||||
if ($item->VoucherId != null) {
|
||||
$voucherIds[] = $item->VoucherId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$vouchers = $TeamStoreModel->selectVoucherWhereIn($voucherIds);
|
||||
|
||||
|
||||
$vouchers = $TeamStoreModel->selectVoucherWhereIn($voucherIds);
|
||||
|
||||
$totalValue = 0;
|
||||
if(!empty($vouchers)){
|
||||
foreach($vouchers as $voucher){
|
||||
if (!empty($vouchers)) {
|
||||
foreach ($vouchers as $voucher) {
|
||||
$totalValue = $totalValue + $voucher->VoucherValue;
|
||||
if($voucher->VoucherType == "Percentage"){
|
||||
if ($voucher->VoucherType == "Percentage") {
|
||||
$voucherData = array(
|
||||
'totalValue'=> $totalValue,
|
||||
'type'=>'Percentage'
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Percentage'
|
||||
);
|
||||
}else{
|
||||
} else {
|
||||
$voucherData = array(
|
||||
'totalValue'=> $totalValue,
|
||||
'type'=>'Flat'
|
||||
'totalValue' => $totalValue,
|
||||
'type' => 'Flat'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if($voucherData['type'] == "Percentage"){
|
||||
|
||||
if ($voucherData['type'] == "Percentage") {
|
||||
$getPercentageValue = $voucherData['totalValue'] / 100;
|
||||
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal - $getDiscountValue;
|
||||
}else{
|
||||
} else {
|
||||
//Flat voucher computation here..
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$finalSubTotal = $getSubtotal[0]->Subtotal;
|
||||
}
|
||||
|
||||
if($getVoucher[0]->VoucherType == "Percentage"){
|
||||
if ($getVoucher[0]->VoucherType == "Percentage") {
|
||||
$offData = $getVoucher[0]->VoucherValue . '%';
|
||||
}else{
|
||||
} 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 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>
|
||||
<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
|
||||
'subtotal' => $finalSubTotal
|
||||
));
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
return response()->json(array(
|
||||
'success' => false,
|
||||
'message' => "Sorry, the voucher code is invalid. Please try again."
|
||||
@@ -767,10 +785,10 @@ class TeamStoreController extends Controller {
|
||||
{
|
||||
$m = new TeamStoreModel;
|
||||
$cartKey = $request->session()->get('cartkey');
|
||||
|
||||
|
||||
$usermodel = new UserModel;
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
|
||||
$array_address_book = $usermodel->selectAddresBook('UserId', $userId);
|
||||
|
||||
// var_dump($array_address_book);
|
||||
@@ -780,10 +798,9 @@ class TeamStoreController extends Controller {
|
||||
$getSubtotal = $m->getSubtotal($cartKey);
|
||||
|
||||
return view('sublayouts.checkout')
|
||||
->with('row', $items)
|
||||
->with('getSubtotal', $getSubtotal)
|
||||
->with('array_address_book', $array_address_book);
|
||||
|
||||
->with('row', $items)
|
||||
->with('getSubtotal', $getSubtotal)
|
||||
->with('array_address_book', $array_address_book);
|
||||
}
|
||||
|
||||
public function mail()
|
||||
@@ -799,13 +816,10 @@ class TeamStoreController extends Controller {
|
||||
|
||||
|
||||
// dd('Mail Send Successfully');
|
||||
Mail::raw('Text to e-mail', function($message)
|
||||
{
|
||||
Mail::raw('Text to e-mail', function ($message) {
|
||||
$message->from('us@example.com', 'Laravel');
|
||||
|
||||
$message->to('frank.begornia@yahoo.com')->subject('sample email');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user