* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ class OnepageController 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() ]); } }