final checkout and card
This commit is contained in:
parent
4bd21bd986
commit
1953c97cd0
33 changed files with 2131 additions and 1084 deletions
|
|
@ -5,8 +5,9 @@ namespace App\Http\Controllers\Web;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use Util;
|
||||
use App\Models\ShoppingInstance;
|
||||
use Validator;
|
||||
use App\Services\Util;
|
||||
use Yard;
|
||||
use Input;
|
||||
|
||||
|
|
@ -33,8 +34,10 @@ class CardController extends Controller
|
|||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug]);
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug, 'weight' => $product->weight]);
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
|
|
@ -50,7 +53,8 @@ class CardController extends Controller
|
|||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$quantity = Input::get('quantity') ? Input::get('quantity') : 1;
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug]);
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
return back();
|
||||
|
||||
|
|
@ -60,12 +64,11 @@ class CardController extends Controller
|
|||
public function showCard(){
|
||||
|
||||
if(Input::get('selected_country')){
|
||||
$selected_country = Input::get('selected_country');
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
|
||||
}else{
|
||||
$ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||
$selected_country = $ShippingCountry->id;
|
||||
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||
// $selected_country = $ShippingCountry->id;
|
||||
}
|
||||
Yard::instance('shopping')->setShippingCountry($selected_country);
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
|
|
@ -86,29 +89,31 @@ class CardController extends Controller
|
|||
return back();
|
||||
}
|
||||
|
||||
public function checkoutCard(){#
|
||||
if(Input::get('selected_country')){
|
||||
$selected_country = Input::get('selected_country');
|
||||
}else{
|
||||
$ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||
$selected_country = $ShippingCountry->id;
|
||||
}
|
||||
Yard::instance('shopping')->setShippingCountry($selected_country);
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.checkout', $data);
|
||||
public function checkoutServer(){
|
||||
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
public function checkoutFinalCard(){
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.checkout-final', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function removeCard($rowId){
|
||||
|
||||
Yard::instance('shopping')->remove($rowId);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use App\Services\Util;
|
|||
use Yard;
|
||||
use Input;
|
||||
|
||||
class CardController extends Controller
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
|
@ -23,72 +23,12 @@ class CardController extends Controller
|
|||
|
||||
|
||||
|
||||
//Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
||||
public function addToCardGet($id, $quantity = 1, $product_slug = false)
|
||||
{
|
||||
public function checkout(){
|
||||
|
||||
$product = Product::find($id);
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug, 'weight' => $product->weight]);
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
public function addToCardPost($id)
|
||||
{
|
||||
|
||||
$product = Product::find($id);
|
||||
|
||||
if($product){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$quantity = Input::get('quantity') ? Input::get('quantity') : 1;
|
||||
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
|
||||
\Session()->flash('show-card-after-add', true);
|
||||
}
|
||||
return back();
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function showCard(){
|
||||
|
||||
if(Input::get('selected_country')){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
|
||||
}else{
|
||||
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||
// $selected_country = $ShippingCountry->id;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.card', $data);
|
||||
}
|
||||
|
||||
public function updateCard(){
|
||||
|
||||
$data = Input::all();
|
||||
if(isset($data['quantity'])){
|
||||
foreach ($data['quantity'] as $rowId => $qty){
|
||||
Yard::instance('shopping')->update($rowId, $qty);
|
||||
}
|
||||
}else{
|
||||
$this->deleteCard();
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
public function checkoutCard(){#
|
||||
if(Input::get('selected_country')){
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
|
||||
}else{
|
||||
|
|
@ -101,7 +41,7 @@ class CardController extends Controller
|
|||
return view('web.templates.checkout', $data);
|
||||
}
|
||||
|
||||
public function checkoutFinalCard(){
|
||||
public function checkoutFinal(){
|
||||
|
||||
$rules = array(
|
||||
'billing.firstname'=>'required',
|
||||
|
|
@ -136,7 +76,6 @@ class CardController extends Controller
|
|||
|
||||
|
||||
public function removeCard($rowId){
|
||||
|
||||
Yard::instance('shopping')->remove($rowId);
|
||||
return back();
|
||||
}
|
||||
|
|
@ -147,8 +86,4 @@ class CardController extends Controller
|
|||
return back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ use App\Mail\MailContact;
|
|||
use GuzzleHttp\Client;
|
||||
use Input;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Util;
|
||||
use App\Services\Util;
|
||||
use Validator;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Input;
|
||||
use Util;
|
||||
use App\Services\Util;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class Kernel extends HttpKernel
|
|||
'admin' => \App\Http\Middleware\Admin::class,
|
||||
'superadmin' => \App\Http\Middleware\SuperAdmin::class,
|
||||
'subdomain' => \App\Http\Middleware\Subdomain::class,
|
||||
'checkout' => \App\Http\Middleware\Checkout::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@
|
|||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\UserShop;
|
||||
use Closure;
|
||||
use Auth;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
|
||||
use Util;
|
||||
use App\Services\Util;
|
||||
use Yard;
|
||||
|
||||
class Subdomain
|
||||
class Checkout
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
|
|
@ -19,15 +21,29 @@ class Subdomain
|
|||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if(!empty($request->route('subdomain'))){
|
||||
$user_shop = UserShop::where('slug', $request->route('subdomain'))->where('active', 1)->first();
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
Util::setPostRoute('user.');
|
||||
if($user_shop){
|
||||
|
||||
if($identifier = ShoppingInstance::where('identifier', $request->route('identifier'))->first()){
|
||||
//user shop
|
||||
$user_shop = $identifier->user_shop;
|
||||
if($user_shop && $user_shop->active == 1){
|
||||
Util::setPostRoute('user.');
|
||||
\Session::put('user_shop', $user_shop);
|
||||
return $next($request);
|
||||
\Session::put('isCheckout', true);
|
||||
}
|
||||
//restore yard
|
||||
Yard::instance('shopping')->restore($request->route('identifier'));
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($identifier->country_id);
|
||||
|
||||
ShoppingInstance::where('identifier', $request->route('identifier'))->delete();
|
||||
$request->route()->forgetParameter('identifier');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if(\Session::has('user_shop') && \Session::has('isCheckout') && Yard::instance('shopping')->count()){
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return redirect(config('app.url'));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Util;
|
||||
use Closure;
|
||||
use Auth;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
|
||||
use Util;
|
||||
|
||||
class Subdomain
|
||||
{
|
||||
|
|
@ -19,7 +19,6 @@ class Subdomain
|
|||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(!empty($request->route('subdomain'))){
|
||||
$user_shop = UserShop::where('slug', $request->route('subdomain'))->where('active', 1)->first();
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use Illuminate\Bus\Queueable;
|
|||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Util;
|
||||
use App\Services\Util;
|
||||
|
||||
class MailContact extends Mailable
|
||||
{
|
||||
|
|
|
|||
26
app/Models/ShoppingInstance.php
Normal file
26
app/Models/ShoppingInstance.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ShoppingInstance extends Model
|
||||
{
|
||||
protected $table = 'shopping_instances';
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'identifier', 'user_shop_id', 'subdomain', 'country_id'
|
||||
];
|
||||
|
||||
public function user_shop()
|
||||
{
|
||||
return $this->belongsTo('App\Models\UserShop', 'user_shop_id');
|
||||
}
|
||||
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Country', 'country_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,8 +6,15 @@ namespace App\Services;
|
|||
class Util
|
||||
{
|
||||
|
||||
|
||||
|
||||
private static $postRoute = 'base.';
|
||||
|
||||
public static function getToken()
|
||||
{
|
||||
return hash_hmac('sha256', str_random(40), config('app.key'));
|
||||
}
|
||||
|
||||
public static function formatDate(){
|
||||
if(\App::getLocale() == "en"){
|
||||
return 'yyyy-mm-dd';
|
||||
|
|
@ -47,6 +54,7 @@ class Util
|
|||
|
||||
public static function addRoute($p = []){
|
||||
$b = [];
|
||||
|
||||
if(\Session::has('user_shop')){
|
||||
if($user_shop = \Session::get('user_shop')){
|
||||
$b = ['subdomain' => $user_shop->slug];
|
||||
|
|
@ -55,4 +63,24 @@ class Util
|
|||
return array_merge($p, $b);
|
||||
}
|
||||
|
||||
public static function isCheckout(){
|
||||
|
||||
if(\Session::has('isCheckout')){
|
||||
if(\Session::get('isCheckout') == true){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getUserShopBackUrl($uri){
|
||||
|
||||
if(\Session::has('user_shop')){
|
||||
if($user_shop = \Session::get('user_shop')){
|
||||
return 'http://'.$user_shop->slug.".".Config('app.domain').$uri;
|
||||
}
|
||||
}
|
||||
return url($uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,52 +6,95 @@ use \Gloudemans\Shoppingcart\Cart;
|
|||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
class Yard extends Cart
|
||||
{
|
||||
|
||||
private $shipping = 0;
|
||||
private $shipping_country_id = 0;
|
||||
private $shipping_country_id = 7; //default de
|
||||
private $ysession;
|
||||
private $yinstance;
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
{
|
||||
$this->ysession = $session;
|
||||
$this->yinstance = sprintf('%s.%s', 'cart', 'shipping_extras');
|
||||
if($this->getShippingExtra('shipping_price')){
|
||||
$this->shipping = floatval($this->getShippingExtra('shipping_price'));
|
||||
}
|
||||
if($this->getShippingExtra('shipping_country_id')){
|
||||
$this->shipping_country_id = $this->getShippingExtra('shipping_country_id');
|
||||
}
|
||||
|
||||
parent::__construct($session, $events);
|
||||
}
|
||||
|
||||
|
||||
public static function getTaxRate()
|
||||
{
|
||||
return config('cart.tax');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $shipping
|
||||
*/
|
||||
public function setShipping($shipping)
|
||||
{
|
||||
$this->shipping = floatval($shipping); ;
|
||||
public function putShippingExtra($key, $value){
|
||||
|
||||
$content = $this->getYContent();
|
||||
$content->put($key, $value);
|
||||
$this->ysession->put($this->yinstance, $content);
|
||||
|
||||
}
|
||||
|
||||
public function setShippingCountry($shipping_country_id)
|
||||
public function getShippingExtra($key){
|
||||
$content = $this->getYContent();
|
||||
if ($content->has($key)){
|
||||
return $content->get($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getShippingCountryName(){
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if($shippingCountry && $shippingCountry->country){
|
||||
return $shippingCountry->country->getLocated();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public function getShippingCountryId()
|
||||
{
|
||||
$this->shipping_country_id = $shipping_country_id ;
|
||||
if($this->shipping_country_id > 0){
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
return $this->shipping_country_id;
|
||||
}
|
||||
|
||||
|
||||
public function getYContent()
|
||||
{
|
||||
if (is_null($this->ysession->get($this->yinstance))) {
|
||||
return new Collection([]);
|
||||
}
|
||||
return $this->ysession->get($this->yinstance);
|
||||
}
|
||||
|
||||
public function setShippingCountryWithPrice($shipping_country_id)
|
||||
{
|
||||
$this->shipping_country_id = $shipping_country_id;
|
||||
$this->putShippingExtra('shipping_country_id', $shipping_country_id);
|
||||
|
||||
if($shipping_country_id > 0){
|
||||
$shippingCountry = ShippingCountry::find($shipping_country_id);
|
||||
$shipping = $shippingCountry->shipping;
|
||||
if($this->weight()){
|
||||
//blance by weigt
|
||||
}
|
||||
$price = $shipping->prices->first();
|
||||
if($price){
|
||||
$this->setShipping($price->price);
|
||||
$this->shipping = floatval($price->price);
|
||||
$this->putShippingExtra('shipping_price', $this->shipping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getShippingCountry()
|
||||
{
|
||||
return $this->shipping_country_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $decimals
|
||||
|
|
@ -101,7 +144,23 @@ class Yard extends Cart
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Get the total price of the items in the cart.
|
||||
*
|
||||
* @param int $decimals
|
||||
* @param string $decimalPoint
|
||||
* @param string $thousandSeperator
|
||||
* @return string
|
||||
*/
|
||||
public function weight($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$content = $this->getContent();
|
||||
$total = $content->reduce(function ($total, CartItem $cartItem) {
|
||||
return $total + ($cartItem->options->weight ? intval($cartItem->options->weight) : 0);
|
||||
}, 0);
|
||||
|
||||
return $total;
|
||||
}
|
||||
/**
|
||||
* Get the total price of the items in the cart.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue