add shipping cost

This commit is contained in:
franknstayn
2020-08-10 22:41:40 +08:00
parent 02361ca64e
commit 5918eded8c
11 changed files with 228 additions and 189 deletions

View File

@@ -1,42 +1,49 @@
<?php namespace App\Http\Controllers\paypal; <?php
use App\Http\Requests; namespace App\Http\Controllers\paypal;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Paypal; // use Paypal;
use Netshell\Paypal\Facades\Paypal;
use App\Models\teamstore\TeamStoreModel; use App\Models\teamstore\TeamStoreModel;
use App\Models\user\UserModel; use App\Models\user\UserModel;
use App\Models\paypal\PayPalModel; use App\Models\paypal\PayPalModel;
use Auth; // use Auth;
use Session; use Illuminate\Support\Facades\Auth;
use Redirect; // use Session;
use Mail; use Illuminate\Support\Facades\Session;
// use Redirect;
use Illuminate\Support\Facades\Redirect;
// use Mail;
use Illuminate\Support\Facades\Mail;
class PaypalController extends Controller { class PaypalController extends Controller
{
private $_apiContext; private $_apiContext;
public function __construct() public function __construct()
{ {
$this->_apiContext = PayPal::ApiContext( $this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'), config('services.paypal.client_id'),
config('services.paypal.secret')); config('services.paypal.secret')
);
/* $this->_apiContext->setConfig(array( // $this->_apiContext->setConfig(array(
'mode' => 'sandbox', // 'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com', // 'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30, // 'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true, // 'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'), // 'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE' // 'log.LogLevel' => 'FINE'
)); */ // ));
// live // live
$this->_apiContext->setConfig(array( $this->_apiContext->setConfig(array(
'mode' => 'live', 'mode' => 'live',
'service.EndPoint' => 'https://api.paypal.com', 'service.EndPoint' => 'https://api.paypal.com',
@@ -45,85 +52,106 @@ class PaypalController extends Controller {
'log.FileName' => storage_path('logs/paypal.log'), 'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE' 'log.LogLevel' => 'FINE'
)); ));
} }
public function payPremium() public function payPremium()
{ {
return view('payPremium'); return view('payPremium');
} }
public function getCheckout(Request $request) public function getCheckout(Request $request)
{ {
if(Auth::guest()){ if (Auth::guest()) {
$message = 'Please <a href="'. url('auth/login'). '">Sign in</a> to your account to proceed.'; $message = 'Please <a href="' . url('auth/login') . '">Sign in</a> to your account to proceed.';
Session::flash('msg', $message); Session::flash('msg', $message);
return Redirect::back(); return Redirect::back();
} }
$payer = PayPal::Payer(); $payer = PayPal::Payer();
$payer->setPaymentMethod('paypal'); $payer->setPaymentMethod('paypal');
$m = new TeamStoreModel; $m = new TeamStoreModel;
$paypal_model = new PayPalModel; $paypal_model = new PayPalModel;
$last_id = $paypal_model->getLastIdPaymentDetails(); $last_id = $paypal_model->getLastIdPaymentDetails();
$invoice_num = str_pad($last_id[0]->Id, 4,'0',STR_PAD_LEFT); $invoice_num = str_pad($last_id[0]->Id, 4, '0', STR_PAD_LEFT);
$cartKey = $request->session()->get('cartkey'); $cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey); $items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey); $getSubtotal = $m->getSubtotal($cartKey);
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey); $grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
$store_array = $m->selectTeamStore('Id', $grouped_item[0]->StoreId); $store_array = $m->selectTeamStore('Id', $grouped_item[0]->StoreId);
$getSmallItemQty = 0;
foreach($items as $item){ $getBulkyItemQty = 0;
if($item->VoucherId != null){ $getMaskItemQty = 0;
$shippingFee = 0;
foreach ($items as $item) {
if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId; $voucherIds[] = $item->VoucherId;
$voucher = $m->selectVoucherWhereIn($voucherIds); $voucher = $m->selectVoucherWhereIn($voucherIds);
$item_id = $item->Id; $item_id = $item->Id;
$totalValue = $voucher[0]->VoucherValue; $totalValue = $voucher[0]->VoucherValue;
if($voucher[0]->VoucherType == "Percentage"){ if ($voucher[0]->VoucherType == "Percentage") {
$getPercentageValue = $totalValue / 100; $getPercentageValue = $totalValue / 100;
$getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue); $getDiscountValue = ($getSubtotal[0]->Subtotal * $getPercentageValue);
$data = array( $data = array(
'Price' => round($getDiscountValue * -1, 2) 'Price' => round($getDiscountValue * -1, 2)
); );
$m->updateVoucherValueInCart($data, $item_id); $m->updateVoucherValueInCart($data, $item_id);
}else{ } else {
$voucherData = array( $voucherData = array(
'totalValue'=> $totalValue, 'totalValue' => $totalValue,
'type'=>'Flat' '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;
}
} }
$getSmallItemQty = ceil($getSmallItemQty / 3) * 8;
$getBulkyItemQty = ceil($getBulkyItemQty / 1) * 8;
$getMaskItemQty = ceil($getMaskItemQty / 25) * 8;
$shippingFee = $getSmallItemQty + $getBulkyItemQty + $getMaskItemQty;
// var_dump($shippingFee);
$order_items = array(); $order_items = array();
$updated_items = $m->myCart($cartKey); $updated_items = $m->myCart($cartKey);
$updated_getSubtotal = $m->getSubtotal($cartKey); $updated_getSubtotal = $m->getSubtotal($cartKey);
// $order_subtotal = $updated_getSubtotal[0]->Subtotal; // $order_subtotal = $updated_getSubtotal[0]->Subtotal;
$order_grandtotal = $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){ 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) {
$tax_value = 0; $tax_value = 0;
}else{ } else {
$tax_value = 0.10; $tax_value = 0.10;
} }
$tax = $order_grandtotal * $tax_value; $tax = $order_grandtotal * $tax_value;
foreach($updated_items as $key => $item){ foreach ($updated_items as $key => $item) {
// $descriptions = "Name: " . $item->Name . " Number: " . $item->Number . " Size: " . $item->Size;"?" // $descriptions = "Name: " . $item->Name . " Number: " . $item->Number . " Size: " . $item->Size;"?"
$order_items[$key] = PayPal::Item(); $order_items[$key] = PayPal::Item();
$order_items[$key]->setName($item->ProductName); $order_items[$key]->setName($item->ProductName);
$order_items[$key]->setCurrency($store_array[0]->StoreCurrency); $order_items[$key]->setCurrency($store_array[0]->StoreCurrency);
@@ -131,44 +159,44 @@ class PaypalController extends Controller {
// $order_items[$key]->setDescription($descriptions); // $order_items[$key]->setDescription($descriptions);
// $order_items[$key]->setTax(10); // $order_items[$key]->setTax(10);
$order_items[$key]->setPrice($item->Price); $order_items[$key]->setPrice($item->Price);
} }
$item_list = PayPal::ItemList(); $item_list = PayPal::ItemList();
$item_list->setItems($order_items); $item_list->setItems($order_items);
$amount_details = PayPal::Details(); $amount_details = PayPal::Details();
$amount_details->setSubtotal($order_grandtotal); $amount_details->setSubtotal($order_grandtotal);
$amount_details->setTax($tax); $amount_details->setTax($tax);
$amount_details->setShipping($shippingFee);
$amount = PayPal::Amount(); $amount = PayPal::Amount();
$amount->setCurrency($store_array[0]->StoreCurrency); $amount->setCurrency($store_array[0]->StoreCurrency);
$amount->setDetails($amount_details); $amount->setDetails($amount_details);
$amount->setTotal($order_grandtotal + $tax); $amount->setTotal($order_grandtotal + $tax + $shippingFee);
$transaction = PayPal::Transaction(); $transaction = PayPal::Transaction();
$transaction->setAmount($amount); $transaction->setAmount($amount);
$transaction->setItemList($item_list); $transaction->setItemList($item_list);
// $transaction->setDescription('Your transaction description'); // $transaction->setDescription('Your transaction description');
$transaction->setInvoiceNumber(date('Ymd') . '-' . $invoice_num); $transaction->setInvoiceNumber(date('Ymd') . '-' . $invoice_num);
$redirectUrls = PayPal:: RedirectUrls(); $redirectUrls = PayPal::RedirectUrls();
$redirectUrls->setReturnUrl(route('getDone')); $redirectUrls->setReturnUrl(route('getDone'));
$redirectUrls->setCancelUrl(route('getCancel')); $redirectUrls->setCancelUrl(route('getCancel'));
$payment = PayPal::Payment(); $payment = PayPal::Payment();
$payment->setIntent('sale'); $payment->setIntent('sale');
$payment->setPayer($payer); $payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls); $payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction)); $payment->setTransactions(array($transaction));
$response = $payment->create($this->_apiContext); $response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href; $redirectUrl = $response->links[1]->href;
return redirect()->to( $redirectUrl ); return redirect()->to($redirectUrl);
} }
public function getDoneTest() public function getDoneTest()
@@ -193,38 +221,38 @@ class PaypalController extends Controller {
// echo $ex; // echo $ex;
// } // }
} }
public function getDone(Request $request) public function getDone(Request $request)
{ {
$id = $request->get('paymentId'); $id = $request->get('paymentId');
$token = $request->get('token'); $token = $request->get('token');
$payer_id = $request->get('PayerID'); $payer_id = $request->get('PayerID');
$payment = PayPal::getById($id, $this->_apiContext); $payment = PayPal::getById($id, $this->_apiContext);
$paymentExecution = PayPal::PaymentExecution(); $paymentExecution = PayPal::PaymentExecution();
$paymentExecution->setPayerId($payer_id); $paymentExecution->setPayerId($payer_id);
$executePayment = $payment->execute($paymentExecution, $this->_apiContext); $executePayment = $payment->execute($paymentExecution, $this->_apiContext);
// print_r($executePayment); // print_r($executePayment);
// if ($executePayment->getState() == 'approved') { // 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'); // /** 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'); // // return Redirect::route('paywithpaypal');
// echo 'Payment success'; // echo 'Payment success';
// } // }
$obj = json_decode($executePayment); $obj = json_decode($executePayment);
$line2 = null; $line2 = null;
//details //details
$total = $obj->transactions[0]->amount->total; $total = $obj->transactions[0]->amount->total;
$sub_total = $obj->transactions[0]->amount->details->subtotal; $sub_total = $obj->transactions[0]->amount->details->subtotal;
@@ -236,7 +264,7 @@ class PaypalController extends Controller {
//shipping address details //shipping address details
$recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name; $recipient_name = $obj->transactions[0]->item_list->shipping_address->recipient_name;
$line1 = $obj->transactions[0]->item_list->shipping_address->line1; $line1 = $obj->transactions[0]->item_list->shipping_address->line1;
if(isset($obj->transactions[0]->item_list->shipping_address->line2)){ if (isset($obj->transactions[0]->item_list->shipping_address->line2)) {
$line2 = $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; $city = $obj->transactions[0]->item_list->shipping_address->city;
@@ -250,7 +278,7 @@ class PaypalController extends Controller {
$first_name = $obj->payer->payer_info->first_name; $first_name = $obj->payer->payer_info->first_name;
$last_name = $obj->payer->payer_info->last_name; $last_name = $obj->payer->payer_info->last_name;
$_payer_id = $obj->payer->payer_info->payer_id; $_payer_id = $obj->payer->payer_info->payer_id;
/// end paypal codes /// end paypal codes
$paypal_model = new PayPalModel; $paypal_model = new PayPalModel;
@@ -264,22 +292,22 @@ class PaypalController extends Controller {
$payment_details = array( $payment_details = array(
'UserId' => $userId, 'UserId' => $userId,
'CartKey' => $cartKey, 'CartKey' => $cartKey,
'PaymentId' => $id, 'PaymentId' => $id,
'Token' => $token, 'Token' => $token,
'PayerId' => $payer_id, 'PayerId' => $payer_id,
'InvoiceNumber' => $invoice_number, 'InvoiceNumber' => $invoice_number,
'Currency' => $currency, 'Currency' => $currency,
'Total' => $total, 'Total' => $total,
'SubTotal' => $sub_total, 'SubTotal' => $sub_total,
'Tax' => $tax, 'Tax' => $tax,
'Payer_Email' => $email, 'Payer_Email' => $email,
'Payer_Firstname' => $first_name, 'Payer_Firstname' => $first_name,
'Payer_Lastname' => $last_name, 'Payer_Lastname' => $last_name,
'PaymentMethod' =>$payment_method 'PaymentMethod' => $payment_method
); );
$p_id = $paypal_model->insertToPaypalDetails($payment_details); $p_id = $paypal_model->insertToPaypalDetails($payment_details);
@@ -295,7 +323,7 @@ class PaypalController extends Controller {
); );
// iinsert shipping address // iinsert shipping address
$paypal_model->insertShippingAddress($shipping_address); $paypal_model->insertShippingAddress($shipping_address);
// insert order from cart_tmp to orders table // insert order from cart_tmp to orders table
$l = $paypal_model->insertToOrders($cartKey); // insert to orders table $l = $paypal_model->insertToOrders($cartKey); // insert to orders table
@@ -306,30 +334,30 @@ class PaypalController extends Controller {
$item_thumbs = $newUserModel->selectDisplayItemThumb(); $item_thumbs = $newUserModel->selectDisplayItemThumb();
$array_payment_details = $newUserModel->selectPaymentDetails('CartKey', $cartKey); $array_payment_details = $newUserModel->selectPaymentDetails('CartKey', $cartKey);
$array_storename = $newUserModel->selectTeamStoreName($cartKey); // email subject $array_storename = $newUserModel->selectTeamStoreName($cartKey); // email subject
foreach($array_storename as $storname){ foreach ($array_storename as $storname) {
$sName[] = $storname->StoreName; $sName[] = $storname->StoreName;
$sid[] = $storname->Id; $sid[] = $storname->Id;
} }
$sName = implode (", ", $sName); $sName = implode(", ", $sName);
$user_loginsArray = $newUserModel->selectUserLoginsWhereIn($sid); $user_loginsArray = $newUserModel->selectUserLoginsWhereIn($sid);
foreach($user_loginsArray as $userdata){ foreach ($user_loginsArray as $userdata) {
$other_email[] = $userdata->other_email; $other_email[] = $userdata->other_email;
} }
if($other_email[0] != null){ if ($other_email[0] != null) {
$other_email = implode (", ", $other_email); $other_email = implode(", ", $other_email);
$email_cc = "orders@crewsportswear.com" . "," . $other_email; $email_cc = "orders@crewsportswear.com" . "," . $other_email;
}else{ } else {
$email_cc = "orders@crewsportswear.com"; $email_cc = "orders@crewsportswear.com";
} }
$explode_other_email = explode(",", $email_cc); $explode_other_email = explode(",", $email_cc);
$data = array( $data = array(
@@ -341,8 +369,8 @@ class PaypalController extends Controller {
'email_cc' => $explode_other_email, 'email_cc' => $explode_other_email,
'subject' => $sName . ' ORDERS', 'subject' => $sName . ' ORDERS',
); );
Mail::send('emails.orders', $data, function($message) use ($data) { Mail::send('emails.orders', $data, function ($message) use ($data) {
$message->from('no-reply@crewsportswear.com', 'CREW Sportswear'); $message->from('no-reply@crewsportswear.com', 'CREW Sportswear');
$message->bcc($data['email_cc'], 'Orders From CREW Sportswear'); $message->bcc($data['email_cc'], 'Orders From CREW Sportswear');
$message->to($data['receiver'])->subject($data['subject']); $message->to($data['receiver'])->subject($data['subject']);
@@ -350,12 +378,11 @@ class PaypalController extends Controller {
// end email sending // end email sending
$request->session()->forget('cartkey'); // clear session for cartkey $request->session()->forget('cartkey'); // clear session for cartkey
// redirect to thank you page. // redirect to thank you page.
return view('paypal.get_done') return view('paypal.get_done')
->with('currency', $currency) ->with('currency', $currency)
->with('total', $total); ->with('total', $total);
} }
@@ -363,31 +390,30 @@ class PaypalController extends Controller {
{ {
$m = new TeamStoreModel; $m = new TeamStoreModel;
$cartKey = $request->session()->get('cartkey'); $cartKey = $request->session()->get('cartkey');
$items = $m->myCart($cartKey); $items = $m->myCart($cartKey);
$getSubtotal = $m->getSubtotal($cartKey); $getSubtotal = $m->getSubtotal($cartKey);
foreach($items as $item){ foreach ($items as $item) {
if($item->VoucherId != null){ if ($item->VoucherId != null) {
$voucherIds[] = $item->VoucherId; $voucherIds[] = $item->VoucherId;
$voucher = $m->selectVoucherWhereIn($voucherIds); $voucher = $m->selectVoucherWhereIn($voucherIds);
$item_id = $item->Id; $item_id = $item->Id;
$totalValue = $voucher[0]->VoucherValue; $totalValue = $voucher[0]->VoucherValue;
if($voucher[0]->VoucherType == "Percentage"){ if ($voucher[0]->VoucherType == "Percentage") {
$data = array( $data = array(
'Price' => '00.00' 'Price' => '00.00'
); );
$m->updateVoucherValueInCart($data, $item_id); $m->updateVoucherValueInCart($data, $item_id);
}else{ } else {
$voucherData = array( $voucherData = array(
'totalValue'=> $totalValue, 'totalValue' => $totalValue,
'type'=>'Flat' 'type' => 'Flat'
); );
} }
} }
} }
return redirect()->route('cart'); return redirect()->route('cart');
} }
} }

View File

@@ -4,10 +4,12 @@ use App\Http\Requests;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Auth; // use Auth;
use Illuminate\Support\Facades\Auth;
use App\Models\teamstore\TeamStoreModel; use App\Models\teamstore\TeamStoreModel;
use App\Models\user\UserModel; use App\Models\user\UserModel;
use Mail; // use Mail;
use Illuminate\Support\Facades\Mail;
use Analytics; use Analytics;
@@ -251,7 +253,7 @@ class TeamStoreController extends Controller {
} }
if($item[0]->ProductAvailableQty != null){ if($item[0]->ProductAvailableQty != null){
$soldQty = $m->getSoldQty($product_array[0]->Id); $soldQty = $TeamStoreModel->getSoldQty($item[0]->Id);
$availableQty = $item[0]->ProductAvailableQty - $soldQty[0]->SoldQty; $availableQty = $item[0]->ProductAvailableQty - $soldQty[0]->SoldQty;
}else{ }else{
// echo 'no qty'; // echo 'no qty';
@@ -288,7 +290,8 @@ class TeamStoreController extends Controller {
$ProductURL = $product_array[0]->ProductURL; $ProductURL = $product_array[0]->ProductURL;
$product_form = $product_array[0]->ProductForm; $product_form = $product_array[0]->ProductForm;
$design_code = $product_array[0]->DesignCode; $design_code = $product_array[0]->DesignCode;
$product_name = $product_array[0]->ProductName; $product_name = $product_array[0]->ProductName;
$shipping_cost_id = $product_array[0]->ShippingCostId;
$teamstore_array = $m->selectTeamStore('Id', $TeamStoreId); $teamstore_array = $m->selectTeamStore('Id', $TeamStoreId);
@@ -323,7 +326,8 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key], 'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key], 'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price, 'Price' => $final_price,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
}elseif($product_form == "tshirt-form"){ }elseif($product_form == "tshirt-form"){
@@ -339,7 +343,8 @@ class TeamStoreController extends Controller {
'ProductName' => $product_name, 'ProductName' => $product_name,
'Size' => $post['uniformSize'], 'Size' => $post['uniformSize'],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => $post['quantity'] 'Quantity' => $post['quantity'],
'ShippingCostId' => $shipping_cost_id
); );
}elseif($product_form == "quantity-form"){ }elseif($product_form == "quantity-form"){
@@ -353,7 +358,8 @@ class TeamStoreController extends Controller {
'ProductURL' => $ProductURL, 'ProductURL' => $ProductURL,
'ProductName' => $product_name, 'ProductName' => $product_name,
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => $post['quantity'] 'Quantity' => $post['quantity'],
'ShippingCostId' => $shipping_cost_id
); );
@@ -375,7 +381,8 @@ class TeamStoreController extends Controller {
'Name' => $order_names[$key], 'Name' => $order_names[$key],
'Number' => $order_number[$key], 'Number' => $order_number[$key],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
}elseif($product_form == "name-number-size-form"){ }elseif($product_form == "name-number-size-form"){
@@ -398,7 +405,8 @@ class TeamStoreController extends Controller {
'Size' => $order_size[$key], 'Size' => $order_size[$key],
'Number' => $order_number[$key], 'Number' => $order_number[$key],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
@@ -418,7 +426,8 @@ class TeamStoreController extends Controller {
'ProductName' => $product_name, 'ProductName' => $product_name,
'Number' => $order_number[$key], 'Number' => $order_number[$key],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
}elseif($product_form == "name-name2-size-form"){ }elseif($product_form == "name-name2-size-form"){
@@ -441,7 +450,8 @@ class TeamStoreController extends Controller {
'Name2' => $order_names2[$key], 'Name2' => $order_names2[$key],
'Size' => $order_size[$key], 'Size' => $order_size[$key],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
}elseif($product_form == "name-size-form"){ }elseif($product_form == "name-size-form"){
@@ -462,7 +472,8 @@ class TeamStoreController extends Controller {
'Name' => $order_names[$key], 'Name' => $order_names[$key],
'Size' => $order_size[$key], 'Size' => $order_size[$key],
'Price' => $ProductPrice, 'Price' => $ProductPrice,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
}elseif($product_form == "jersey-and-shorts-quantity-form"){ }elseif($product_form == "jersey-and-shorts-quantity-form"){
@@ -492,7 +503,8 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key], 'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key], 'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price, 'Price' => $final_price,
'Quantity' => $quantity[$key] 'Quantity' => $quantity[$key],
'ShippingCostId' => $shipping_cost_id
); );
} }
@@ -524,11 +536,12 @@ class TeamStoreController extends Controller {
'JerseySize' => $order_jersey_size[$key], 'JerseySize' => $order_jersey_size[$key],
'ShortsSize' => $order_shorts_size[$key], 'ShortsSize' => $order_shorts_size[$key],
'Price' => $final_price, 'Price' => $final_price,
'Quantity' => 1 'Quantity' => 1,
'ShippingCostId' => $shipping_cost_id
); );
} }
} }
$i = $m->insertToCart($items); $i = $m->insertToCart($items);
if($i['i']){ if($i['i']){

View File

@@ -4,44 +4,18 @@ use App\Http\Requests;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Auth; use Illuminate\Support\Facades\Auth;
use App\Models\user\UserModel; use App\Models\user\UserModel;
use App\Models\teamstore\TeamStoreModel; use App\Models\teamstore\TeamStoreModel;
use App\Models\MainModel; use App\Models\MainModel;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Paypal; use Illuminate\Support\Facades\Mail;
use View; use Illuminate\Support\Facades\Validator;
use Mail;
use Validator;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class UserController extends Controller { class UserController extends Controller {
// private $_apiContext;
// public function __construct()
// {
// $this->_apiContext = PayPal::ApiContext(
// config('services.paypal.client_id'),
// config('services.paypal.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'
// ));
// // view()->share('datas', [1, 2, 3]);
// }
//
public function index(){ public function index(){
return view('user-layouts.index'); return view('user-layouts.index');
@@ -333,10 +307,12 @@ class UserController extends Controller {
$product_array = $newTeamStoreModel->selectTeamStoreProducts('ProductURL', $url); $product_array = $newTeamStoreModel->selectTeamStoreProducts('ProductURL', $url);
$thumbnails_array = $newTeamStoreModel->getThumbnails($product_array[0]->Id); $thumbnails_array = $newTeamStoreModel->getThumbnails($product_array[0]->Id);
$available_size = explode(",", $product_array[0]->AvailableSizes); $available_size = explode(",", $product_array[0]->AvailableSizes);
// var_dump($product_array); $shipping_cost = $newUserModel->selectShippingCost();
return view('user-layouts.view-store-item')->with('product_array', $product_array) return view('user-layouts.view-store-item')->with('product_array', $product_array)
->with('available_size', $available_size) ->with('available_size', $available_size)
->with('thumbnails_array', $thumbnails_array); ->with('thumbnails_array', $thumbnails_array)
->with('shipping_cost', $shipping_cost);
} }
@@ -346,6 +322,12 @@ class UserController extends Controller {
$post = $request->all(); $post = $request->all();
$newTeamStoreModel = new TeamStoreModel; $newTeamStoreModel = new TeamStoreModel;
if($post['shipping_cost'] == 0){
$shipping_cost_id = null;
}else{
$shipping_cost_id = $post['shipping_cost'];
}
$item_url = $post['item_url']; $item_url = $post['item_url'];
$data = array( $data = array(
'ProductName' => $post['itemName'], 'ProductName' => $post['itemName'],
@@ -353,7 +335,9 @@ class UserController extends Controller {
'ProductDescription' => $post['itemDescription'], 'ProductDescription' => $post['itemDescription'],
'PrivacyStatus' => $post['item_privacy'], 'PrivacyStatus' => $post['item_privacy'],
'ProductForm' => $post['itemForm'], 'ProductForm' => $post['itemForm'],
'AvailableSizes' => implode(",", $post['available_size']) 'AvailableSizes' => implode(",", $post['available_size']),
'ShippingCostId' => $shipping_cost_id
); );
$i = $newTeamStoreModel->updateStoreItem($data, $item_url); $i = $newTeamStoreModel->updateStoreItem($data, $item_url);

View File

@@ -1,5 +1,7 @@
<?php <?php
use Illuminate\Support\Facades\Route;
// use Spatie\LaravelAnalytics\LaravelAnalytics;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Application Routes | Application Routes
@@ -175,6 +177,6 @@ Route::group(['middleware' => 'admin'], function () {
Route::get('cliparts/index', 'cliparts\ClipartsController@index'); Route::get('cliparts/index', 'cliparts\ClipartsController@index');
Route::get('analytics', function (){ // Route::get('analytics', function (){
$analyticsData = LaravelAnalytics::getVisitorsAndPageViews(7); // $analyticsData = LaravelAnalytics::getVisitorsAndPageViews(7);
}); // });

View File

@@ -1,7 +1,7 @@
<?php namespace App\Models; <?php namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DB; use Illuminate\Support\Facades\DB;
class SizesModel extends Model { class SizesModel extends Model {

View File

@@ -1,7 +1,7 @@
<?php namespace App\Models\paypal; <?php namespace App\Models\paypal;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DB; use Illuminate\Support\Facades\DB;
class PayPalModel extends Model { class PayPalModel extends Model {
@@ -37,7 +37,5 @@ class PayPalModel extends Model {
->get(); ->get();
// var_dump($i); // var_dump($i);
return $i; return $i;
} }
} }

View File

@@ -1,7 +1,7 @@
<?php namespace App\Models\teamstore; <?php namespace App\Models\teamstore;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DB; use Illuminate\Support\Facades\DB;
class TeamStoreModel extends Model { class TeamStoreModel extends Model {

View File

@@ -1,7 +1,7 @@
<?php namespace App\Models\user; <?php namespace App\Models\user;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use DB; use Illuminate\Support\Facades\DB;
class UserModel extends Model { class UserModel extends Model {
@@ -310,5 +310,11 @@ class UserModel extends Model {
return $i; return $i;
} }
function selectShippingCost(){
$i = DB::table('shipping_cost')
->get();
return $i;
}
} }

View File

@@ -35,10 +35,10 @@ return [
], ],
// sandbox // sandbox
/* 'paypal' => [ // 'paypal' => [
'client_id' => 'AQuz-HKzQiL7FygkG8skSekaWf-RP6Rgj4f1XeX1Ghp86bUFj7tQXVT1xbpluu5_WCGRbQpOVGtlJKVB', // 'client_id' => 'AQuz-HKzQiL7FygkG8skSekaWf-RP6Rgj4f1XeX1Ghp86bUFj7tQXVT1xbpluu5_WCGRbQpOVGtlJKVB',
'secret' => 'EJAMKxQsl-mFkL_4J_90cvTamYfcsgswqgIxz9wQPiRAwJ6sy_wNsttMlmrXIpxI96JpYzdMXkLCHAPz' // 'secret' => 'EJAMKxQsl-mFkL_4J_90cvTamYfcsgswqgIxz9wQPiRAwJ6sy_wNsttMlmrXIpxI96JpYzdMXkLCHAPz'
], */ // ],
// live // live
'paypal' => [ 'paypal' => [

View File

@@ -1842,7 +1842,7 @@
function submitFormItemDetails(){ function submitFormItemDetails(){
var data = $("#frm-item-details").serialize(); var data = $("#frm-item-details").serialize();
console.log(data)
$.ajax({ $.ajax({
type : 'POST', type : 'POST',
url : "{{ url('user/store-items/update') }}", url : "{{ url('user/store-items/update') }}",

View File

@@ -20,7 +20,6 @@
<li class="active">{{ $product_array[0]->ProductName }}</li> <li class="active">{{ $product_array[0]->ProductName }}</li>
</ol> </ol>
</section> </section>
<!-- Main content --> <!-- Main content -->
<section class="content"> <section class="content">
<div class="row"> <div class="row">
@@ -146,9 +145,20 @@
<label>Item Privacy</label> <label>Item Privacy</label>
<select class="form-control" name="item_privacy"> <select class="form-control" name="item_privacy">
<option value="public" @if($product_array[0]->PrivacyStatus == "public") selected @endif>Public</option> <option value="public" @if($product_array[0]->PrivacyStatus == "public") selected @endif>Public</option>
<option value="private" @if($product_array[0]->PrivacyStatus == "private") selected @endif">Private</option> <option value="private" @if($product_array[0]->PrivacyStatus == "private") selected @endif>Private</option>
</select> </select>
</div> </div>
<div class="form-group">
<label>Select Shipping Category</label>
<select class="form-control" name="shipping_cost" required>
<option value="0">None</option>
@foreach ($shipping_cost as $sc)
<option value="{{ $sc->Id }}" @if($sc->Id == $product_array[0]->ShippingCostId) selected @endif>{{ $sc->DisplayName }}</option>
@endforeach
</select>
<span id="err_available_size"></span>
</div>
</div> </div>
</div> </div>
</div> </div>