2018-09-13 11:10:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-28 12:54:26 +00:00
|
|
|
namespace Webkul\Shop\Http\Controllers;
|
2018-09-25 05:22:22 +00:00
|
|
|
|
2018-09-13 11:10:45 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Auth;
|
2018-09-25 05:22:22 +00:00
|
|
|
use Webkul\Cart\Facades\Cart;
|
2018-09-20 10:01:51 +00:00
|
|
|
use Webkul\Shipping\Facades\Shipping;
|
2018-09-21 10:17:01 +00:00
|
|
|
use Webkul\Payment\Facades\Payment;
|
2018-09-25 05:22:22 +00:00
|
|
|
use Webkul\Cart\Http\Requests\CustomerAddressForm;
|
2018-09-13 11:10:45 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-09-28 12:54:26 +00:00
|
|
|
* Chekout controller for the customer and guest for placing order
|
2018-09-13 11:10:45 +00:00
|
|
|
*
|
2018-09-19 06:58:15 +00:00
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
2018-09-13 11:10:45 +00:00
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
2018-09-28 12:54:26 +00:00
|
|
|
class OnepageController extends Controller
|
2018-09-13 11:10:45 +00:00
|
|
|
{
|
|
|
|
|
/**
|
2018-09-19 06:58:15 +00:00
|
|
|
* Contains route related configuration
|
2018-09-13 11:10:45 +00:00
|
|
|
*
|
2018-09-19 06:58:15 +00:00
|
|
|
* @var array
|
2018-09-13 11:10:45 +00:00
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
2018-09-19 06:58:15 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-09-13 11:10:45 +00:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2018-09-26 04:21:14 +00:00
|
|
|
if(!$cart = Cart::getCart())
|
|
|
|
|
return redirect()->route('shop.checkout.cart.index');
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'])->with('cart', $cart);
|
2018-09-13 11:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-20 10:01:51 +00:00
|
|
|
/**
|
|
|
|
|
* Saves customer address.
|
|
|
|
|
*
|
2018-09-25 05:22:22 +00:00
|
|
|
* @param \Webkul\Cart\Http\Requests\CustomerAddressForm $request
|
2018-09-20 10:01:51 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-09-25 05:22:22 +00:00
|
|
|
public function saveAddress(CustomerAddressForm $request)
|
2018-09-20 10:01:51 +00:00
|
|
|
{
|
2018-09-26 04:21:14 +00:00
|
|
|
if(!Cart::saveCustomerAddress(request()->all()) || !$rates = Shipping::collectRates())
|
|
|
|
|
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
2018-09-20 10:01:51 +00:00
|
|
|
|
2018-09-26 04:21:14 +00:00
|
|
|
return response()->json($rates);
|
2018-09-20 10:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Saves shipping method.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function saveShipping()
|
|
|
|
|
{
|
2018-09-26 10:19:18 +00:00
|
|
|
$shippingMethod = request()->get('shipping_method');
|
|
|
|
|
|
|
|
|
|
if(!$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
|
|
|
|
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
|
|
|
|
|
|
|
|
|
Cart::collectTotals();
|
|
|
|
|
|
2018-09-21 10:17:01 +00:00
|
|
|
return response()->json(Payment::getSupportedPaymentMethods());
|
2018-09-20 10:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Saves payment method.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-09-25 05:22:22 +00:00
|
|
|
public function savePayment()
|
2018-09-20 10:01:51 +00:00
|
|
|
{
|
2018-09-26 10:19:18 +00:00
|
|
|
$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()
|
|
|
|
|
]);
|
2018-09-20 10:01:51 +00:00
|
|
|
}
|
2018-09-13 11:10:45 +00:00
|
|
|
}
|