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,21 +1,27 @@
<?php namespace App\Http\Controllers\paypal;
<?php
use App\Http\Requests;
namespace App\Http\Controllers\paypal;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Paypal;
// use Paypal;
use Netshell\Paypal\Facades\Paypal;
use App\Models\teamstore\TeamStoreModel;
use App\Models\user\UserModel;
use App\Models\paypal\PayPalModel;
use Auth;
use Session;
use Redirect;
use Mail;
// use Auth;
use Illuminate\Support\Facades\Auth;
// use Session;
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;
@@ -24,17 +30,18 @@ class PaypalController extends Controller {
{
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
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'
)); */
// $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(
@@ -81,6 +88,11 @@ class PaypalController extends Controller {
$grouped_item = $m->selectTeamStoreGroupByCartKey($cartKey);
$store_array = $m->selectTeamStore('Id', $grouped_item[0]->StoreId);
$getSmallItemQty = 0;
$getBulkyItemQty = 0;
$getMaskItemQty = 0;
$shippingFee = 0;
foreach ($items as $item) {
if ($item->VoucherId != null) {
@@ -103,7 +115,23 @@ class PaypalController extends Controller {
);
}
}
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();
$updated_items = $m->myCart($cartKey);
@@ -131,7 +159,6 @@ class PaypalController extends Controller {
// $order_items[$key]->setDescription($descriptions);
// $order_items[$key]->setTax(10);
$order_items[$key]->setPrice($item->Price);
}
$item_list = PayPal::ItemList();
@@ -139,11 +166,12 @@ class PaypalController extends Controller {
$amount_details = PayPal::Details();
$amount_details->setSubtotal($order_grandtotal);
$amount_details->setTax($tax);
$amount_details->setShipping($shippingFee);
$amount = PayPal::Amount();
$amount->setCurrency($store_array[0]->StoreCurrency);
$amount->setDetails($amount_details);
$amount->setTotal($order_grandtotal + $tax);
$amount->setTotal($order_grandtotal + $tax + $shippingFee);
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
@@ -355,7 +383,6 @@ class PaypalController extends Controller {
return view('paypal.get_done')
->with('currency', $currency)
->with('total', $total);
}
@@ -389,5 +416,4 @@ class PaypalController extends Controller {
return redirect()->route('cart');
}
}

View File

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

View File

@@ -4,44 +4,18 @@ use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use Illuminate\Support\Facades\Auth;
use App\Models\user\UserModel;
use App\Models\teamstore\TeamStoreModel;
use App\Models\MainModel;
use Illuminate\Support\Facades\Hash;
use Paypal;
use View;
use Mail;
use Validator;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;
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(){
return view('user-layouts.index');
@@ -333,10 +307,12 @@ class UserController extends Controller {
$product_array = $newTeamStoreModel->selectTeamStoreProducts('ProductURL', $url);
$thumbnails_array = $newTeamStoreModel->getThumbnails($product_array[0]->Id);
$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)
->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();
$newTeamStoreModel = new TeamStoreModel;
if($post['shipping_cost'] == 0){
$shipping_cost_id = null;
}else{
$shipping_cost_id = $post['shipping_cost'];
}
$item_url = $post['item_url'];
$data = array(
'ProductName' => $post['itemName'],
@@ -353,7 +335,9 @@ class UserController extends Controller {
'ProductDescription' => $post['itemDescription'],
'PrivacyStatus' => $post['item_privacy'],
'ProductForm' => $post['itemForm'],
'AvailableSizes' => implode(",", $post['available_size'])
'AvailableSizes' => implode(",", $post['available_size']),
'ShippingCostId' => $shipping_cost_id
);
$i = $newTeamStoreModel->updateStoreItem($data, $item_url);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -20,7 +20,6 @@
<li class="active">{{ $product_array[0]->ProductName }}</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
@@ -146,9 +145,20 @@
<label>Item Privacy</label>
<select class="form-control" name="item_privacy">
<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>
</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>