449 lines
13 KiB
PHP
449 lines
13 KiB
PHP
<?php namespace App\Http\Controllers\teamstore;
|
|
|
|
use App\Http\Requests;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Auth;
|
|
use App\Models\teamstore\TeamStoreModel;
|
|
use App\Models\user\UserModel;
|
|
use Mail;
|
|
|
|
|
|
class TeamStoreController extends Controller {
|
|
|
|
public function index(Request $request, $teamStoreURL)
|
|
{
|
|
// var_dump($teamStoreURL);
|
|
$m = new TeamStoreModel;
|
|
$store_array = $m->selectTeamStore('StoreUrl', $teamStoreURL);
|
|
$product_array = $m->selectTeamStoreProducts('TeamStoreId', $store_array[0]->Id);
|
|
$user_role = '';
|
|
|
|
if (Auth::check()){
|
|
$user_role = Auth::user()->role;
|
|
$store_id = Auth::user()->store_id;
|
|
}
|
|
|
|
// if($request->session()->get('teamstore_data_array') == null){
|
|
// if($store_id != $store_array[0]->Id){
|
|
// 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);
|
|
foreach ($thumbnails_array as $t => $thumb) {
|
|
|
|
if($thumb->ImageClass == 'custom'){
|
|
$displayThumbnails = $thumb->Image;
|
|
break;
|
|
}
|
|
|
|
if($thumb->ImageClass == 'active'){
|
|
$displayThumbnails = $thumb->Image;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$thumbnails[] = array(
|
|
'folder' => $store_array[0]->ImageFolder,
|
|
'product_id' => $pr_arr->Id,
|
|
'thumb' => $displayThumbnails
|
|
|
|
);
|
|
}
|
|
|
|
// var_dump($thumbnails);
|
|
return view('teamstore-sublayouts.index')
|
|
->with('store_array', $store_array)
|
|
->with('product_array', $product_array)
|
|
->with('thumbnails', $thumbnails);
|
|
}
|
|
|
|
public function storelist()
|
|
{
|
|
|
|
$m = new TeamStoreModel;
|
|
$stores_array = $m->selectAllTeamStore();
|
|
|
|
return view('teamstore-sublayouts.stores')
|
|
->with('stores_array', $stores_array);
|
|
|
|
|
|
|
|
}
|
|
public function checkTeamStorePassword(Request $request)
|
|
{
|
|
$m = new TeamStoreModel;
|
|
$post = $request->all();
|
|
$store_array = $m->selectTeamStore('Password', $post['password']);
|
|
|
|
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 view('teamstore-sublayouts.index');
|
|
}
|
|
|
|
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);
|
|
// var_dump($product_array);
|
|
$thumbnails_array = $m->getThumbnails($product_array[0]->Id);
|
|
$teams_array = $m->getTeams($product_array[0]->Id);
|
|
$sizes_array = $m->getSizes();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
public function login(Request $request)
|
|
{
|
|
// [0]->StoreUrl != $store_array[0]->StoreUrl
|
|
// if($request->session()->get('teamstore_data_array') != null){
|
|
// return redirect('teamstore/'.$request->session()->get('teamstore_data_array')[0]->StoreUrl);
|
|
// }else{
|
|
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();
|
|
$itemCount = $post['itemCount'];
|
|
$cssValue = $post['jersey_chk'];
|
|
$product_id = $post['product_id'];
|
|
$classname = "row" . $itemCount;
|
|
|
|
$m = new TeamStoreModel;
|
|
$teams_array = array();
|
|
$teams_array = $m->getTeams($product_id);
|
|
$sizes_array = $m->getSizes();
|
|
// var_dump($teams_array);
|
|
?>
|
|
<tr class="<?php echo $classname; ?>">
|
|
<td class="td-hide" style="<?php echo $cssValue; ?>">
|
|
<input type="text" class="form-control input-sm capitalizeText cls-uniformName" name="uniformName[]" placeholder="i.e John Doe" data-error="#err-uniformName<?php echo $itemCount ?>" required >
|
|
<span id="err-uniformName<?php echo $itemCount ?>" style="color: #dd4b39"></span>
|
|
</td>
|
|
<td>
|
|
<select class="form-control input-sm cls-uniformTeam" name="uniformTeam[]" data-error="#err-uniformTeam<?php echo $itemCount ?>" require>
|
|
<option value="">Select Team</option>
|
|
<?php
|
|
|
|
foreach($teams_array as $team){
|
|
?><option value="<?php echo $team->Team ?>"><?php echo $team->Team ?></option><?php
|
|
}
|
|
|
|
?>
|
|
<option value="others">Others</option>
|
|
</select>
|
|
<span id="err-uniformTeam<?php echo $itemCount ?>" style="color: #dd4b39"></span>
|
|
</td>
|
|
<td>
|
|
<div id="selectOptionNumber1">
|
|
<select class="form-control input-sm cls-uniformNumber" name="uniformNumber[]" data-error="#err-uniformNumber<?php echo $itemCount ?>" require >
|
|
<option value="">Select Number</option>
|
|
<?php
|
|
for($i = 0 ; $i < 100 ; $i++){
|
|
?><option value="<?php echo $i ?>"><?php echo $i ?></option><?php
|
|
}
|
|
?>
|
|
</select>
|
|
<span id="err-uniformNumber<?php echo $itemCount ?>" style="color: #dd4b39"></span>
|
|
</div>
|
|
|
|
</td>
|
|
<td>
|
|
<div id="fetchSizes">
|
|
<select class="form-control input-sm cls-uniformSize" name="uniformSize[]" data-error="#err-uniformSize<?php echo $itemCount ?>" require>
|
|
<option value="">Select Size</option>
|
|
<?php
|
|
foreach($sizes_array as $size){
|
|
?><option value="<?php echo $size->Size ?>"><?php echo $size->Size ?></option><?php
|
|
}
|
|
?>
|
|
</select>
|
|
<span id="err-uniformSize<?php echo $itemCount ?>" style="color: #dd4b39"></span>
|
|
</div>
|
|
|
|
</td>
|
|
<td class="text-center">
|
|
<span class="changeToRemoveBtn">
|
|
<button type="button" class="btn btn-danger btn-sm removeRow" data-toggle="tooltip" title="Remove"><i class="fa fa-remove" aria-hidden="true"></i></button>
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<tr id="addnew-btn-tbl-row">
|
|
<td colspan="5" ><button type="button" id="addNewRow" class="btn btn-success btn-sm pull-right" data-toggle="tooltip" title="Add Another"><i class="fa fa-plus" aria-hidden="true"></i> Add Row</button></td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
|
|
public function addToCart(Request $request)
|
|
{
|
|
$post = $request->all();
|
|
$m = new TeamStoreModel;
|
|
|
|
|
|
$product_id = $post['product_id'];
|
|
$store_url = $post['store_url'];
|
|
$store_id = $post['store_id'];
|
|
|
|
if($request->session()->has('cartkey')){
|
|
$cartKey = $request->session()->get('cartkey');
|
|
}else{
|
|
$request->session()->put('cartkey', sha1(time() . str_random(6)));
|
|
$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;
|
|
|
|
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"){
|
|
$final_price = $ProductPrice / 2;
|
|
}else{
|
|
$final_price = $ProductPrice;
|
|
}
|
|
|
|
$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],
|
|
'Number' => $order_number[$key],
|
|
'JerseySize' => $order_jersey_size[$key],
|
|
'ShortsSize' => $order_shorts_size[$key],
|
|
'Price' => $final_price,
|
|
'Quantity' => 1
|
|
);
|
|
}
|
|
}elseif($product_form == "tshirt-form"){
|
|
|
|
$items[] = array(
|
|
'ProductId' => $product_id,
|
|
'StoreURL' => $store_url,
|
|
'StoreId' => $store_id,
|
|
'FormUsed' => $product_form,
|
|
'CartKey' => $cartKey,
|
|
'DesignCode' => $design_code,
|
|
'ProductURL' => $ProductURL,
|
|
'ProductName' => $product_name,
|
|
'Size' => $post['uniformSize'],
|
|
'Price' => $ProductPrice,
|
|
'Quantity' => $post['quantity']
|
|
);
|
|
}elseif($product_form == "quantity-form"){
|
|
|
|
$items[] = array(
|
|
'ProductId' => $product_id,
|
|
'StoreURL' => $store_url,
|
|
'StoreId' => $store_id,
|
|
'FormUsed' => $product_form,
|
|
'CartKey' => $cartKey,
|
|
'DesignCode' => $design_code,
|
|
'ProductURL' => $ProductURL,
|
|
'ProductName' => $product_name,
|
|
'Price' => $ProductPrice,
|
|
'Quantity' => $post['quantity']
|
|
);
|
|
|
|
|
|
}elseif($product_form == "name-number-form"){
|
|
|
|
$order_names = $post['order_names'];
|
|
$order_number = $post['order_number'];
|
|
|
|
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],
|
|
'Number' => $order_number[$key],
|
|
'Price' => $ProductPrice,
|
|
'Quantity' => 1
|
|
);
|
|
}
|
|
}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){
|
|
$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],
|
|
'Size' => $order_size[$key],
|
|
'Number' => $order_number[$key],
|
|
'Price' => $ProductPrice,
|
|
'Quantity' => 1
|
|
);
|
|
}
|
|
|
|
}elseif($product_form == "number-form"){
|
|
|
|
$order_number = $post['order_number'];
|
|
|
|
foreach($order_number 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,
|
|
'Number' => $order_number[$key],
|
|
'Price' => $ProductPrice,
|
|
'Quantity' => 1
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$i = $m->insertToCart($items);
|
|
|
|
if($i){
|
|
return response()->json(array(
|
|
'success' => true
|
|
));
|
|
}
|
|
|
|
|
|
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');
|
|
|
|
$items = $m->myCart($cartKey);
|
|
$getSubtotal = $m->getSubtotal($cartKey);
|
|
$items_group = $m->myCartGroup($cartKey);
|
|
$item_thumbs = $m->selectDisplayCartThumb();
|
|
|
|
return view('sublayouts.cart')
|
|
->with('item_group', $items_group)
|
|
->with('row', $items)
|
|
->with('img_thumb', $item_thumbs)
|
|
->with('getSubtotal', $getSubtotal);
|
|
}
|
|
|
|
public function checkout(Request $request)
|
|
{
|
|
$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);
|
|
|
|
$items = $m->myCart($cartKey);
|
|
|
|
$getSubtotal = $m->getSubtotal($cartKey);
|
|
|
|
return view('sublayouts.checkout')
|
|
->with('row', $items)
|
|
->with('getSubtotal', $getSubtotal)
|
|
->with('array_address_book', $array_address_book);
|
|
|
|
}
|
|
|
|
public function mail()
|
|
{
|
|
// $user = User::find(1)->toArray();
|
|
|
|
// var_dump($user);
|
|
|
|
// Mail::send('emails.mailExample', $user, function($message) use ($user) {
|
|
// $message->to($user->email);
|
|
// $message->subject('E-Mail Example');
|
|
// });
|
|
|
|
|
|
// dd('Mail Send Successfully');
|
|
Mail::raw('Text to e-mail', function($message)
|
|
{
|
|
$message->from('us@example.com', 'Laravel');
|
|
|
|
$message->to('frank.begornia@yahoo.com')->subject('sample email');
|
|
});
|
|
}
|
|
|
|
|
|
}
|