Merge with master on stage checkout
This commit is contained in:
commit
aeaf81f08b
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Controllers;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
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\Facades\Cart;
|
||||
use Webkul\Cart\Http\Requests\CustomerAddressForm;
|
||||
|
||||
/**
|
||||
* Chekout controller for the customer
|
||||
|
|
@ -48,10 +49,14 @@ class CheckoutController extends Controller
|
|||
/**
|
||||
* Saves customer address.
|
||||
*
|
||||
* @param \Webkul\Cart\Http\Requests\CustomerAddressForm $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveAddress()
|
||||
public function saveAddress(CustomerAddressForm $request)
|
||||
{
|
||||
if(!Cart::saveCustomerAddress(request()->all())) {
|
||||
// return response()->json(['redirect_url' => route('store.home')], 403)
|
||||
}
|
||||
|
||||
return response()->json(Shipping::collectRates());
|
||||
}
|
||||
|
|
@ -71,7 +76,7 @@ class CheckoutController extends Controller
|
|||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveAPayment()
|
||||
public function savePayment()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Cart\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerAddressForm extends FormRequest
|
||||
{
|
||||
protected $rules;
|
||||
|
||||
/**
|
||||
* Determine if the product is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$this->rules = [
|
||||
'billing.first_name' => ['required'],
|
||||
'billing.last_name' => ['required'],
|
||||
'billing.email' => ['required'],
|
||||
'billing.address1' => ['required'],
|
||||
'billing.city' => ['required'],
|
||||
'billing.state' => ['required'],
|
||||
'billing.postcode' => ['required'],
|
||||
'billing.phone' => ['required'],
|
||||
'billing.country' => ['required']
|
||||
];
|
||||
|
||||
if(!$this->get('billing')['use_for_shipping']) {
|
||||
$this->rules = array_merge($this->rules, [
|
||||
'shipping.first_name' => ['required'],
|
||||
'shipping.last_name' => ['required'],
|
||||
'shipping.email' => ['required'],
|
||||
'shipping.address1' => ['required'],
|
||||
'shipping.city' => ['required'],
|
||||
'shipping.state' => ['required'],
|
||||
'shipping.postcode' => ['required'],
|
||||
'shipping.phone' => ['required'],
|
||||
'shipping.country' => ['required']
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
}
|
||||
}
|
||||
|
|
@ -235,4 +235,14 @@ class ConfigurableOption extends AbstractProduct
|
|||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product images for configurable variations
|
||||
*
|
||||
* @param Product $product
|
||||
* @return array
|
||||
*/
|
||||
protected function is($product)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -31,17 +31,27 @@ $(document).ready(function () {
|
|||
});
|
||||
},
|
||||
|
||||
addServerErrors: function () {
|
||||
var scope = null;
|
||||
addServerErrors: function (scope = null) {
|
||||
for (var key in serverErrors) {
|
||||
var inputNames = [];
|
||||
key.split('.').forEach(function(chunk, index) {
|
||||
if(index) {
|
||||
inputNames.push('[' + chunk + ']')
|
||||
} else {
|
||||
inputNames.push(chunk)
|
||||
}
|
||||
})
|
||||
|
||||
var inputName = inputNames.join('');
|
||||
|
||||
const field = this.$validator.fields.find({
|
||||
name: key,
|
||||
name: inputName,
|
||||
scope: scope
|
||||
});
|
||||
if (field) {
|
||||
this.$validator.errors.add({
|
||||
id: field.id,
|
||||
field: key,
|
||||
field: inputName,
|
||||
msg: serverErrors[key][0],
|
||||
scope: scope
|
||||
});
|
||||
|
|
|
|||
|
|
@ -157,6 +157,9 @@
|
|||
this_this.currentStep = 2;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
this_this.handleErrorResponse(error.response, 'address-form')
|
||||
})
|
||||
},
|
||||
|
||||
saveShipping () {
|
||||
|
|
@ -169,11 +172,14 @@
|
|||
this_this.currentStep = 3;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
this_this.handleErrorResponse(error.response, 'shipping-form')
|
||||
})
|
||||
},
|
||||
|
||||
savePayment () {
|
||||
var this_this = this;
|
||||
this.$http.post("{{ route('shop.checkout.save-payment') }}", {'shipping_method': this.selected_shipping_method})
|
||||
this.$http.post("{{ route('shop.checkout.save-payment') }}", {'shipping_method': this.selected_payment_method})
|
||||
.then(function(response) {
|
||||
if(response.data.jump_to_section == 'payment') {
|
||||
shippingHtml = Vue.compile(response.data.html)
|
||||
|
|
@ -181,6 +187,20 @@
|
|||
this_this.currentStep = 4;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
this_this.handleErrorResponse(error.response, 'payment-form')
|
||||
})
|
||||
},
|
||||
|
||||
handleErrorResponse (response, scope) {
|
||||
if(response.status == 422) {
|
||||
serverErrors = response.data.errors;
|
||||
this.$root.addServerErrors(scope)
|
||||
} else if(response.status == 403) {
|
||||
if(response.data.redirect_url) {
|
||||
window.location.href = response.data.redirect_url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1427,16 +1427,28 @@ $(document).ready(function () {
|
|||
},
|
||||
|
||||
addServerErrors: function addServerErrors() {
|
||||
var scope = null;
|
||||
var scope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
||||
|
||||
for (var key in serverErrors) {
|
||||
var inputNames = [];
|
||||
key.split('.').forEach(function (chunk, index) {
|
||||
if (index) {
|
||||
inputNames.push('[' + chunk + ']');
|
||||
} else {
|
||||
inputNames.push(chunk);
|
||||
}
|
||||
});
|
||||
|
||||
var inputName = inputNames.join('');
|
||||
|
||||
var field = this.$validator.fields.find({
|
||||
name: key,
|
||||
name: inputName,
|
||||
scope: scope
|
||||
});
|
||||
if (field) {
|
||||
this.$validator.errors.add({
|
||||
id: field.id,
|
||||
field: key,
|
||||
field: inputName,
|
||||
msg: serverErrors[key][0],
|
||||
scope: scope
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue