102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Webkul\Cart\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Auth;
|
|
use Webkul\Cart\Facades\Cart;
|
|
use Webkul\Shipping\Facades\Shipping;
|
|
use Webkul\Payment\Facades\Payment;
|
|
use Webkul\Cart\Http\Requests\CustomerAddressForm;
|
|
|
|
/**
|
|
* Chekout controller for the customer
|
|
* and guest for placing order
|
|
*
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
*/
|
|
class CheckoutController extends Controller
|
|
{
|
|
/**
|
|
* Contains route related configuration
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $_config;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->_config = request('_config');
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
if(!$cart = Cart::getCart())
|
|
return redirect()->route('shop.checkout.cart.index');
|
|
|
|
return view($this->_config['view'])->with('cart', $cart);
|
|
}
|
|
|
|
/**
|
|
* Saves customer address.
|
|
*
|
|
* @param \Webkul\Cart\Http\Requests\CustomerAddressForm $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function saveAddress(CustomerAddressForm $request)
|
|
{
|
|
if(!Cart::saveCustomerAddress(request()->all()) || !$rates = Shipping::collectRates())
|
|
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
|
|
|
return response()->json($rates);
|
|
}
|
|
|
|
/**
|
|
* Saves shipping method.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function saveShipping()
|
|
{
|
|
$shippingMethod = request()->get('shipping_method');
|
|
|
|
if(!$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
|
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
|
|
|
Cart::collectTotals();
|
|
|
|
return response()->json(Payment::getSupportedPaymentMethods());
|
|
}
|
|
|
|
/**
|
|
* Saves payment method.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function savePayment()
|
|
{
|
|
$payment = request()->get('payment');
|
|
|
|
if(!$payment || !Cart::savePaymentMethod($payment))
|
|
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
|
|
|
$cart = Cart::getCart();
|
|
|
|
return response()->json([
|
|
'jump_to_section' => 'review',
|
|
'html' => view('shop::checkout.onepage.review', compact('cart'))->render()
|
|
]);
|
|
}
|
|
} |