updated checkout flow

This commit is contained in:
franknstayn
2021-11-03 21:30:42 +08:00
parent 148df27117
commit 08c274f5bd
18 changed files with 254594 additions and 26526 deletions

View File

@@ -1,24 +1,29 @@
<?php namespace App\Http\Controllers;
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Support\Facades\Auth;
use App\Traits\CaptchaTrait;
use App\User;
use Validator;
use Illuminate\Support\Facades\Validator;
use App\Models\user\UserModel;
use Illuminate\Http\Request;
class CustomAuthController extends Controller {
class CustomAuthController extends Controller
{
use CaptchaTrait;
public function authenticate(Request $request){
public function authenticate(Request $request)
{
$post = $request->all();
$email = $post['email'];
$password = $post['password'];
if (Auth::attempt(['email' => $email, 'password' => $password])){
if (Auth::attempt(['email' => $email, 'password' => $password])) {
if (Auth::user()->role == 'admin') {
$message = '
@@ -27,83 +32,101 @@ class CustomAuthController extends Controller {
<h4><i class="icon fa fa-ban"></i> ERROR:</h4>
You are not allowed to enter to this site.
</div>';
return response()->json(array('success' => false, 'message'=>$message));
}
return response()->json(array('success' => false, 'message' => $message));
}
$message = "success";
$navbar = view('layout.navbar', compact('view'))->render();
$save_design_button = ' <button type="button" class="btn btn-lg btn-primary pull-right" data-toggle="modal" data-target="#modalDesignName"><i class="fa fa-floppy-o" aria-hidden="true"></i> Save Design</button>';
return response()->json(array(
'success' => true,
'message'=>$message,
'navbar'=>$navbar,
'success' => true,
'message' => $message,
'navbar' => $navbar,
'save_design_button' => $save_design_button
));
}else{
} else {
$message = '
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> ERROR:</h4>
Username or Password is incorrect.
</div>';
return response()->json(array('success' => false, 'message'=>$message));
return response()->json(array('success' => false, 'message' => $message));
}
}
public function postRegister(Request $request){
public function postRegister(Request $request)
{
$post = $request->all();
$userModel = new UserModel;
$post['captcha'] = $this->captchaCheck();
$validator = Validator::make($post, [
'username' => 'unique:user_logins',
'email' => 'unique:user_logins',
'g-recaptcha-response' => 'required',
'captcha' => 'required|min:1'
],
[
'g-recaptcha-response.required' => 'Captcha is required',
'captcha.min' => 'Wrong captcha, please try again.'
]);
if ($validator->fails())
{
$validator = Validator::make(
$post,
[
'username' => 'unique:user_logins',
'email' => 'unique:user_logins',
'g-recaptcha-response' => 'required',
'captcha' => 'required|min:1'
],
[
'g-recaptcha-response.required' => 'Captcha is required',
'captcha.min' => 'Wrong captcha, please try again.'
]
);
if ($validator->fails()) {
$errors = "";
foreach($validator->errors()->all() as $error){
$errors .= "<li>".$error."</li>";
foreach ($validator->errors()->all() as $error) {
$errors .= "<li>" . $error . "</li>";
}
$message = '
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> ERROR:</h4>
'.$errors.
'</div>';
' . $errors .
'</div>';
return response()->json(array(
return response()->json(array(
'success' => false,
'message' => $message
));
}
User::create([
'name' => $post['name'],
'username' => $post['username'],
}
$user = User::create([
'name' => $post['firstname'] . ' ' . $post['lastname'],
'username' => $post['email'],
'email' => $post['email'],
'password' => bcrypt($post['password']),
'role' => 'user'
]);
$data = array(
'UserId' => $user->id,
'Fullname' => $post['firstname'] . ' ' . $post['lastname'],
'ContactNumber' => $post['mobilenumber'],
// 'OtherNotes' => $post['othernotes'],
'Address' => $post['address'],
'Address2' => $post['address2'],
'State' => $post['state'],
'City' => $post['city'],
'ZipCode' => $post['zipcode'],
'CountryCode' => $post['countryCode'],
'Country' => $post['country']
);
$userModel->insertAddressBook($data);
Auth::attempt(['email' => $post['email'], 'password' => $post['password']]);
return response()->json(array(
'success' => true
'success' => true,
'redirect' => $post['redirect']
));
}
}

View File

@@ -1,8 +1,8 @@
<?php
namespace App\Http\Controllers\paypal;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
// use Paypal;
use Netshell\Paypal\Facades\Paypal;
@@ -18,6 +18,7 @@ use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Redirect;
// use Mail;
use Illuminate\Support\Facades\Mail;
use PayPal\Exception\PayPalConnectionException;
class PaypalController extends Controller
@@ -28,30 +29,42 @@ class PaypalController extends Controller
public function __construct()
{
$paypal_env = "live";
$paypal_apiUrl = 'https://api.paypal.com'; // default
if ($paypal_env == 'live') {
$paypal_apiUrl = 'https://api.paypal.com';
} else {
$paypal_apiUrl = 'https://api.sandbox.paypal.com';
}
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret')
config('services.paypal_' . $paypal_env . '.client_id'),
config('services.paypal_' . $paypal_env . '.secret')
// config('services.paypal_live.client_id'),
// config('services.paypal_live.secret')
);
// $this->_apiContext->setConfig(array(
// 'mode' => 'sandbox',
// 'service.EndPoint' => 'https://api.sandbox.paypal.com',
// 'http.ConnectionTimeOut' => 30,
// 'log.LogEnabled' => true,
// 'log.FileName' => storage_path('logs/paypal.log'),
// 'log.LogLevel' => 'FINE'
// ));
// live
$this->_apiContext->setConfig(array(
'mode' => 'live',
'service.EndPoint' => 'https://api.paypal.com',
'mode' => $paypal_env,
'service.EndPoint' => $paypal_apiUrl,
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
// live
// $this->_apiContext->setConfig(array(
// 'mode' => 'sandbox',
// 'service.EndPoint' => 'https://api.paypal.com',
// 'http.ConnectionTimeOut' => 30,
// 'log.LogEnabled' => true,
// 'log.FileName' => storage_path('logs/paypal.log'),
// 'log.LogLevel' => 'FINE'
// ));
}
@@ -63,16 +76,54 @@ class PaypalController extends Controller
public function getCheckout(Request $request)
{
$UserModel = new UserModel;
if (Auth::guest()) {
$message = 'Please <a href="' . url('auth/login') . '">Sign in</a> to your account to proceed.';
Session::flash('msg', $message);
return Redirect::back();
}
$userId = Auth::user()->id;
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
if (count($array_address_book) <= 0) {
$message = 'Please complete your shipping address. <a href="user/address-book/create"> <strong> <u>click here</u> </strong></a>.';
Session::flash('cartkeyError', $message);
return Redirect::back();
}
$shipping_address_url = "user/address-book/edit/" . $array_address_book[0]->Id;
if (
count($array_address_book) <= 0 ||
$array_address_book[0]->Fullname == null ||
$array_address_book[0]->ContactNumber == null ||
$array_address_book[0]->Address == null ||
$array_address_book[0]->State == null ||
$array_address_book[0]->City == null ||
$array_address_book[0]->ZipCode == null
) {
$message = 'Please complete your shipping address. <a href="' . url($shipping_address_url) . '"> <strong> <u>click here</u> </strong></a>.';
Session::flash('cartkeyError', $message);
return Redirect::back();
}
// $shippingAddress = [
// "recipient_name" => $array_address_book[0]->Fullname,
// "line1" => $array_address_book[0]->Address,
// "line2" => "",
// "city" => $array_address_book[0]->City,
// "country_code" => $array_address_book[0]->CountryCode,
// "postal_code" => $array_address_book[0]->ZipCode,
// "state" => $array_address_book[0]->State,
// "phone" => $array_address_book[0]->ContactNumber
// ];
// $request->session()->forget('cartkey');
if(!$request->session()->has('cartkey')){
if (!$request->session()->has('cartkey')) {
$message = 'Your cart is empty';
Session::flash('cartkeyError', $message);
return Redirect::back();
@@ -81,81 +132,56 @@ class PaypalController extends Controller
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
// $inputFields = Paypal::InputFields();
// $inputFields->setAllowNote(true)
// ->setNoShipping(1)
// ->setAddressOverride(0);
// $webProfile = Paypal::WebProfile();
// $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())
// // ->setPresentation($presentation)
// ->setInputFields($inputFields);
// $shipping = PayPal::ShippingAddress();
// $shipping->setRecipientName($array_address_book[0]->Fullname);
// $shipping->setLine1($array_address_book[0]->Address);
// $shipping->setCity($array_address_book[0]->City);
// $shipping->setCountryCode($array_address_book[0]->CountryCode);
// $shipping->setPostalCode($array_address_book[0]->ZipCode);
// $shipping->setState($array_address_book[0]->State);
// $shipping->setPhone($array_address_book[0]->ContactNumber);
// $payerInfo = Paypal::PayerInfo();
// $payerInfo->setShippingAddress($shipping);
// $payer->setPayerInfo($payerInfo);
$m = new TeamStoreModel;
$paypal_model = new PayPalModel;
$last_id = $paypal_model->getLastIdPaymentDetails();
$invoice_num = str_pad($last_id[0]->Id, 4, '0', STR_PAD_LEFT);
// var_dump(count($last_id));
if (count($last_id) > 0) {
$lastId = $last_id[0]->Id + 1;
} else {
$lastId = 1;
}
$invoice_num = str_pad($lastId, 6, '0', STR_PAD_LEFT);
// var_dump($invoice_num);
$cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey);
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
$store_array = $m->selectTeamStore('Id', $grouped_item[0]->StoreId);
$getSmallItemQty = 0;
$getBulkyItemQty = 0;
$getMaskItemQty = 0;
$getDGSItemQty = 0;
$shippingFee = 0;
$shippingFee = $this->getShippingFee($cartKey);
foreach ($items as $item) {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId;
$voucher = $m->selectVoucherWhereIn($voucherIds);
$item_id = $item->Id;
$totalValue = $voucher[0]->VoucherValue;
if ($voucher[0]->VoucherType == "Percentage") {
$getPercentageValue = $totalValue / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$data = array(
'Price' => round($getDiscountValue * -1, 2)
);
$tax = $this->getTax($cartKey)['tax'];
$order_grandtotal = $this->getTax($cartKey)['order_grandtotal'];
$m->updateVoucherValueInCart($data, $item_id);
} else {
$voucherData = array(
'totalValue' => $totalValue,
'type' => 'Flat'
);
}
}
if($item->ShippingCostId == 1){
$getSmallItemQty += $item->Quantity;
}else if($item->ShippingCostId == 2){
$getBulkyItemQty += $item->Quantity;
}else if($item->ShippingCostId == 3){
$getMaskItemQty += $item->Quantity;
}else if($item->ShippingCostId == 4){
$getDGSItemQty += $item->Quantity;
}
}
$getSmallItemQty = ceil($getSmallItemQty / 3) * 8;
$getBulkyItemQty = ceil($getBulkyItemQty / 1) * 8;
$getMaskItemQty = ceil($getMaskItemQty / 25) * 8;
$getMaskItemQty = ceil($getMaskItemQty / 4) * 5;
$shippingFee = $getSmallItemQty + $getBulkyItemQty + $getMaskItemQty + $getDGSItemQty;
// var_dump($shippingFee);
$order_items = array();
$updated_items = $m->myCart($cartKey);
$updated_getSubtotal = $m->getSubtotal($cartKey);
// $order_subtotal = $updated_getSubtotal[0]->Subtotal;
$order_grandtotal = $updated_getSubtotal[0]->Subtotal;
if ($grouped_item[0]->StoreId == 76 || $grouped_item[0]->StoreId == 78 || $grouped_item[0]->StoreId == 111 || $grouped_item[0]->StoreId == 131 || $grouped_item[0]->StoreId == 30 || $grouped_item[0]->StoreId == 141 || $grouped_item[0]->StoreId == 162 || $grouped_item[0]->StoreId == 185) {
$tax_value = 0;
} else {
$tax_value = 0.10;
}
$tax = $order_grandtotal * $tax_value;
foreach ($updated_items as $key => $item) {
@@ -172,6 +198,29 @@ class PaypalController extends Controller
$item_list = PayPal::ItemList();
$item_list->setItems($order_items);
$payment = PayPal::Payment();
// var_dump(array($transaction));
if ($array_address_book[0]->CountryCode == "CA") {
$shipping = PayPal::ShippingAddress();
$shipping->setRecipientName($array_address_book[0]->Fullname);
$shipping->setLine1($array_address_book[0]->Address);
$shipping->setLine2($array_address_book[0]->Address2);
$shipping->setCity($array_address_book[0]->City);
$shipping->setCountryCode($array_address_book[0]->CountryCode);
$shipping->setPostalCode($array_address_book[0]->ZipCode);
$shipping->setState($array_address_book[0]->State);
$shipping->setPhone($array_address_book[0]->ContactNumber);
$item_list->setShippingAddress($shipping);
$payment->setExperienceProfileId($this->createWebProfile());
}
// var_dump($item_list);
$amount_details = PayPal::Details();
$amount_details->setSubtotal($order_grandtotal);
$amount_details->setTax($tax);
@@ -192,9 +241,10 @@ class PaypalController extends Controller
$redirectUrls = PayPal::RedirectUrls();
$redirectUrls->setReturnUrl(route('getDone'));
$redirectUrls->setCancelUrl(route('getCancel'));
// var_dump($shippingAddress)
$payment = PayPal::Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
@@ -233,19 +283,306 @@ class PaypalController extends Controller
}
public function getShippingFee($cartKey)
{
$m = new TeamStoreModel;
$UserModel = new UserModel;
$userId = 0;
if (!Auth::guest()) {
$userId = Auth::user()->id;
}
$items = $m->myCart($cartKey); // item from cart_tmp
$getSubtotal = $m->getSubtotal($cartKey);
$getSmallItemQty = 0;
$getBulkyItemQty = 0;
$getMaskItemQty = 0;
$getDGSItemQty = 0;
$shippingFee = 0;
$CAShippingfee = 0;
foreach ($items as $item) {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId;
$voucher = $m->selectVoucherWhereIn($voucherIds);
$item_id = $item->Id;
$totalValue = $voucher[0]->VoucherValue;
if ($voucher[0]->VoucherType == "Percentage") {
$getPercentageValue = $totalValue / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$data = array(
'Price' => round($getDiscountValue * -1, 2)
);
$m->updateVoucherValueInCart($data, $item_id);
} else {
$voucherData = array(
'totalValue' => $totalValue,
'type' => 'Flat'
);
}
}
if ($item->ShippingCostId == 1) {
$getSmallItemQty += $item->Quantity;
} else if ($item->ShippingCostId == 2) {
$getBulkyItemQty += $item->Quantity;
} else if ($item->ShippingCostId == 3) {
$getMaskItemQty += $item->Quantity;
} else if ($item->ShippingCostId == 4) {
$getDGSItemQty += $item->Quantity;
}
$CAShippingfee += $item->Quantity; // for canada
}
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
$countryCode = "";
if (count($array_address_book) > 0) {
$countryCode = $array_address_book[0]->CountryCode;
$CAShippingfee = ceil($CAShippingfee / 2) * 30;
}
$getSmallItemQty = ceil($getSmallItemQty / 3) * 8;
$getBulkyItemQty = ceil($getBulkyItemQty / 1) * 8;
$getMaskItemQty = ceil($getMaskItemQty / 25) * 8;
$getDGSItemQty = ceil($getDGSItemQty / 4) * 5;
$shippingFee = $getSmallItemQty + $getBulkyItemQty + $getMaskItemQty + $getDGSItemQty;
if ($countryCode == "CA") {
$shippingFee = $CAShippingfee;
}
return $shippingFee;
}
public function getTax($cartKey)
{
$m = new TeamStoreModel;
$updated_getSubtotal = $m->getSubtotal($cartKey);
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
if (count($grouped_item) <= 0) {
$tax_value = 0;
} else {
if ($grouped_item[0]->StoreId == 76 || $grouped_item[0]->StoreId == 78 || $grouped_item[0]->StoreId == 111 || $grouped_item[0]->StoreId == 131 || $grouped_item[0]->StoreId == 30 || $grouped_item[0]->StoreId == 141 || $grouped_item[0]->StoreId == 162 || $grouped_item[0]->StoreId == 185 || $grouped_item[0]->StoreId == 244) {
$tax_value = 0;
} else {
$tax_value = 0.10;
}
}
$order_grandtotal = $updated_getSubtotal[0]->Subtotal;
$tax = $order_grandtotal * $tax_value;
return [
'tax' => $tax,
'order_grandtotal' => $order_grandtotal,
];
}
public function getDone(Request $request)
{
$paypal_model = new PayPalModel;
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$userId = Auth::user()->id;
$user_email = Auth::user()->email;
$checkCartKey = $paypal_model->checkCartKey($cartKey);
if (count($checkCartKey) > 0) {
$message = 'You already paid for this order. Please check your Order Page. <a href="user/orders"> <strong> <u>click here</u> </strong></a>.';
Session::put('cartkeyError', $message);
return Redirect::route('cart');
}
$id = $request->get('paymentId');
$token = $request->get('token');
$payer_id = $request->get('PayerID');
try {
$payment = PayPal::getById($id, $this->_apiContext);
$payment = PayPal::getById($id, $this->_apiContext);
$paymentExecution = PayPal::PaymentExecution();
$paymentExecution = PayPal::PaymentExecution();
$paymentExecution->setPayerId($payer_id);
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
$obj = json_decode($executePayment);
// var_dump($obj);
if ($executePayment->getState() == 'approved') {
/** it's all right **/
/** Here Write your database logic like that insert record or value in database if you want **/
// \Session::put('success','Payment success');
// return Redirect::route('paywithpaypal');
$line2 = null;
//details
$total = $obj->transactions[0]->amount->total;
$sub_total = $obj->transactions[0]->amount->details->subtotal;
$tax = $obj->transactions[0]->amount->details->tax;
$shipping = $obj->transactions[0]->amount->details->shipping;
$relatedResources = $obj->transactions[0]->related_resources[0];
$saleId = $relatedResources->sale->id; // transaction_id
$currency = $obj->transactions[0]->amount->currency;
$invoice_number = $obj->transactions[0]->invoice_number;
// var_dump( $obj->transactions[0]->item_list->phone);
//shipping address details
$recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name;
$line1 = $obj->transactions[0]->item_list->shipping_address->line1;
if (isset($obj->transactions[0]->item_list->shipping_address->line2)) {
$line2 = $obj->transactions[0]->item_list->shipping_address->line2;
}
$city = $obj->transactions[0]->item_list->shipping_address->city;
$state = $obj->transactions[0]->item_list->shipping_address->state;
$postal_code = $obj->transactions[0]->item_list->shipping_address->postal_code;
$country_code = $obj->transactions[0]->item_list->shipping_address->country_code;
// payer info
$payment_method = $obj->payer->payment_method;
$email = $obj->payer->payer_info->email;
$first_name = $obj->payer->payer_info->first_name;
$last_name = $obj->payer->payer_info->last_name;
$_payer_id = $obj->payer->payer_info->payer_id;
/// end paypal codes
$payment_details = array(
'UserId' => $userId,
'CartKey' => $cartKey,
'PaymentId' => $id,
'Token' => $token,
'PayerId' => $payer_id,
'InvoiceNumber' => $invoice_number,
'Currency' => $currency,
'Total' => $total,
'SubTotal' => $sub_total,
'Tax' => $tax,
'Payer_Email' => $email,
'Payer_Firstname' => $first_name,
'Payer_Lastname' => $last_name,
'PaymentMethod' => $payment_method,
'ShippingCost' => $shipping,
'TransactionId' => $saleId
);
$p_id = $paypal_model->insertToPaypalDetails($payment_details);
$shipping_address = array(
'PaymentDetail_Id' => $p_id,
'recipient_name' => $recipient_name,
'line1' => $line1,
'line2' => $line2,
'city' => $city,
'state' => $state,
'postal_code' => $postal_code,
'country_code' => $country_code,
);
// iinsert shipping address
$paypal_model->insertShippingAddress($shipping_address);
// insert order from cart_tmp to orders table
$l = $paypal_model->insertToOrders($cartKey); // insert to orders table
//email sending
$newUserModel = new UserModel;
$order_item_array = $newUserModel->selectOrderItem($cartKey);
$item_goup_array = $newUserModel->itemGroup($cartKey);
$item_thumbs = $newUserModel->selectDisplayItemThumb();
$array_payment_details = $newUserModel->selectPaymentDetails('CartKey', $cartKey);
$array_storename = $newUserModel->selectTeamStoreName($cartKey); // email subject
foreach ($array_storename as $storname) {
$sName[] = $storname->StoreName;
$sid[] = $storname->Id;
}
$sName = implode(", ", $sName);
$user_loginsArray = $newUserModel->selectUserLoginsWhereIn($sid);
foreach ($user_loginsArray as $userdata) {
$other_email[] = $userdata->other_email;
}
if ($other_email[0] != null) {
$other_email = implode(", ", array_filter($other_email, function ($value) {
return !is_null($value) && $value !== '';
}));
$email_cc = "orders@crewsportswear.com" . "," . $other_email;
} else {
$email_cc = "orders@crewsportswear.com";
}
$explode_other_email = explode(",", $email_cc);
$data = array(
'order_item_array' => $order_item_array,
'item_goup_array' => $item_goup_array,
'img_thumb' => $item_thumbs,
'array_payment_details' => $array_payment_details,
'receiver' => $user_email,
'email_cc' => $explode_other_email,
'subject' => $sName . ' ORDERS',
);
Mail::send('emails.orders', $data, function ($message) use ($data) {
$message->from('no-reply@crewsportswear.com', 'CREW Sportswear');
$message->bcc($data['email_cc'], 'Orders From CREW Sportswear');
$message->to($data['receiver'])->subject($data['subject']);
});
// end email sending
$insertTracking = array(
"StepId" => 1,
"ScannedBy" => 1,
"InvoiceNumber" => $invoice_number,
"created_at" => date('Y-m-d H:i:s')
);
$ApiModel = new ApiModel;
$ApiModel->insertTracking($insertTracking);
$request->session()->forget('cartkey'); // clear session for cartkey
// redirect to thank you page.
return view('paypal.get_done')
->with('currency', $currency)
->with('total', $total);
} else {
Session::put('cartkeyError', 'Something went wrong. Please try again.');
return Redirect::route('cart');
}
} catch (PayPalConnectionException $e) {
//throw $th;
// echo $e->getCode();
echo $e->getData();
Session::put('cartkeyError', 'Invalid payment.');
return Redirect::route('cart');
}
$paymentExecution->setPayerId($payer_id);
$executePayment = $payment->execute($paymentExecution, $this->_apiContext);
// print_r($executePayment);
// if ($executePayment->getState() == 'approved') {
@@ -257,157 +594,9 @@ class PaypalController extends Controller
// // return Redirect::route('paywithpaypal');
// echo 'Payment success';
// }
$obj = json_decode($executePayment);
$line2 = null;
//details
$total = $obj->transactions[0]->amount->total;
$sub_total = $obj->transactions[0]->amount->details->subtotal;
$tax = $obj->transactions[0]->amount->details->tax;
$shipping = $obj->transactions[0]->amount->details->shipping;
$relatedResources = $obj->transactions[0]->related_resources[0];
$saleId = $relatedResources->sale->id; // transaction_id
$currency = $obj->transactions[0]->amount->currency;
$invoice_number = $obj->transactions[0]->invoice_number;
//shipping address details
$recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name;
$line1 = $obj->transactions[0]->item_list->shipping_address->line1;
if (isset($obj->transactions[0]->item_list->shipping_address->line2)) {
$line2 = $obj->transactions[0]->item_list->shipping_address->line2;
}
$city = $obj->transactions[0]->item_list->shipping_address->city;
$state = $obj->transactions[0]->item_list->shipping_address->state;
$postal_code = $obj->transactions[0]->item_list->shipping_address->postal_code;
$country_code = $obj->transactions[0]->item_list->shipping_address->country_code;
// payer info
$payment_method = $obj->payer->payment_method;
$email = $obj->payer->payer_info->email;
$first_name = $obj->payer->payer_info->first_name;
$last_name = $obj->payer->payer_info->last_name;
$_payer_id = $obj->payer->payer_info->payer_id;
/// end paypal codes
$paypal_model = new PayPalModel;
$m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey');
$userId = Auth::user()->id;
$user_email = Auth::user()->email;
$items = $m->myCart($cartKey); // item from cart_tmp
$getSubtotal = $m->getSubtotal($cartKey);
$payment_details = array(
'UserId' => $userId,
'CartKey' => $cartKey,
'PaymentId' => $id,
'Token' => $token,
'PayerId' => $payer_id,
'InvoiceNumber' => $invoice_number,
'Currency' => $currency,
'Total' => $total,
'SubTotal' => $sub_total,
'Tax' => $tax,
'Payer_Email' => $email,
'Payer_Firstname' => $first_name,
'Payer_Lastname' => $last_name,
'PaymentMethod' => $payment_method,
'ShippingCost' => $shipping,
'TransactionId' => $saleId
);
$p_id = $paypal_model->insertToPaypalDetails($payment_details);
$shipping_address = array(
'PaymentDetail_Id' => $p_id,
'recipient_name' => $recipient_name,
'line1' => $line1,
'line2' => $line2,
'city' => $city,
'state' => $state,
'postal_code' => $postal_code,
'country_code' => $country_code,
);
// iinsert shipping address
$paypal_model->insertShippingAddress($shipping_address);
// insert order from cart_tmp to orders table
$l = $paypal_model->insertToOrders($cartKey); // insert to orders table
//email sending
$newUserModel = new UserModel;
$order_item_array = $newUserModel->selectOrderItem($cartKey);
$item_goup_array = $newUserModel->itemGroup($cartKey);
$item_thumbs = $newUserModel->selectDisplayItemThumb();
$array_payment_details = $newUserModel->selectPaymentDetails('CartKey', $cartKey);
$array_storename = $newUserModel->selectTeamStoreName($cartKey); // email subject
foreach ($array_storename as $storname) {
$sName[] = $storname->StoreName;
$sid[] = $storname->Id;
}
$sName = implode(", ", $sName);
$user_loginsArray = $newUserModel->selectUserLoginsWhereIn($sid);
foreach ($user_loginsArray as $userdata) {
$other_email[] = $userdata->other_email;
}
if ($other_email[0] != null) {
$other_email = implode(", ", array_filter($other_email, function($value) { return !is_null($value) && $value !== ''; }));
$email_cc = "orders@crewsportswear.com" . "," . $other_email;
} else {
$email_cc = "orders@crewsportswear.com";
}
$explode_other_email = explode(",", $email_cc);
$data = array(
'order_item_array' => $order_item_array,
'item_goup_array' => $item_goup_array,
'img_thumb' => $item_thumbs,
'array_payment_details' => $array_payment_details,
'receiver' => $user_email,
'email_cc' => $explode_other_email,
'subject' => $sName . ' ORDERS',
);
Mail::send('emails.orders', $data, function ($message) use ($data) {
$message->from('no-reply@crewsportswear.com', 'CREW Sportswear');
$message->bcc($data['email_cc'], 'Orders From CREW Sportswear');
$message->to($data['receiver'])->subject($data['subject']);
});
// end email sending
$insertTracking = array(
"StepId" => 1,
"ScannedBy" => 1,
"InvoiceNumber" => $invoice_number,
"created_at" => date('Y-m-d H:i:s')
);
$ApiModel = new ApiModel;
$ApiModel->insertTracking($insertTracking);
$request->session()->forget('cartkey'); // clear session for cartkey
// redirect to thank you page.
return view('paypal.get_done')
->with('currency', $currency)
->with('total', $total);
// var_dump($obj->payer->payer_info->shipping_address);
// var_dump($obj->transactions[0]->item_list->shipping_address);
}
@@ -419,6 +608,10 @@ class PaypalController extends Controller
$items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey);
if ($items == null) {
return redirect()->route('cart');
}
foreach ($items as $item) {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId;
@@ -441,4 +634,47 @@ class PaypalController extends Controller
return redirect()->route('cart');
}
}
public function createWebProfile()
{
$UserModel = new UserModel;
$userId = Auth::user()->id;
$array_address_book = $UserModel->selectAddresBook('UserId', $userId);
if (count($array_address_book) <= 0) {
$message = 'Please add Shipping address.';
Session::flash('cartkeyError', $message);
return Redirect::back();
}
// $shippingAddress = [
// "recipient_name" => ,
$flowConfig = PayPal::FlowConfig();
$presentation = PayPal::Presentation();
$inputFields = PayPal::InputFields();
$webProfile = PayPal::WebProfile();
// $presentation->setLogoImage("https://www.crewsportswear.com/beta/public/images/logo.png")->setBrandName("Merchbay"); //NB: Paypal recommended to use https for the logo's address and the size set to 190x60.
$presentation->setBrandName("Crewsportswear"); //NB: Paypal recommended to use https for the logo's address and the size set to 190x60.
if ($array_address_book[0]->CountryCode == "CA") {
$flowConfig->setLandingPageType("Billing"); //Set the page type
$inputFields->setAllowNote(true)->setAddressOverride(1);
} else {
$inputFields->setAllowNote(true)->setAddressOverride(0);
}
$webProfile->setName("Crewsportswear " . uniqid())
->setFlowConfig($flowConfig)
// Parameters for style and presentation.
->setPresentation($presentation)
// Parameters for input field customization.
->setInputFields($inputFields);
$createProfileResponse = $webProfile->create($this->_apiContext);
return $createProfileResponse->getId(); //The new webprofile's id
}
}

View File

@@ -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');
});
}
}
}

View File

@@ -79,11 +79,13 @@ class UserController extends Controller {
'ContactNumber' => $post['mobilenumber'],
'OtherNotes' => $post['othernotes'],
'Address' => $post['address'],
'Address2' => $post['address2'],
'State' => $post['state'],
'City' => $post['city'],
'ZipCode' => $post['zipcode']
'ZipCode' => $post['zipcode'],
'CountryCode' => $post['countryCode'],
'Country' => $post['country']
);
echo $i = $m->insertAddressBook($data);
}
@@ -116,11 +118,15 @@ class UserController extends Controller {
'ContactNumber' => $post['mobilenumber'],
'OtherNotes' => $post['othernotes'],
'Address' => $post['address'],
'Address2' => $post['address2'],
'State' => $post['state'],
'City' => $post['city'],
'ZipCode' => $post['zipcode']
'ZipCode' => $post['zipcode'],
'CountryCode' => $post['countryCode'],
'Country' => $post['country']
);
echo $i = $m->saveUpdateAddressBook($data, $id);
}

View File

@@ -1,9 +1,13 @@
<?php namespace App\Http\Middleware;
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Support\Facades\URL;
class Authenticate {
class Authenticate
{
/**
* The Guard implementation.
@@ -32,19 +36,19 @@ class Authenticate {
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
else
{
} else {
$prev = URL::previous();
if (str_contains($prev, ['cart'])) {
return redirect()->guest('auth/register?redirectUrl='. $prev);
}
return redirect()->guest('auth/login');
}
}
return $next($request);
}
}

View File

@@ -37,5 +37,15 @@ class PayPalModel extends Model {
->get();
// var_dump($i);
return $i;
}
}
function checkCartKey($ck){
$i = DB::table('payment_details')
->where('CartKey', $ck)
// ->take(1)
->get();
// var_dump($i);
return $i;
}
}

View File

@@ -35,13 +35,13 @@ return [
],
// sandbox
// 'paypal' => [
// 'client_id' => 'AQuz-HKzQiL7FygkG8skSekaWf-RP6Rgj4f1XeX1Ghp86bUFj7tQXVT1xbpluu5_WCGRbQpOVGtlJKVB',
// 'secret' => 'EJAMKxQsl-mFkL_4J_90cvTamYfcsgswqgIxz9wQPiRAwJ6sy_wNsttMlmrXIpxI96JpYzdMXkLCHAPz'
// ],
'paypal_sandbox' => [
'client_id' => 'AQuz-HKzQiL7FygkG8skSekaWf-RP6Rgj4f1XeX1Ghp86bUFj7tQXVT1xbpluu5_WCGRbQpOVGtlJKVB',
'secret' => 'EJAMKxQsl-mFkL_4J_90cvTamYfcsgswqgIxz9wQPiRAwJ6sy_wNsttMlmrXIpxI96JpYzdMXkLCHAPz'
],
// live
'paypal' => [
'paypal_live' => [
'client_id' => 'AUqBUFW5lfyYmrlBtFZA3RNw45sttM3ltbvS_d4qCVBMrkcMG9rEeivGvtNFSy8XTiEp50YyQ6khKxbq',
'secret' => 'ELlnuiupoFKwGUSc2g5j-sD1EmsvKpdhth1gFV7njpfvyNtKsK8WwIKUMOS0ehJcRatV865eMhfgsnd_'
],

372
public/api/canada.json Normal file
View File

@@ -0,0 +1,372 @@
{
"Alberta": [
"Airdrie",
"Grande Prairie",
"Red Deer",
"Beaumont",
"Hanna",
"St. Albert",
"Bonnyville",
"Hinton",
"Spruce Grove",
"Brazeau",
"Irricana",
"Strathcona County",
"Breton",
"Lacombe",
"Strathmore",
"Calgary",
"Leduc",
"Sylvan Lake",
"Camrose",
"Lethbridge",
"Swan Hills",
"Canmore",
"McLennan",
"Taber",
"Didzbury",
"Medicine Hat",
"Turner Valley",
"Drayton Valley",
"Olds",
"Vermillion",
"Edmonton",
"Onoway",
"Wood Buffalo",
"Ft. Saskatchewan",
"Provost"
],
"British Columbia": [
"Burnaby",
"Lumby",
"City of Port Moody",
"Cache Creek",
"Maple Ridge",
"Prince George",
"Castlegar",
"Merritt",
"Prince Rupert",
"Chemainus",
"Mission",
"Richmond",
"Chilliwack",
"Nanaimo",
"Saanich",
"Clearwater",
"Nelson",
"Sooke",
"Colwood",
"New Westminster",
"Sparwood",
"Coquitlam",
"North Cowichan",
"Surrey",
"Cranbrook",
"North Vancouver",
"Terrace",
"Dawson Creek",
"North Vancouver",
"Tumbler",
"Delta",
"Osoyoos",
"Vancouver",
"Fernie",
"Parksville",
"Vancouver",
"Invermere",
"Peace River",
"Vernon",
"Kamloops",
"Penticton",
"Victoria",
"Kaslo",
"Port Alberni",
"Whistler",
"Langley",
"Port Hardy"
],
"Manitoba": [
"Birtle",
"Flin Flon",
"Swan River",
"Brandon",
"Snow Lake",
"The Pas",
"Cranberry Portage",
"Steinbach",
"Thompson",
"Dauphin",
"Stonewall",
"Winnipeg"
],
"New Brunswick": [
"Cap-Pele",
"Miramichi",
"Saint John",
"Fredericton",
"Moncton",
"Saint Stephen",
"Grand Bay-Westfield",
"Oromocto",
"Shippagan",
"Grand Falls",
"Port Elgin",
"Sussex",
"Memramcook",
"Sackville",
"Tracadie-Sheila"
],
"Newfoundland And Labrador": [
"Argentia",
"Corner Brook",
"Paradise",
"Bishop's Falls",
"Labrador City",
"Portaux Basques",
"Botwood",
"Mount Pearl",
"St. John's",
"Brigus"
],
"Northwest Territories": [
"Town of Hay River",
"Town of Inuvik",
"Yellowknife"
],
"Nova Scotia": [
"Amherst",
"Hants County",
"Pictou",
"Annapolis",
"Inverness County",
"Pictou County",
"Argyle",
"Kentville",
"Queens",
"Baddeck",
"County of Kings",
"Richmond",
"Bridgewater",
"Lunenburg",
"Shelburne",
"Cape Breton",
"Lunenburg County",
"Stellarton",
"Chester",
"Mahone Bay",
"Truro",
"Cumberland County",
"New Glasgow",
"Windsor",
"East Hants",
"New Minas",
"Yarmouth",
"Halifax",
"Parrsboro"
],
"Ontario": [
"Ajax",
"Halton",
"Peterborough",
"Atikokan",
"Halton Hills",
"Pickering",
"Barrie",
"Hamilton",
"Port Bruce",
"Belleville",
"Hamilton-Wentworth",
"Port Burwell",
"Blandford-Blenheim",
"Hearst",
"Port Colborne",
"Blind River",
"Huntsville",
"Port Hope",
"Brampton",
"Ingersoll",
"Prince Edward",
"Brant",
"James",
"Quinte West",
"Brantford",
"Kanata",
"Renfrew",
"Brock",
"Kincardine",
"Richmond Hill",
"Brockville",
"King",
"Sarnia",
"Burlington",
"Kingston",
"Sault Ste. Marie",
"Caledon",
"Kirkland Lake",
"Scarborough",
"Cambridge",
"Kitchener",
"Scugog",
"Chatham-Kent",
"Larder Lake",
"Souix Lookout CoC Sioux Lookout",
"Chesterville",
"Leamington",
"Smiths Falls",
"Clarington",
"Lennox-Addington",
"South-West Oxford",
"Cobourg",
"Lincoln",
"St. Catharines",
"Cochrane",
"Lindsay",
"St. Thomas",
"Collingwood",
"London",
"Stoney Creek",
"Cornwall",
"Loyalist Township",
"Stratford",
"Cumberland",
"Markham",
"Sudbury",
"Deep River",
"Metro Toronto",
"Temagami",
"Dundas",
"Merrickville",
"Thorold",
"Durham",
"Milton",
"Thunder Bay",
"Dymond",
"Nepean",
"Tillsonburg",
"Ear Falls",
"Newmarket",
"Timmins",
"East Gwillimbury",
"Niagara",
"Toronto",
"East Zorra-Tavistock",
"Niagara Falls",
"Uxbridge",
"Elgin",
"Niagara-on-the-Lake",
"Vaughan",
"Elliot Lake",
"North Bay",
"Wainfleet",
"Flamborough",
"North Dorchester",
"Wasaga Beach",
"Fort Erie",
"North Dumfries",
"Waterloo",
"Fort Frances",
"North York",
"Waterloo",
"Gananoque",
"Norwich",
"Welland",
"Georgina",
"Oakville",
"Wellesley",
"Glanbrook",
"Orangeville",
"West Carleton",
"Gloucester",
"Orillia",
"West Lincoln",
"Goulbourn",
"Osgoode",
"Whitby",
"Gravenhurst",
"Oshawa",
"Wilmot",
"Grimsby",
"Ottawa",
"Windsor",
"Guelph",
"Ottawa-Carleton",
"Woolwich",
"Haldimand-Norfork",
"Owen Sound",
"York"
],
"Prince Edward Island": [
"Alberton",
"Montague",
"Stratford",
"Charlottetown",
"Souris",
"Summerside",
"Cornwall"
],
"Quebec": [
"Alma",
"Fleurimont",
"Longueuil",
"Amos",
"Gaspe",
"Marieville",
"Anjou",
"Gatineau",
"Mount Royal",
"Aylmer",
"Hull",
"Montreal",
"Beauport",
"Joliette",
"Montreal Region",
"Bromptonville",
"Jonquiere",
"Montreal-Est",
"Brosssard",
"Lachine",
"Quebec",
"Chateauguay",
"Lasalle",
"Saint-Leonard",
"Chicoutimi",
"Laurentides",
"Sherbrooke",
"Coaticook",
"LaSalle",
"Sorel",
"Coaticook",
"Laval",
"Thetford Mines",
"Dorval",
"Lennoxville",
"Victoriaville",
"Drummondville",
"Levis"
],
"Saskatchewan": [
"Avonlea",
"Melfort",
"Swift Current",
"Colonsay",
"Nipawin",
"Tisdale",
"Craik",
"Prince Albert",
"Unity",
"Creighton",
"Regina",
"Weyburn",
"Eastend",
"Saskatoon",
"Wynyard",
"Esterhazy",
"Shell Lake",
"Yorkton",
"Gravelbourg"
],
"Yukon": [
"Carcross",
"Whitehorse"
]
}

238
public/api/usa.json Normal file
View File

@@ -0,0 +1,238 @@
[
{
"name": "Alabama",
"abbreviation": "AL"
},
{
"name": "Alaska",
"abbreviation": "AK"
},
{
"name": "American Samoa",
"abbreviation": "AS"
},
{
"name": "Arizona",
"abbreviation": "AZ"
},
{
"name": "Arkansas",
"abbreviation": "AR"
},
{
"name": "California",
"abbreviation": "CA"
},
{
"name": "Colorado",
"abbreviation": "CO"
},
{
"name": "Connecticut",
"abbreviation": "CT"
},
{
"name": "Delaware",
"abbreviation": "DE"
},
{
"name": "District Of Columbia",
"abbreviation": "DC"
},
{
"name": "Federated States Of Micronesia",
"abbreviation": "FM"
},
{
"name": "Florida",
"abbreviation": "FL"
},
{
"name": "Georgia",
"abbreviation": "GA"
},
{
"name": "Guam",
"abbreviation": "GU"
},
{
"name": "Hawaii",
"abbreviation": "HI"
},
{
"name": "Idaho",
"abbreviation": "ID"
},
{
"name": "Illinois",
"abbreviation": "IL"
},
{
"name": "Indiana",
"abbreviation": "IN"
},
{
"name": "Iowa",
"abbreviation": "IA"
},
{
"name": "Kansas",
"abbreviation": "KS"
},
{
"name": "Kentucky",
"abbreviation": "KY"
},
{
"name": "Louisiana",
"abbreviation": "LA"
},
{
"name": "Maine",
"abbreviation": "ME"
},
{
"name": "Marshall Islands",
"abbreviation": "MH"
},
{
"name": "Maryland",
"abbreviation": "MD"
},
{
"name": "Massachusetts",
"abbreviation": "MA"
},
{
"name": "Michigan",
"abbreviation": "MI"
},
{
"name": "Minnesota",
"abbreviation": "MN"
},
{
"name": "Mississippi",
"abbreviation": "MS"
},
{
"name": "Missouri",
"abbreviation": "MO"
},
{
"name": "Montana",
"abbreviation": "MT"
},
{
"name": "Nebraska",
"abbreviation": "NE"
},
{
"name": "Nevada",
"abbreviation": "NV"
},
{
"name": "New Hampshire",
"abbreviation": "NH"
},
{
"name": "New Jersey",
"abbreviation": "NJ"
},
{
"name": "New Mexico",
"abbreviation": "NM"
},
{
"name": "New York",
"abbreviation": "NY"
},
{
"name": "North Carolina",
"abbreviation": "NC"
},
{
"name": "North Dakota",
"abbreviation": "ND"
},
{
"name": "Northern Mariana Islands",
"abbreviation": "MP"
},
{
"name": "Ohio",
"abbreviation": "OH"
},
{
"name": "Oklahoma",
"abbreviation": "OK"
},
{
"name": "Oregon",
"abbreviation": "OR"
},
{
"name": "Palau",
"abbreviation": "PW"
},
{
"name": "Pennsylvania",
"abbreviation": "PA"
},
{
"name": "Puerto Rico",
"abbreviation": "PR"
},
{
"name": "Rhode Island",
"abbreviation": "RI"
},
{
"name": "South Carolina",
"abbreviation": "SC"
},
{
"name": "South Dakota",
"abbreviation": "SD"
},
{
"name": "Tennessee",
"abbreviation": "TN"
},
{
"name": "Texas",
"abbreviation": "TX"
},
{
"name": "Utah",
"abbreviation": "UT"
},
{
"name": "Vermont",
"abbreviation": "VT"
},
{
"name": "Virgin Islands",
"abbreviation": "VI"
},
{
"name": "Virginia",
"abbreviation": "VA"
},
{
"name": "Washington",
"abbreviation": "WA"
},
{
"name": "West Virginia",
"abbreviation": "WV"
},
{
"name": "Wisconsin",
"abbreviation": "WI"
},
{
"name": "Wyoming",
"abbreviation": "WY"
}
]

File diff suppressed because it is too large Load Diff

23909
public/api/usaCities.old.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -18,7 +19,7 @@
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="{{asset('public/assets/css/style.css')}}" rel="stylesheet">
<!-- <link href="{{asset('public/assets/login/css/style.css')}}" rel="stylesheet">
<link href="{{asset('public/assets/login/css/form-elements.css')}}" rel="stylesheet"> -->
@@ -27,12 +28,16 @@
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-136108155-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-136108155-1');
</script>
</head>
<body>
<!-- <nav class="navbar navbar-default">
<div class="container">
@@ -70,14 +75,14 @@
@include('layout.navbar')
@yield('content')
<!-- Footer -->
<!-- Scripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script>
$(document).ready(function(){
$('.reveal-password').click(function(e){
$(document).ready(function() {
$('.reveal-password').click(function(e) {
var $pwd = $(".pwd");
if ($pwd.attr('type') === 'password') {
$pwd.attr('type', 'text');
@@ -88,7 +93,7 @@
}
});
if($('.data-errors').length > 0){
if ($('.data-errors').length > 0) {
$('#team-store-login').modal('show')
return false;
}
@@ -109,7 +114,7 @@
var placement = $(element).data('error');
if (placement) {
$(placement).append(error);
}else {
} else {
error.insertAfter(element);
}
},
@@ -118,12 +123,15 @@
$("#frm-register").validate({
rules: {
name: {
required : true
firstname: {
required: true
},
username: {
required : true
lastname: {
required: true
},
// username: {
// required: true
// },
email: {
required: true,
email: true
@@ -131,6 +139,24 @@
password: {
required: true
//minlength: 6 // <-- removed underscore
},
mobilenumber: {
required: true
},
address: {
required: true
},
state: {
required: true
},
city: {
required: true
},
zipcode: {
required: true
},
countryCode: {
required: true
}
},
messages: {},
@@ -138,14 +164,14 @@
var placement = $(element).data('error');
if (placement) {
$(placement).append(error);
}else {
} else {
error.insertAfter(element);
}
},
submitHandler: submitRegisterForm
});
$('.password-protected').click(function(){
$('.password-protected').click(function() {
$('#_teamstore_id').val($(this).data('store-id'))
// console.log($(this).data('store-id'))
@@ -158,32 +184,173 @@
event.preventDefault();
$('#frm_search_store').submit();
});
}); // end document ready
function submitLoginForm (){
function getSelectedCountry() {
var selectedState = $('#select_country').data('selected');
if (selectedState) {
// console.log(selectedState)
$("#select_country").val(selectedState).change();
// selectCountry()
}
}
function selectCountry(item) {
const country = item.options[item.selectedIndex].text;
const countryCode = item.options[item.selectedIndex].value
console.log(countryCode)
if (countryCode === "US") {
fetchUSA()
}
if (countryCode === "CA") {
fetchCanada()
}
}
function fetchCanada() {
$.getJSON("{{ asset('/public/api/canada.json') }}", function(items) {
var states = [];
Object.keys(items).forEach(function(state) {
states.push(state)
});
var uniqueStates = Array.from(new Set(states));
var selectedState = $('#lst-states').data('selected');
$('.dynamic-state').remove();
$('.dynamic-city').remove();
uniqueStates.sort().forEach(function(key) {
if (selectedState == key) {
$('#lst-states').append('<option value="' + key + '" selected class="dynamic-state">' + key + '</option>');
var cities = [];
cities = items[selectedState];
var uniqueCities = Array.from(new Set(cities));
var selectedCity = $('#lst-cities').data('selected');
$('.dynamic-city').remove();
uniqueCities.sort().forEach(function(key) {
if (selectedCity == key) {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city" selected>' + key + '</option>');
} else {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
}
});
} else {
$('#lst-states').append('<option value="' + key + '" class="dynamic-state">' + key + '</option>');
}
});
$(document).on('select change', '#lst-states', function() {
var cities = [];
var selectedState = $(this).val()
cities = items[selectedState];
var uniqueCities = Array.from(new Set(cities));
$('.dynamic-city').remove();
uniqueCities.sort().forEach(function(key) {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
});
});
});
}
function fetchUSA() {
$.getJSON("{{ asset('/public/api/usaCities.json') }}", function(data) {
var states = [];
for (i = 0; i < data.length; i++) {
states.push(data[i]['state']);
}
var uniqueStates = Array.from(new Set(states));
var selectedState = $('#lst-states').data('selected');
$('.dynamic-state').remove();
$('.dynamic-city').remove();
uniqueStates.sort().forEach(function(key) {
if (selectedState == key) {
$('#lst-states').append('<option value="' + key + '" selected class="dynamic-state">' + key + '</option>');
//
var cities = [];
for (i = 0; i < data.length; i++) {
console.log(data[i])
cities.push(data[i]);
}
var city = getCities(cities, key);
var uniqueCities = Array.from(new Set(city));
var selectedCity = $('#lst-cities').data('selected');
$('.dynamic-city').remove();
uniqueCities.sort().forEach(function(key) {
if (selectedCity == key) {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city" selected>' + key + '</option>');
} else {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
}
});
} else {
$('#lst-states').append('<option value="' + key + '" class="dynamic-state">' + key + '</option>');
}
});
$(document).on('select change', '#lst-states', function() {
var cities = [];
for (i = 0; i < data.length; i++) {
cities.push(data[i]);
}
var city = getCities(cities, $(this).val());
var uniqueCities = Array.from(new Set(city));
$('.dynamic-city').remove();
uniqueCities.sort().forEach(function(key) {
$('#lst-cities').append('<option value="' + key + '" class="dynamic-city">' + key + '</option>');
});
});
});
}
function getCities(arr, q) {
var sd = [];
arr.find(function(element) {
if (element['state'] == q) {
sd.push(element['city']);
}
});
return sd;
}
function submitLoginForm() {
// method="POST" action="{{ url('/auth/login') }}"
var data = $("#frm-login").serialize();
// console.log(data)
$.ajax({
type : 'POST',
url : "{{ url('/custom/auth') }}",
data : data,
dataType : 'json',
beforeSend: function() {
type: 'POST',
url: "{{ url('/custom/auth') }}",
data: data,
dataType: 'json',
beforeSend: function() {
$("#login-response-msg").fadeOut();
$("#btn-login").html('Signing in &nbsp; <i class="fa fa-spinner fa-spin"></i>');
},
success : function(response){
success: function(response) {
$("#login-response-msg").html("");
$("#login-response-msg").fadeIn(1000, function(){
if(response.success){
$("#login-response-msg").fadeIn(1000, function() {
if (response.success) {
// $("#login-response-msg").html(response);
// console.log();
location.reload();
}else{
} else {
$("#login-response-msg").html(response.message);
}
//
@@ -194,27 +361,35 @@
}
});
return false;
}/* login submit */
} /* login submit */
function submitRegisterForm (){
var data = $("#frm-register").serialize();
function submitRegisterForm() {
var data = $("#frm-register").serializeArray();
data.push({
name: "country",
value: $("#select_country option:selected").text()
});
$.ajax({
type : 'POST',
url : "{{ url('/custom/register') }}",
data : data,
dataType : 'json',
beforeSend: function() {
type: 'POST',
url: "{{ url('/custom/register') }}",
data: data,
dataType: 'json',
beforeSend: function() {
$("#register-response-msg").fadeOut();
$("#btn-register").html('Please wait &nbsp; <i class="fa fa-spinner fa-spin"></i>');
},
success : function(response){
success: function(response) {
$("#register-response-msg").html("");
$("#register-response-msg").fadeIn(1000, function(){
if(response.success){
location.reload();
}else{
$("#register-response-msg").fadeIn(1000, function() {
if (response.success) {
if (response.redirect != "") {
window.location = response.redirect;
} else {
location.reload();
}
} else {
$("#register-response-msg").html(response.message);
}
$("#btn-register").html('Register');
@@ -226,8 +401,7 @@
return false;
}
</script>
</body>
</html>
</html>

View File

@@ -2,11 +2,12 @@
@section('content')
<style>
.error{
.error {
color: red;
}
.g-recaptcha {
width:100%;
width: 100%;
}
</style>
<div class="container">
@@ -22,25 +23,40 @@
<div class="col-xs-12">
<div id="register-response-msg"></div>
<form role="form" id="frm-register">
<div class="form-group text-center">
<h5>Personal Information</h5>
</div>
<input type="hidden" name="redirect" value="{{ Request::get('redirectUrl') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="control-label">Fullname</label>
<input type="text" class="form-control" name="name" value="{{ old('name') }}" placeholder="Fullname">
<label class="control-label">First name</label>
<input type="text" class="form-control" name="firstname" placeholder="First name">
</div>
<div class="form-group">
<label class="control-label">Last name</label>
<input type="text" class="form-control" name="lastname" placeholder="Last name">
</div>
<!-- <div class="form-group">
<label class="control-label">Username</label>
<input type="text" class="form-control" name="username" value="{{ old('username') }}" placeholder="Username">
</div>
</div> -->
<div class="form-group">
<label class="control-label">Email Address</label>
<input type="email" class="form-control" name="email" value="{{ old('email') }}" placeholder="Email Address">
</div>
<div class="form-group">
<label class="control-label">Phone Number</label>
<input type="text" class="form-control" name="mobilenumber" placeholder="Phone Number">
</div>
<div class="form-group">
<label class="control-label">Password</label>
<input type="password" class="form-control" name="password" id="password" required placeholder="Password">
<input type="password" class="form-control" name="password" id="password" required placeholder="Password">
</div>
<div class="form-group">
@@ -48,6 +64,50 @@
<input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password" data-rule-equalTo="#password" required>
</div>
<div class="form-group text-center">
<h5>Address Information</h5>
</div>
<div class="form-group">
<label class="control-label">Select Country</label>
<select name="countryCode" id="select_country" class="form-control" onchange="selectCountry(this)">
<option value="">Select Country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
</div>
<div class="form-group">
<label class="control-label">State / Province</label>
<label></label>
<select class="form-control" name="state" id="lst-states">
<option value="">Select State</option>
</select>
</div>
<div class="form-group">
<label class="control-label">City</label>
<select class="form-control" name="city" id="lst-cities">
<option value="">Select City</option>
</select>
</div>
<div class="form-group">
<label class="control-label">Address 1</label>
<input type="text" class="form-control" name="address" placeholder="Address 1">
</div>
<div class="form-group">
<label class="control-label">Address 2</label>
<input type="text" class="form-control" name="address2" placeholder="Address 2">
</div>
<div class="form-group">
<label class="control-label">Zip Code</label>
<input type="text" class="form-control" name="zipcode" placeholder="Please enter your zip code">
</div>
<div class="form-group">
<div class="g-recaptcha text-center" data-sitekey="{{ env('CAPTCHA_SITE_KEY') }}"></div>
</div>
@@ -57,7 +117,7 @@
<div class="form-group">
<button type="submit" id="btn-register" class="btn btn-primary btn-block">Register</button>
</div>
</form>
</div>
</div>
@@ -74,4 +134,4 @@
</div>
</div>
</div>
@endsection
@endsection

View File

@@ -29,7 +29,7 @@
@if(Session::has('cartkeyError'))
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="fa fa-exclamation-circle"></i> Error:</h4>
<h4><i class="fa fa-exclamation-circle"></i> Almost there:</h4>
{!! Session::get('cartkeyError') !!}
</div>
@endif
@@ -51,9 +51,42 @@
@endif
<h3>Order Summary</h3>
</div>
@if (!Auth::guest())
<div style="border: 1px solid #e2e2e2; padding: 10px; border-bottom: none;">
<p><strong>Ship to:</strong></p>
@if ($address_book === null)
<a href="{{ url('user/address-book/create') }}">[ Add ]</a>
@else
<div>{{ $address_book[0]->Fullname }}</div>
<div>{{ $address_book[0]->ContactNumber }}</div>
<div>
{{ $address_book[0]->Address . ' ' . $address_book[0]->Address2 . ', ' . $address_book[0]->State . ', ' . $address_book[0]->City . ', ' . $address_book[0]->Country . ', ' . $address_book[0]->CountryCode . ' ' . $address_book[0]->ZipCode }}
<a href="{{ url('user/address-book/edit/'.$address_book[0]->Id) }}">[ Edit ]</a>
</div>
@endif
</div>
@endif
<div style="border: 1px solid #e2e2e2; padding: 10px; border-bottom: none;">
<h3>Subtotal: <span id="my_subtotal">{{ round($getSubtotal, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</small></h3>
{{-- <h3>Subtotal: <span id="my_subtotal">{{ round($getSubtotal, 2) }}</span> <small>{{ $store_array[0]->StoreCurrency }}</small></h3> --}}
<h5><strong>Subtotal:</strong>
<span>{{ number_format($tax['order_grandtotal'], 2) . ' ' . $store_array[0]->StoreCurrency }}</span>
</h5>
<h5><strong>Shipping Fee:</strong>
<span>{{ number_format($shipping_fee, 2) . ' ' . $store_array[0]->StoreCurrency }}</span>
</h5>
<h5> <strong>Tax:</strong>
<span>{{ number_format($tax['tax'], 2) . ' ' . $store_array[0]->StoreCurrency }}</span>
</h5>
<hr>
<h3> <strong>Total:</strong> <span id="my_subtotal">{{ number_format($tax['order_grandtotal'] + $shipping_fee + $tax['tax'], 2) }}</span>
<span>{{ $store_array[0]->StoreCurrency }}</span>
</h3>
<hr>
<div class="form-group" id="voucher_list">
@foreach($row as $item)

View File

@@ -34,15 +34,13 @@
<tr>
<th>Full name</th>
<th>Address</th>
<th>Postcode</th>
<th>Phone Number</th>
<th class="text-center">Action</th>
</tr>
@foreach($array_address_book as $row)
<tr>
<td>{{ $row->Fullname }}</td>
<td>{{ $row->Address }}</td>
<td>{{ $row->State }}, {{ $row->City }}, {{ $row->ZipCode }}</td>
<td>{{ $row->Address . ' ' . $row->Address2 }}, {{ $row->State }}, {{ $row->City }}, {{ $row->Country}} {{ $row->CountryCode}}, {{ $row->ZipCode }}</td>
<td>{{ $row->ContactNumber }}</td>
<td class="text-center">
<a href="{{ url('user/address-book/edit/') }}/{{ $row->Id }}" class="btn btn-default btn-xs"><i class="fa fa-edit"></i> Edit</a>

View File

@@ -1,81 +1,93 @@
@extends('user-layouts.user_template')
@section('content')
<div class="content-wrapper" style="min-height: 916px;">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Address Book
<!-- <small>Control panel</small> -->
</h1>
<ol class="breadcrumb">
<li><a href="{{ url ('user') }}"><i class="fa fa-home"></i> Home</a></li>
<li><a href="{{ url ('user/address-book') }}"><i class="fa fa-address-book-o"></i> Address Book</a></li>
<li class="active">Add New Address</li>
</ol>
</section>
<div class="content-wrapper" style="min-height: 916px;">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Address Book
<!-- <small>Control panel</small> -->
</h1>
<ol class="breadcrumb">
<li><a href="{{ url ('user') }}"><i class="fa fa-home"></i> Home</a></li>
<li><a href="{{ url ('user/address-book') }}"><i class="fa fa-address-book-o"></i> Address Book</a></li>
<li class="active">Add New Address</li>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">
Add New Address
</h3>
</div>
<form role="form" id="frm-create-address-book">
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" name="fullname" placeholder="Fullaname">
</div>
<div class="form-group">
<label>Mobile Number</label>
<input type="text" class="form-control" name="mobilenumber" placeholder="Please enter your mobile number">
</div>
<div class="form-group">
<label>Other Notes</label>
<input type="text" class="form-control" name="othernotes" placeholder="Please enter your notes">
</div>
<!-- /.box-body -->
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">
Add New Address
</h3>
</div>
<form role="form" id="frm-create-address-book">
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" name="fullname" placeholder="Fullaname">
</div>
<div class="col-md-6">
<div class="form-group">
<label>House Number, Building and Street Name</label>
<input type="text" class="form-control" name="address" placeholder="Please enter your House Number, Building and Street Name">
</div>
<div class="form-group">
<label>State</label>
<select class="form-control" name="state" id="lst-states" >
<option value="">Select State</option>
</select>
</div>
<div class="form-group">
<label>City</label>
<select class="form-control" name="city" id="lst-cities">
<option value="">Select City</option>
</select>
</div>
<div class="form-group">
<label>Zip Code</label>
<input type="text" class="form-control" name="zipcode" placeholder="Please enter your zip code">
</div>
<div class="form-group">
<label>Mobile Number</label>
<input type="text" class="form-control" name="mobilenumber" placeholder="Please enter your mobile number">
</div>
<div class="form-group">
<label>Other Notes</label>
<input type="text" class="form-control" name="othernotes" placeholder="Please enter your notes">
</div>
<!-- /.box-body -->
</div>
<div class="col-md-6">
<div class="form-group">
<label>Country</label>
<select class="form-control" name="countryCode" id="select_country" onchange="selectCountry(this)">
<option value="">Select Country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
</div>
<div class="form-group">
<label>State / Province</label>
<select class="form-control" name="state" id="lst-states">
<option value="">Select State</option>
</select>
</div>
<div class="form-group">
<label>City</label>
<select class="form-control" name="city" id="lst-cities">
<option value="">Select City</option>
</select>
</div>
<div class="form-group">
<label>Address 1</label>
<textarea type="text" class="form-control" name="address" placeholder="Address 1"></textarea>
</div>
<div class="form-group">
<label>Address 2</label>
<textarea type="text" class="form-control" name="address2" placeholder="Address 2"></textarea>
</div>
<div class="form-group">
<label>Zip Code</label>
<input type="text" class="form-control" name="zipcode" placeholder="Please enter your zip code">
</div>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-custom-save">Save</button>
</div>
</form>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-custom-save">Save</button>
</div>
</form>
<div>
</div>
</div>
</div>
</section>
</section>
<!-- /.content -->
</div>
@endsection
</div>
@endsection

View File

@@ -46,8 +46,12 @@
</div>
<div class="col-md-6">
<div class="form-group">
<label>House Number, Building and Street Name</label>
<input type="text" class="form-control" name="address" placeholder="Please enter your House Number, Building and Street Name" value="{{ $array_address_book[0]->Address }}">
<label>Country</label>
<select class="form-control" name="countryCode" id="select_country" onchange="selectCountry(this)" data-selected="{{ $array_address_book[0]->CountryCode }}">
<option value="">Select Country</option>
<option value="US">United States</option>
<option value="CA">Canada</option>
</select>
</div>
<div class="form-group">
<label>State</label>
@@ -61,6 +65,15 @@
<option value="">Select City</option>
</select>
</div>
<div class="form-group">
<label>Address 1</label>
<input type="text" class="form-control" name="address" placeholder="Address 1" value="{{ $array_address_book[0]->Address }}">
</div>
<div class="form-group">
<label>Address 2</label>
<input type="text" class="form-control" name="address2" placeholder="Address 2" value="{{ $array_address_book[0]->Address2 }}">
</div>
<div class="form-group">
<label>Zip Code</label>
<input type="text" class="form-control" name="zipcode" placeholder="Please enter your zip code" value="{{ $array_address_book[0]->ZipCode }}">

File diff suppressed because it is too large Load Diff