Skip to content
Permalink
Browse files

#676 Using localization for client side (one-page checkout, AjaxCart…

…, mainMenu)
  • Loading branch information...
DmitriyKulagin committed Sep 4, 2019
1 parent fb5f157 commit 6b25e4381ed52a8490c392672af39309e6f25f50
@@ -14523,6 +14523,9 @@
<LocaleResource Name="Admin.Vendors.VendorNotes.Fields.Note.Validation">
<Value>Vendor note can not be empty.</Value>
</LocaleResource>
<LocaleResource Name="AjaxCart.Failure">
<Value>Failed to add the product. Please refresh the page and try one more time.</Value>
</LocaleResource>
<LocaleResource Name="BackInStockSubscriptions.AlreadySubscribed">
<Value>You're already subscribed for this product back in stock notification</Value>
</LocaleResource>
@@ -15959,7 +15962,10 @@
</LocaleResource>
<LocaleResource Name="Languages.Selector.Label">
<Value>Languages selector</Value>
</LocaleResource>
</LocaleResource>
<LocaleResource Name="MainMenu.AjaxFailure">
<Value>Failed to open menu. Please refresh the page and try one more time.</Value>
</LocaleResource>
<LocaleResource Name="Manufacturers">
<Value>Manufacturers</Value>
</LocaleResource>
@@ -16566,6 +16572,12 @@
<LocaleResource Name="Payment.SelectCreditCard">
<Value>Select credit card</Value>
</LocaleResource>
<LocaleResource Name="PaymentMethod.NotAvailableMethodsError">
<Value>Your order cannot be completed at this time as there is no payment methods available for it.</Value>
</LocaleResource>
<LocaleResource Name="PaymentMethod.SpecifyMethodError">
<Value>Please specify payment method.</Value>
</LocaleResource>
<LocaleResource Name="PDFInvoice.Address">
<Value>Address: {0}</Value>
</LocaleResource>
@@ -17559,6 +17571,12 @@
<LocaleResource Name="Search.Vendor">
<Value>Vendor</Value>
</LocaleResource>
<LocaleResource Name="ShippingMethod.NotAvailableMethodsError">
<Value>Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.</Value>
</LocaleResource>
<LocaleResource Name="ShippingMethod.SpecifyMethodError">
<Value>Please specify shipping method.</Value>
</LocaleResource>
<LocaleResource Name="ShoppingCart">
<Value>Shopping cart</Value>
</LocaleResource>
@@ -111,7 +111,11 @@
@*shipping methods content will be loaded here*@
</div>
<script asp-location="Footer">
ShippingMethod.init('#co-shipping-method-form', '@(storeLocation)checkout/OpcSaveShippingMethod/');
var localized_data = {
NotAvailableMethodsError: "@T("ShippingMethod.NotAvailableMethodsError")",
SpecifyMethodError: "@T("ShippingMethod.SpecifyMethodError")"
};
ShippingMethod.init('#co-shipping-method-form', '@(storeLocation)checkout/OpcSaveShippingMethod/', localized_data);
</script>
<div class="buttons" id="shipping-method-buttons-container">
<p class="back-link">
@@ -135,7 +139,11 @@
</div>
</form>
<script asp-location="Footer">
PaymentMethod.init('#co-payment-method-form', '@(storeLocation)checkout/OpcSavePaymentMethod/');
var localized_data = {
NotAvailableMethodsError: "@T("PaymentMethod.NotAvailableMethodsError")",
SpecifyMethodError: "@T("PaymentMethod.SpecifyMethodError")"
};
PaymentMethod.init('#co-payment-method-form', '@(storeLocation)checkout/OpcSavePaymentMethod/', localized_data);
</script>
<div class="buttons" id="payment-method-buttons-container">
<p class="back-link">
@@ -113,8 +113,10 @@
$('.menu-toggle').on('click', function () {
$(this).siblings('.top-menu.mobile').slideToggle('slow');
});
mainMenu.init('@Url.Action("GetCatalogRoot", "Catalog")', '@Url.Action("GetCatalogSubCategories", "Catalog")', 'ul.top-menu.notmobile', 'ul.top-menu.mobile');
var localized_data = {
AjaxFailure: "@T("MainMenu.AjaxFailure")"
};
mainMenu.init('@Url.Action("GetCatalogRoot", "Catalog")', '@Url.Action("GetCatalogSubCategories", "Catalog")', 'ul.top-menu.notmobile', 'ul.top-menu.mobile', localized_data);
});
</script>

@@ -9,7 +9,10 @@
@await Component.InvokeAsync("AdminHeaderLinks")
@await Html.PartialAsync("_Header")
<script asp-location="Footer">
AjaxCart.init(false, '.header-links .cart-qty', '.header-links .wishlist-qty', '#flyout-cart');
var localized_data = {
AjaxCartFailure: "@T("AjaxCart.Failure")"
};
AjaxCart.init(false, '.header-links .cart-qty', '.header-links .wishlist-qty', '#flyout-cart', localized_data);
</script>
<div class="header-menu">
@await Component.InvokeAsync("TopMenu")
@@ -9,13 +9,15 @@ var AjaxCart = {
topcartselector: '',
topwishlistselector: '',
flyoutcartselector: '',
localized_data: false,

init: function (usepopupnotifications, topcartselector, topwishlistselector, flyoutcartselector) {
init: function (usepopupnotifications, topcartselector, topwishlistselector, flyoutcartselector, localized_data) {
this.loadWaiting = false;
this.usepopupnotifications = usepopupnotifications;
this.topcartselector = topcartselector;
this.topwishlistselector = topwishlistselector;
this.flyoutcartselector = flyoutcartselector;
this.localized_data = localized_data;
},

setLoadWaiting: function (display) {
@@ -25,7 +27,7 @@ var AjaxCart = {

//add a product to the cart/wishlist from the catalog pages
addproducttocart_catalog: function (urladd) {
if (this.loadWaiting != false) {
if (this.loadWaiting !== false) {
return;
}
this.setLoadWaiting(true);
@@ -42,7 +44,7 @@ var AjaxCart = {

//add a product to the cart/wishlist from the product details page
addproducttocart_details: function (urladd, formselector) {
if (this.loadWaiting != false) {
if (this.loadWaiting !== false) {
return;
}
this.setLoadWaiting(true);
@@ -60,7 +62,7 @@ var AjaxCart = {

//add a product to compare list
addproducttocomparelist: function (urladd) {
if (this.loadWaiting != false) {
if (this.loadWaiting !== false) {
return;
}
this.setLoadWaiting(true);
@@ -87,9 +89,9 @@ var AjaxCart = {
}
if (response.message) {
//display notification
if (response.success == true) {
if (response.success === true) {
//success
if (AjaxCart.usepopupnotifications == true) {
if (AjaxCart.usepopupnotifications === true) {
displayPopupNotification(response.message, 'success', true);
}
else {
@@ -99,7 +101,7 @@ var AjaxCart = {
}
else {
//error
if (AjaxCart.usepopupnotifications == true) {
if (AjaxCart.usepopupnotifications === true) {
displayPopupNotification(response.message, 'error', true);
}
else {
@@ -121,6 +123,6 @@ var AjaxCart = {
},

ajaxFailure: function () {
alert('Failed to add the product. Please refresh the page and try one more time.');
alert(this.localized_data.AjaxCartFailure);
}
};
@@ -3,10 +3,12 @@
subCatRoute: '',
topMenuRootSelector: '',
mobileMenuRootSelector: '',
localized_data: false,

init: function (rootRoute, subCatRoute, topMenuRootSelector, mobileMenuRootSelector) {
init: function (rootRoute, subCatRoute, topMenuRootSelector, mobileMenuRootSelector, localized_data) {
this.rootRoute = rootRoute;
this.subCatRoute = subCatRoute;
this.localized_data = localized_data;
this.topMenuRootSelector = $(topMenuRootSelector);
this.mobileMenuRootSelector = $(mobileMenuRootSelector);

@@ -160,6 +162,6 @@
},

ajaxFailure: function () {
alert('Failed to open menu. Please refresh the page and try one more time.');
alert(this.localized_data.AjaxFailure);
}
};
@@ -36,19 +36,20 @@ var Checkout = {
},

setLoadWaiting: function (step, keepDisabled) {
var container;
if (step) {
if (this.loadWaiting) {
this.setLoadWaiting(false);
}
var container = $('#' + step + '-buttons-container');
container = $('#' + step + '-buttons-container');
container.addClass('disabled');
container.css('opacity', '.5');
this._disableEnableAll(container, true);
$('#' + step + '-please-wait').show();
} else {
if (this.loadWaiting) {
var container = $('#' + this.loadWaiting + '-buttons-container');
var isDisabled = (keepDisabled ? true : false);
container = $('#' + this.loadWaiting + '-buttons-container');
var isDisabled = keepDisabled ? true : false;
if (!isDisabled) {
container.removeClass('disabled');
container.css('opacity', '1');
@@ -135,7 +136,7 @@ var Billing = {
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

Checkout.setLoadWaiting('billing');

@@ -157,7 +158,7 @@ var Billing = {
nextStep: function (response) {
//ensure that response.wrong_billing_address is set
//if not set, "true" is the default value
if (typeof response.wrong_billing_address == 'undefined') {
if (typeof response.wrong_billing_address === 'undefined') {
response.wrong_billing_address = false;
}
if (Billing.disableBillingAddressCheckoutStep) {
@@ -170,7 +171,7 @@ var Billing = {


if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));
@@ -232,7 +233,7 @@ var Shipping = {
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

Checkout.setLoadWaiting('shipping');

@@ -253,7 +254,7 @@ var Shipping = {

nextStep: function (response) {
if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));
@@ -277,16 +278,18 @@ var Shipping = {
var ShippingMethod = {
form: false,
saveUrl: false,
localized_data: false,

init: function (form, saveUrl) {
init: function (form, saveUrl, localized_data) {
this.form = form;
this.saveUrl = saveUrl;
this.localized_data = localized_data;
},

validate: function () {
var methods = document.getElementsByName('shippingoption');
if (methods.length==0) {
alert('Your order cannot be completed at this time as there is no shipping methods available for it. Please make necessary changes in your shipping address.');
if (methods.length === 0) {
alert(this.localized_data.NotAvailableMethodsError);
return false;
}

@@ -295,12 +298,12 @@ var ShippingMethod = {
return true;
}
}
alert('Please specify shipping method.');
alert(this.localized_data.SpecifyMethodError);
return false;
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

if (this.validate()) {
Checkout.setLoadWaiting('shipping-method');
@@ -323,7 +326,7 @@ var ShippingMethod = {

nextStep: function (response) {
if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));
@@ -341,10 +344,12 @@ var ShippingMethod = {
var PaymentMethod = {
form: false,
saveUrl: false,
localized_data: false,

init: function (form, saveUrl) {
init: function (form, saveUrl, localized_data) {
this.form = form;
this.saveUrl = saveUrl;
this.localized_data = localized_data;
},

toggleUseRewardPoints: function (useRewardPointsInput) {
@@ -358,8 +363,8 @@ var PaymentMethod = {

validate: function () {
var methods = document.getElementsByName('paymentmethod');
if (methods.length == 0) {
alert('Your order cannot be completed at this time as there is no payment methods available for it.');
if (methods.length === 0) {
alert(this.localized_data.NotAvailableMethodsError);
return false;
}

@@ -368,12 +373,12 @@ var PaymentMethod = {
return true;
}
}
alert('Please specify payment method.');
alert(this.localized_data.SpecifyMethodError);
return false;
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

if (this.validate()) {
Checkout.setLoadWaiting('payment-method');
@@ -395,7 +400,7 @@ var PaymentMethod = {

nextStep: function (response) {
if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));
@@ -420,7 +425,7 @@ var PaymentInfo = {
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

Checkout.setLoadWaiting('payment-info');
$.ajax({
@@ -440,7 +445,7 @@ var PaymentInfo = {

nextStep: function (response) {
if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));
@@ -466,7 +471,7 @@ var ConfirmOrder = {
},

save: function () {
if (Checkout.loadWaiting != false) return;
if (Checkout.loadWaiting !== false) return;

//terms of service
var termOfServiceOk = true;
@@ -500,7 +505,7 @@ var ConfirmOrder = {

nextStep: function (response) {
if (response.error) {
if ((typeof response.message) == 'string') {
if (typeof response.message === 'string') {
alert(response.message);
} else {
alert(response.message.join("\n"));

0 comments on commit 6b25e43

Please sign in to comment.
You can’t perform that action at this time.