Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

checkout - address validation errors in alert box

DanielŻuławski42c3da5fb1d6
diff --git a/src/Web/Grand.Web/Views/Checkout/_BillingAddress.cshtml b/src/Web/Grand.Web/Views/Checkout/_BillingAddress.cshtml
index 41e0d0b38..37eb6830c 100644
--- a/src/Web/Grand.Web/Views/Checkout/_BillingAddress.cshtml
+++ b/src/Web/Grand.Web/Views/Checkout/_BillingAddress.cshtml
@@ -40,6 +40,17 @@
<partial name="_CreateOrUpdateAddress" model="Model.BillingAddress.NewAddress" view-data="dataDictAddress" />
}
</div>
+ <template v-if="vmorder.billingAddressErrors !== null">
+ <div class="alert alert-danger">
+ <ul class="m-0 p-0">
+ <template v-for="message in vmorder.billingAddressErrors">
+ <li>
+ {{message}}
+ </li>
+ </template>
+ </ul>
+ </div>
+ </template>
</div>
@await Component.InvokeAsync("Widget", new { widgetZone = "checkout_billing_address_bottom" })
</div>
diff --git a/src/Web/Grand.Web/Views/Checkout/_BillingWithoutShipping.cshtml b/src/Web/Grand.Web/Views/Checkout/_BillingWithoutShipping.cshtml
index 0a75f3b28..177324a8a 100644
--- a/src/Web/Grand.Web/Views/Checkout/_BillingWithoutShipping.cshtml
+++ b/src/Web/Grand.Web/Views/Checkout/_BillingWithoutShipping.cshtml
@@ -51,6 +51,17 @@
<partial name="_CreateOrUpdateAddress" model="Model.NewAddress" view-data="dataDictAddress" />
}
<div asp-validation-summary="ModelOnly" class="message-error"></div>
+ <template v-if="vmorder.billingAddressErrors !== null">
+ <div class="alert alert-danger">
+ <ul class="m-0 p-0">
+ <template v-for="message in vmorder.billingAddressErrors">
+ <li>
+ {{message}}
+ </li>
+ </template>
+ </ul>
+ </div>
+ </template>
</div>
</div>
@await Component.InvokeAsync("Widget", new { widgetZone = "checkout_billing_address_bottom" })
diff --git a/src/Web/Grand.Web/Views/Checkout/_ShippingAddress.cshtml b/src/Web/Grand.Web/Views/Checkout/_ShippingAddress.cshtml
index 384275565..2fa219e54 100644
--- a/src/Web/Grand.Web/Views/Checkout/_ShippingAddress.cshtml
+++ b/src/Web/Grand.Web/Views/Checkout/_ShippingAddress.cshtml
@@ -66,6 +66,17 @@
<partial name="_CreateOrUpdateAddress" model="Model.NewAddress" view-data="dataDictAddress" />
}
<div asp-validation-summary="ModelOnly" class="message-error"></div>
+ <template v-if="vmorder.shippingAddressErrors !== null">
+ <div class="alert alert-danger">
+ <ul class="m-0 p-0">
+ <template v-for="message in vmorder.shippingAddressErrors">
+ <li>
+ {{message}}
+ </li>
+ </template>
+ </ul>
+ </div>
+ </template>
</div>
</div>
@await Component.InvokeAsync("Widget", new { widgetZone = "checkout_shipping_address_bottom" })
diff --git a/src/Web/Grand.Web/wwwroot/theme/script/public.checkout.js b/src/Web/Grand.Web/wwwroot/theme/script/public.checkout.js
index c5ab6484e..49cdce834 100644
--- a/src/Web/Grand.Web/wwwroot/theme/script/public.checkout.js
+++ b/src/Web/Grand.Web/wwwroot/theme/script/public.checkout.js
@@ -56,12 +56,16 @@ var vmorder = new Vue({
// shippingbussy
shippingBussy: false,
// selectedshipping
- selectedShippingMethod: 0
+ selectedShippingMethod: 0,
+ shippingAddressErrors: null,
+ billingAddressErrors: null,
}
},
methods: {
formCheckoutSubmit() {
document.querySelector('#shipping-buttons-container .new-address-next-step-button').setAttribute('onclick', "vmorder.vShipping.save(); document.getElementById('opc-shipping-submit').click()");
+ vmorder.shippingAddressErrors = null;
+ vmorder.billingAddressErrors = null;
},
setDisabled(e) {
var button = e.target;
@@ -243,6 +247,7 @@ var vmorder = new Vue({
}
}
}
+
if (response.data.allow_sections) {
response.data.allow_sections.forEach(function (e) {
document.querySelector('#button-' + e).classList.add('allow');
@@ -363,6 +368,9 @@ var vmorder = new Vue({
vmorder.vShipping.nextStep(response);
}
}
+ if (response.data.wrong_shipping_address) {
+ vmorder.shippingAddressErrors = response.data.model_state;
+ }
}).catch(function (error) {
error.axiosFailure;
}).then(function () {
@@ -375,6 +383,7 @@ var vmorder = new Vue({
},
nextStep: function (response) {
+
if (response.data.error) {
if ((typeof response.data.message) == 'string') {
alert(response.data.message);
@@ -437,6 +446,9 @@ var vmorder = new Vue({
if (document.querySelector('#back-' + response.data.goto_section)) {
document.querySelector('#back-' + response.data.goto_section).setAttribute('onclick', 'document.querySelector("#button-billing").click(); vmorder.ShippingMethod = false;');
}
+ if (response.data.wrong_billing_address) {
+ vmorder.billingAddressErrors = response.data.model_state;
+ }
vmorder.vBilling.nextStep(response);
}).catch(function (error) {