final checkout und card
This commit is contained in:
parent
dc857e88d5
commit
4bd21bd986
2 changed files with 188 additions and 0 deletions
154
app/Http/Controllers/Web/CheckoutController.php
Executable file
154
app/Http/Controllers/Web/CheckoutController.php
Executable file
|
|
@ -0,0 +1,154 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Web;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Product;
|
||||||
|
use Validator;
|
||||||
|
use App\Services\Util;
|
||||||
|
use Yard;
|
||||||
|
use Input;
|
||||||
|
|
||||||
|
class CardController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Cart::instance('wishlist')->add('sdjk922', 'Product 2', 1, 19.95, ['size' => 'medium']);
|
||||||
|
public function addToCardGet($id, $quantity = 1, $product_slug = false)
|
||||||
|
{
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||||
|
// $selected_country = $ShippingCountry->id;
|
||||||
|
}
|
||||||
|
$data = [
|
||||||
|
'user_shop' => Util::getUserShop(),
|
||||||
|
];
|
||||||
|
return view('web.templates.checkout', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkoutFinalCard(){
|
||||||
|
|
||||||
|
$rules = array(
|
||||||
|
'billing.firstname'=>'required',
|
||||||
|
'billing.lastname'=>'required',
|
||||||
|
'billing.email'=>'required|email',
|
||||||
|
'billing.address'=>'required',
|
||||||
|
'billing.zipcode'=>'required',
|
||||||
|
'billing.city' => 'required',
|
||||||
|
'accepted_data_checkbox' => 'accepted',
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!Input::get('shipping.same_as_billing')){
|
||||||
|
$rules = array_merge($rules, [
|
||||||
|
'shipping.firstname'=>'required',
|
||||||
|
'shipping.lastname'=>'required',
|
||||||
|
'shipping.address'=>'required',
|
||||||
|
'shipping.zipcode'=>'required',
|
||||||
|
'shipping.city' => 'required',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$validator = Validator::make(Input::all(), $rules);
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all());
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'user_shop' => Util::getUserShop(),
|
||||||
|
];
|
||||||
|
return view('web.templates.checkout-final', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function removeCard($rowId){
|
||||||
|
|
||||||
|
Yard::instance('shopping')->remove($rowId);
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteCard(){
|
||||||
|
|
||||||
|
Yard::instance('shopping')->destroy();
|
||||||
|
return back();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
34
app/Http/Middleware/Checkout.php
Executable file
34
app/Http/Middleware/Checkout.php
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Models\UserShop;
|
||||||
|
use Closure;
|
||||||
|
use Auth;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
|
||||||
|
use Util;
|
||||||
|
|
||||||
|
class Subdomain
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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){
|
||||||
|
\Session::put('user_shop', $user_shop);
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redirect(config('app.url'));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue