'
+ ''
+ '
'
+ ''
+ '
'
@@ -269,14 +245,17 @@ function fillModalElement(editProductUrl) {
$.ajax({
url: editProductUrl,
method: 'GET',
- dataType: 'html',
- success: function (html) {
- var parsedHtml = parseHtml(html);
+ dataType: 'json',
+ success: function (data) {
+ var parsedHtml = parseHtml(data.renderedTemplate);
$('#editProductModal .modal-body').empty();
$('#editProductModal .modal-body').html(parsedHtml.body);
$('#editProductModal .modal-footer').html(parsedHtml.footer);
+ $('#editProductModal .modal-header .close .sr-only').text(data.closeButtonText);
+ $('#editProductModal .enter-message').text(data.enterDialogMessage);
$('#editProductModal').modal('show');
+ $('body').trigger('editproductmodal:ready');
$.spinner().stop();
},
error: function () {
@@ -340,6 +319,9 @@ module.exports = function () {
$('body > .modal-backdrop').remove();
$.spinner().start();
+
+ $('body').trigger('cart:beforeUpdate');
+
$.ajax({
url: url,
type: 'get',
@@ -354,6 +336,10 @@ module.exports = function () {
);
$('.number-of-items').empty().append(data.basket.resources.numberOfItems);
$('.minicart-quantity').empty().append(data.basket.numItems);
+ $('.minicart-link').attr({
+ 'aria-label': data.basket.resources.minicartCountOfItems,
+ title: data.basket.resources.minicartCountOfItems
+ });
$('.minicart .popover').empty();
$('.minicart .popover').removeClass('show');
$('body').removeClass('modal-open');
@@ -374,6 +360,9 @@ module.exports = function () {
$('body').trigger('setShippingMethodSelection', data.basket);
validateBasket(data.basket);
}
+
+ $('body').trigger('cart:update', data);
+
$.spinner().stop();
},
error: function (err) {
@@ -403,6 +392,8 @@ module.exports = function () {
$(this).parents('.card').spinner().start();
+ $('body').trigger('cart:beforeUpdate');
+
$.ajax({
url: url,
type: 'get',
@@ -416,6 +407,9 @@ module.exports = function () {
updateAvailability(data, uuid);
validateBasket(data);
$(this).data('pre-select-qty', quantity);
+
+ $('body').trigger('cart:update', data);
+
$.spinner().stop();
if ($(this).parents('.product-info').hasClass('bonus-product-line-item') && $('.cart-page').length) {
location.reload();
@@ -441,6 +435,7 @@ module.exports = function () {
// url = appendToUrl(url, urlParams);
$('.totals').spinner().start();
+ $('body').trigger('cart:beforeShippingMethodSelected');
$.ajax({
url: url,
type: 'post',
@@ -455,6 +450,8 @@ module.exports = function () {
updateApproachingDiscounts(data.approachingDiscounts);
validateBasket(data);
}
+
+ $('body').trigger('cart:shippingMethodSelected', data);
$.spinner().stop();
},
error: function (err) {
@@ -475,6 +472,7 @@ module.exports = function () {
$('.coupon-error-message').empty();
if (!$('.coupon-code-field').val()) {
$('.promo-code-form .form-control').addClass('is-invalid');
+ $('.promo-code-form .form-control').attr('aria-describedby', 'missingCouponCode');
$('.coupon-missing-error').show();
$.spinner().stop();
return false;
@@ -482,6 +480,7 @@ module.exports = function () {
var $form = $('.promo-code-form');
$('.promo-code-form .form-control').removeClass('is-invalid');
$('.coupon-error-message').empty();
+ $('body').trigger('promotion:beforeUpdate');
$.ajax({
url: $form.attr('action'),
@@ -491,17 +490,21 @@ module.exports = function () {
success: function (data) {
if (data.error) {
$('.promo-code-form .form-control').addClass('is-invalid');
+ $('.promo-code-form .form-control').attr('aria-describedby', 'invalidCouponCode');
$('.coupon-error-message').empty().append(data.errorMessage);
+ $('body').trigger('promotion:error', data);
} else {
$('.coupons-and-promos').empty().append(data.totals.discountsHtml);
updateCartTotals(data);
updateApproachingDiscounts(data.approachingDiscounts);
validateBasket(data);
+ $('body').trigger('promotion:success', data);
}
$('.coupon-code-field').val('');
$.spinner().stop();
},
error: function (err) {
+ $('body').trigger('promotion:error', err);
if (err.responseJSON.redirectUrl) {
window.location.href = err.responseJSON.redirectUrl;
} else {
@@ -543,6 +546,7 @@ module.exports = function () {
$('body > .modal-backdrop').remove();
$.spinner().start();
+ $('body').trigger('promotion:beforeUpdate');
$.ajax({
url: url,
type: 'get',
@@ -553,8 +557,10 @@ module.exports = function () {
updateApproachingDiscounts(data.approachingDiscounts);
validateBasket(data);
$.spinner().stop();
+ $('body').trigger('promotion:success', data);
},
error: function (err) {
+ $('body').trigger('promotion:error', err);
if (err.responseJSON.redirectUrl) {
window.location.href = err.responseJSON.redirectUrl;
} else {
@@ -566,6 +572,7 @@ module.exports = function () {
});
$('body').on('click', '.cart-page .bonus-product-button', function () {
$.spinner().start();
+ $(this).addClass('launched-modal');
$.ajax({
url: $(this).data('url'),
method: 'GET',
@@ -579,6 +586,20 @@ module.exports = function () {
}
});
});
+
+ $('body').on('hidden.bs.modal', '#chooseBonusProductModal', function () {
+ $('#chooseBonusProductModal').remove();
+ $('.modal-backdrop').remove();
+ $('body').removeClass('modal-open');
+
+ if ($('.cart-page').length) {
+ $('.launched-modal .btn-outline-primary').trigger('focus');
+ $('.launched-modal').removeClass('launched-modal');
+ } else {
+ $('.product-detail .add-to-cart').focus();
+ }
+ });
+
$('body').on('click', '.cart-page .product-edit .edit, .cart-page .bundle-edit .edit', function (e) {
e.preventDefault();
@@ -587,6 +608,26 @@ module.exports = function () {
fillModalElement(editProductUrl);
});
+ $('body').on('shown.bs.modal', '#editProductModal', function () {
+ $('#editProductModal').siblings().attr('aria-hidden', 'true');
+ $('#editProductModal .close').focus();
+ });
+
+ $('body').on('hidden.bs.modal', '#editProductModal', function () {
+ $('#editProductModal').siblings().attr('aria-hidden', 'false');
+ });
+
+ $('body').on('keydown', '#editProductModal', function (e) {
+ var focusParams = {
+ event: e,
+ containerSelector: '#editProductModal',
+ firstElementSelector: '.close',
+ lastElementSelector: '.update-cart-product-global',
+ nextToLastElementSelector: '.modal-footer .quantity-select'
+ };
+ focusHelper.setTabNextFocus(focusParams);
+ });
+
$('body').on('product:updateAddToCart', function (e, response) {
// update global add to cart (single products, bundles)
var dialog = $(response.$productContainer)
@@ -650,20 +691,30 @@ module.exports = function () {
$('.modal.show .update-cart-url').data('selected-quantity', selectedQuantity);
});
+ $('body').on('change', '.options-select', function () {
+ var selectedOptionValueId = $(this).children('option:selected').data('value-id');
+ $('.modal.show .update-cart-url').data('selected-option', selectedOptionValueId);
+ });
+
$('body').on('click', '.update-cart-product-global', function (e) {
e.preventDefault();
var updateProductUrl = $(this).closest('.cart-and-ipay').find('.update-cart-url').val();
var selectedQuantity = $(this).closest('.cart-and-ipay').find('.update-cart-url').data('selected-quantity');
+ var selectedOptionValueId = $(this).closest('.cart-and-ipay').find('.update-cart-url').data('selected-option');
var uuid = $(this).closest('.cart-and-ipay').find('.update-cart-url').data('uuid');
var form = {
uuid: uuid,
pid: base.getPidValue($(this)),
- quantity: selectedQuantity
+ quantity: selectedQuantity,
+ selectedOptionValueId: selectedOptionValueId
};
$(this).parents('.card').spinner().start();
+
+ $('body').trigger('cart:beforeUpdate');
+
if (updateProductUrl) {
$.ajax({
url: updateProductUrl,
@@ -672,9 +723,7 @@ module.exports = function () {
data: form,
dataType: 'json',
success: function (data) {
- $('#editProductModal').remove();
- $('.modal-backdrop').remove();
- $('body').removeClass('modal-open');
+ $('#editProductModal').modal('hide');
$('.coupons-and-promos').empty().append(data.cartModel.totals.discountsHtml);
updateCartTotals(data.cartModel);
@@ -688,6 +737,8 @@ module.exports = function () {
validateBasket(data.cartModel);
+ $('body').trigger('cart:update', data);
+
$.spinner().stop();
},
error: function (err) {
@@ -702,7 +753,6 @@ module.exports = function () {
}
});
-
base.selectAttribute();
base.colorAttribute();
base.removeBonusProduct();
@@ -710,4 +760,7 @@ module.exports = function () {
base.enableBonusProductSelection();
base.showMoreBonusProducts();
base.addBonusProductsToCart();
+ base.focusChooseBonusProductModal();
+ base.trapChooseBonusProductModalFocus();
+ base.onClosingChooseBonusProductModal();
};
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/address.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/address.js
index 07f0a01..182948a 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/address.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/address.js
@@ -172,7 +172,8 @@ module.exports = {
$('body').trigger('checkout:clearBillingForm');
var $option = $($el.parents('form').find('.addressSelector option')[0]);
$option.attr('value', 'new');
- $option.text('New Address');
+ var $newTitle = $('#dwfrm_billing input[name=localizedNewAddressTitle]').val();
+ $option.text($newTitle);
$option.prop('selected', 'selected');
$el.parents('[data-address-mode]').attr('data-address-mode', 'new');
} else {
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/billing.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/billing.js
index f8c9328..63c1c32 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/billing.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/billing.js
@@ -75,10 +75,10 @@ function updateBillingAddressSelector(order, customer) {
}
/**
- * updates the billing address form values within payment forms
+ * Updates the billing address form values within payment forms without any payment instrument validation
* @param {Object} order - the order model
*/
-function updateBillingAddressFormValues(order) {
+function updateBillingAddress(order) {
var billing = order.billing;
if (!billing.billingAddress || !billing.billingAddress.address) return;
@@ -96,16 +96,35 @@ function updateBillingAddressFormValues(order) {
$('select[name$=_country]', form).val(billing.billingAddress.address.countryCode.value);
$('input[name$=_phone]', form).val(billing.billingAddress.address.phone);
$('input[name$=_email]', form).val(order.orderEmail);
+}
- if (billing.payment && billing.payment.selectedPaymentInstruments
- && billing.payment.selectedPaymentInstruments.length > 0) {
- var instrument = billing.payment.selectedPaymentInstruments[0];
- $('select[name$=expirationMonth]', form).val(instrument.expirationMonth);
- $('select[name$=expirationYear]', form).val(instrument.expirationYear);
- // Force security code and card number clear
- $('input[name$=securityCode]', form).val('');
- $('input[name$=cardNumber]').data('cleave').setRawValue('');
- }
+/**
+ * Validate and update payment instrument form fields
+ * @param {Object} order - the order model
+ */
+function validateAndUpdateBillingPaymentInstrument(order) {
+ var billing = order.billing;
+ if (!billing.payment || !billing.payment.selectedPaymentInstruments
+ || billing.payment.selectedPaymentInstruments.length <= 0) return;
+
+ var form = $('form[name=dwfrm_billing]');
+ if (!form) return;
+
+ var instrument = billing.payment.selectedPaymentInstruments[0];
+ $('select[name$=expirationMonth]', form).val(instrument.expirationMonth);
+ $('select[name$=expirationYear]', form).val(instrument.expirationYear);
+ // Force security code and card number clear
+ $('input[name$=securityCode]', form).val('');
+ $('input[name$=cardNumber]').data('cleave').setRawValue('');
+}
+
+/**
+ * Updates the billing address form values within payment forms
+ * @param {Object} order - the order model
+ */
+function updateBillingAddressFormValues(order) {
+ module.exports.methods.updateBillingAddress(order);
+ module.exports.methods.validateAndUpdateBillingPaymentInstrument(order);
}
/**
@@ -124,17 +143,10 @@ function clearBillingAddressFormValues() {
}
/**
- * Updates the billing information in checkout, based on the supplied order model
+ * update billing address summary and contact information
* @param {Object} order - checkout model to use as basis of new truth
- * @param {Object} customer - customer model to use as basis of new truth
- * @param {Object} [options] - options
*/
-function updateBillingInformation(order, customer) {
- updateBillingAddressSelector(order, customer);
-
- // update billing address form
- updateBillingAddressFormValues(order);
-
+function updateBillingAddressSummary(order) {
// update billing address summary
addressHelpers.methods.populateAddressSummary('.billing .address-summary',
order.billing.billingAddress.address);
@@ -147,6 +159,22 @@ function updateBillingInformation(order, customer) {
}
}
+/**
+ * Updates the billing information in checkout, based on the supplied order model
+ * @param {Object} order - checkout model to use as basis of new truth
+ * @param {Object} customer - customer model to use as basis of new truth
+ * @param {Object} [options] - options
+ */
+function updateBillingInformation(order, customer) {
+ updateBillingAddressSelector(order, customer);
+
+ // update billing address form
+ updateBillingAddressFormValues(order);
+
+ // update billing address summary and billing parts of order summary
+ updateBillingAddressSummary(order);
+}
+
/**
* Updates the payment information in checkout, based on the supplied order model
* @param {Object} order - checkout model to use as basis of new truth
@@ -180,8 +208,6 @@ function clearCreditCardForm() {
$('select[name$="_expirationMonth"]').val('');
$('select[name$="_expirationYear"]').val('');
$('input[name$="_securityCode"]').val('');
- $('input[name$="_email"]').val('');
- $('input[name$="_phone"]').val('');
}
module.exports = {
@@ -191,7 +217,10 @@ module.exports = {
clearBillingAddressFormValues: clearBillingAddressFormValues,
updateBillingInformation: updateBillingInformation,
updatePaymentInformation: updatePaymentInformation,
- clearCreditCardForm: clearCreditCardForm
+ clearCreditCardForm: clearCreditCardForm,
+ updateBillingAddress: updateBillingAddress,
+ validateAndUpdateBillingPaymentInstrument: validateAndUpdateBillingPaymentInstrument,
+ updateBillingAddressSummary: updateBillingAddressSummary
},
showBillingDetails: function () {
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/checkout.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/checkout.js
index f1002f6..9c7551d 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/checkout.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/checkout.js
@@ -1,10 +1,12 @@
'use strict';
+var customerHelpers = require('./customer');
var addressHelpers = require('./address');
var shippingHelpers = require('./shipping');
var billingHelpers = require('./billing');
var summaryHelpers = require('./summary');
var formHelpers = require('./formErrors');
+var scrollAnimate = require('../components/scrollAnimate');
/**
@@ -27,6 +29,9 @@ var formHelpers = require('./formErrors');
// Collect form data from user input
//
var formData = {
+ // Customer Data
+ customer: {},
+
// Shipping Address
shipping: {},
@@ -44,6 +49,7 @@ var formHelpers = require('./formErrors');
// The different states/stages of checkout
//
var checkoutStages = [
+ 'customer',
'shipping',
'payment',
'placeOrder',
@@ -82,7 +88,37 @@ var formHelpers = require('./formErrors');
var stage = checkoutStages[members.currentStage];
var defer = $.Deferred(); // eslint-disable-line
- if (stage === 'shipping') {
+ if (stage === 'customer') {
+ //
+ // Clear Previous Errors
+ //
+ customerHelpers.methods.clearErrors();
+ //
+ // Submit the Customer Form
+ //
+ var customerFormSelector = customerHelpers.methods.isGuestFormActive() ? customerHelpers.vars.GUEST_FORM : customerHelpers.vars.REGISTERED_FORM;
+ var customerForm = $(customerFormSelector);
+ $.ajax({
+ url: customerForm.attr('action'),
+ type: 'post',
+ data: customerForm.serialize(),
+ success: function (data) {
+ if (data.redirectUrl) {
+ window.location.href = data.redirectUrl;
+ } else {
+ customerHelpers.methods.customerFormResponse(defer, data);
+ }
+ },
+ error: function (err) {
+ if (err.responseJSON && err.responseJSON.redirectUrl) {
+ window.location.href = err.responseJSON.redirectUrl;
+ }
+ // Server error submitting form
+ defer.reject(err.responseJSON);
+ }
+ });
+ return defer;
+ } else if (stage === 'shipping') {
//
// Clear Previous Errors
//
@@ -93,21 +129,25 @@ var formHelpers = require('./formErrors');
//
var isMultiShip = $('#checkout-main').hasClass('multi-ship');
var formSelector = isMultiShip ?
- '.multi-shipping .active form' : '.single-shipping .shipping-form';
+ '.multi-shipping .active form' : '.single-shipping .shipping-form';
var form = $(formSelector);
if (isMultiShip && form.length === 0) {
+ // disable the next:Payment button here
+ $('body').trigger('checkout:disableButton', '.next-step-button button');
// in case the multi ship form is already submitted
var url = $('#checkout-main').attr('data-checkout-get-url');
$.ajax({
url: url,
method: 'GET',
success: function (data) {
+ // enable the next:Payment button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
if (!data.error) {
$('body').trigger('checkout:updateCheckoutView',
{ order: data.order, customer: data.customer });
defer.resolve();
- } else if ($('.shipping-error .alert-danger').length < 1) {
+ } else if (data.message && $('.shipping-error .alert-danger').length < 1) {
var errorMsg = data.message;
var errorHtml = '
' +
@@ -115,10 +155,15 @@ var formHelpers = require('./formErrors');
'×' +
'' + errorMsg + '
';
$('.shipping-error').append(errorHtml);
+ scrollAnimate($('.shipping-error'));
defer.reject();
+ } else if (data.redirectUrl) {
+ window.location.href = data.redirectUrl;
}
},
error: function () {
+ // enable the next:Payment button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
// Server error submitting form
defer.reject();
}
@@ -133,16 +178,21 @@ var formHelpers = require('./formErrors');
shippingFormData = data;
}
});
-
+ // disable the next:Payment button here
+ $('body').trigger('checkout:disableButton', '.next-step-button button');
$.ajax({
url: form.attr('action'),
type: 'post',
data: shippingFormData,
success: function (data) {
+ // enable the next:Payment button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
shippingHelpers.methods.shippingFormResponse(defer, data);
},
error: function (err) {
- if (err.responseJSON.redirectUrl) {
+ // enable the next:Payment button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
+ if (err.responseJSON && err.responseJSON.redirectUrl) {
window.location.href = err.responseJSON.redirectUrl;
}
// Server error submitting form
@@ -158,14 +208,46 @@ var formHelpers = require('./formErrors');
formHelpers.clearPreviousErrors('.payment-form');
- var paymentForm = $('#dwfrm_billing').serialize();
+ var billingAddressForm = $('#dwfrm_billing .billing-address-block :input').serialize();
$('body').trigger('checkout:serializeBilling', {
- form: $('#dwfrm_billing'),
- data: paymentForm,
- callback: function (data) { paymentForm = data; }
+ form: $('#dwfrm_billing .billing-address-block'),
+ data: billingAddressForm,
+ callback: function (data) {
+ if (data) {
+ billingAddressForm = data;
+ }
+ }
+ });
+
+ var contactInfoForm = $('#dwfrm_billing .contact-info-block :input').serialize();
+
+ $('body').trigger('checkout:serializeBilling', {
+ form: $('#dwfrm_billing .contact-info-block'),
+ data: contactInfoForm,
+ callback: function (data) {
+ if (data) {
+ contactInfoForm = data;
+ }
+ }
+ });
+
+ var activeTabId = $('.tab-pane.active').attr('id');
+ var paymentInfoSelector = '#dwfrm_billing .' + activeTabId + ' .payment-form-fields :input';
+ var paymentInfoForm = $(paymentInfoSelector).serialize();
+
+ $('body').trigger('checkout:serializeBilling', {
+ form: $(paymentInfoSelector),
+ data: paymentInfoForm,
+ callback: function (data) {
+ if (data) {
+ paymentInfoForm = data;
+ }
+ }
});
+ var paymentForm = billingAddressForm + '&' + contactInfoForm + '&' + paymentInfoForm;
+
if ($('.data-checkout-stage').data('customer-type') === 'registered') {
// if payment method is credit card
if ($('.payment-information').data('payment-method-id') === 'CREDIT_CARD') {
@@ -174,9 +256,11 @@ var formHelpers = require('./formErrors');
'selected-payment .saved-payment-security-code').val();
if (cvvCode === '') {
- $('.saved-payment-instrument.' +
+ var cvvElement = $('.saved-payment-instrument.' +
'selected-payment ' +
- '.form-control').addClass('is-invalid');
+ '.form-control');
+ cvvElement.addClass('is-invalid');
+ scrollAnimate(cvvElement);
defer.reject();
return defer;
}
@@ -192,12 +276,16 @@ var formHelpers = require('./formErrors');
}
}
}
+ // disable the next:Place Order button here
+ $('body').trigger('checkout:disableButton', '.next-step-button button');
$.ajax({
url: $('#dwfrm_billing').attr('action'),
method: 'POST',
data: paymentForm,
success: function (data) {
+ // enable the next:Place Order button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
// look for field validation errors
if (data.error) {
if (data.fieldErrors.length) {
@@ -212,6 +300,7 @@ var formHelpers = require('./formErrors');
data.serverErrors.forEach(function (error) {
$('.error-message').show();
$('.error-message-text').text(error);
+ scrollAnimate($('.error-message'));
});
}
@@ -239,11 +328,14 @@ var formHelpers = require('./formErrors');
$('.cancel-new-payment').removeClass('checkout-hidden');
}
+ scrollAnimate();
defer.resolve(data);
}
},
error: function (err) {
- if (err.responseJSON.redirectUrl) {
+ // enable the next:Place Order button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
+ if (err.responseJSON && err.responseJSON.redirectUrl) {
window.location.href = err.responseJSON.redirectUrl;
}
}
@@ -251,10 +343,14 @@ var formHelpers = require('./formErrors');
return defer;
} else if (stage === 'placeOrder') {
+ // disable the placeOrder button here
+ $('body').trigger('checkout:disableButton', '.next-step-button button');
$.ajax({
url: $('.place-order').data('action'),
method: 'POST',
success: function (data) {
+ // enable the placeOrder button here
+ $('body').trigger('checkout:enableButton', '.next-step-button button');
if (data.error) {
if (data.cartError) {
window.location.href = data.redirectUrl;
@@ -264,22 +360,34 @@ var formHelpers = require('./formErrors');
defer.reject(data);
}
} else {
- var continueUrl = data.continueUrl;
- var urlParams = {
- ID: data.orderID,
- token: data.orderToken
- };
-
- continueUrl += (continueUrl.indexOf('?') !== -1 ? '&' : '?') +
- Object.keys(urlParams).map(function (key) {
- return key + '=' + encodeURIComponent(urlParams[key]);
- }).join('&');
-
- window.location.href = continueUrl;
+ var redirect = $('
';
$('.shipping-error').append(errorHtml);
+ scrollAnimate($('.shipping-error'));
}
/**
@@ -502,7 +510,7 @@ function shippingFormResponse(defer, data) {
order: data.order,
customer: data.customer
});
-
+ scrollAnimate($('.payment-form'));
defer.resolve(data);
}
}
@@ -516,16 +524,16 @@ function clearShippingForms(order) {
var form = el.form;
if (!form) return;
- $('input[name$=_firstName]', form).val(null);
- $('input[name$=_lastName]', form).val(null);
- $('input[name$=_address1]', form).val(null);
- $('input[name$=_address2]', form).val(null);
- $('input[name$=_city]', form).val(null);
- $('input[name$=_postalCode]', form).val(null);
- $('select[name$=_stateCode],input[name$=_stateCode]', form).val(null);
- $('select[name$=_country]', form).val(null);
+ $('input[name$=_firstName]', form).val('');
+ $('input[name$=_lastName]', form).val('');
+ $('input[name$=_address1]', form).val('');
+ $('input[name$=_address2]', form).val('');
+ $('input[name$=_city]', form).val('');
+ $('input[name$=_postalCode]', form).val('');
+ $('select[name$=_stateCode],input[name$=_stateCode]', form).val('');
+ $('select[name$=_country]', form).val('');
- $('input[name$=_phone]', form).val(null);
+ $('input[name$=_phone]', form).val('');
$('input[name$=_isGift]', form).prop('checked', false);
$('textarea[name$=_giftMessage]', form).val('');
@@ -564,6 +572,7 @@ function createNewShipment(url, shipmentData) {
*/
function selectShippingMethodAjax(url, urlParams, el) {
$.spinner().start();
+ $('body').trigger('checkout:beforeShippingMethodSelected');
$.ajax({
url: url,
type: 'post',
@@ -588,6 +597,7 @@ function selectShippingMethodAjax(url, urlParams, el) {
}
);
}
+ $('body').trigger('checkout:shippingMethodSelected', data);
$.spinner().stop();
})
.fail(function () {
@@ -686,6 +696,8 @@ module.exports = {
},
selectShippingMethod: function () {
+ var baseObj = this;
+
$('.shipping-method-list').change(function () {
var $shippingForm = $(this).parents('form');
var methodID = $(':checked', this).val();
@@ -697,11 +709,18 @@ module.exports = {
urlParams.giftMessage = $shippingForm.find('textarea[name$=_giftMessage]').val();
var url = $(this).data('select-shipping-method-url');
- selectShippingMethodAjax(url, urlParams, $(this));
+
+ if (baseObj.methods && baseObj.methods.selectShippingMethodAjax) {
+ baseObj.methods.selectShippingMethodAjax(url, urlParams, $(this));
+ } else {
+ selectShippingMethodAjax(url, urlParams, $(this));
+ }
});
},
toggleMultiship: function () {
+ var baseObj = this;
+
$('input[name="usingMultiShipping"]').on('change', function () {
var url = $('.multi-shipping-checkbox-block form').attr('action');
var usingMultiShip = this.checked;
@@ -721,7 +740,11 @@ module.exports = {
});
if ($('#checkout-main').data('customer-type') === 'guest') {
- clearShippingForms(response.order);
+ if (baseObj.methods && baseObj.methods.clearShippingForms) {
+ baseObj.methods.clearShippingForms(response.order);
+ } else {
+ clearShippingForms(response.order);
+ }
} else {
response.order.shipping.forEach(function (shipping) {
$('input[value=' + shipping.UUID + ']').each(function (formIndex, el) {
@@ -761,6 +784,8 @@ module.exports = {
},
selectMultiShipping: function () {
+ var baseObj = this;
+
$('body').on('shipping:selectMultiShipping', function (e, data) {
$('.multi-shipping .shipping-address').addClass('d-none');
@@ -768,9 +793,19 @@ module.exports = {
var element = $('.multi-shipping .card[data-shipment-uuid="' + shipping.UUID + '"]');
if (shipping.shippingAddress) {
- viewMultishipAddress($(element));
+ if (baseObj.methods && baseObj.methods.viewMultishipAddress) {
+ baseObj.methods.viewMultishipAddress($(element));
+ } else {
+ viewMultishipAddress($(element));
+ }
} else {
- enterMultishipView($(element));
+ /* eslint-disable no-lonely-if */
+ if (baseObj.methods && baseObj.methods.enterMultishipView) {
+ baseObj.methods.enterMultishipView($(element));
+ } else {
+ enterMultishipView($(element));
+ }
+ /* eslint-enable no-lonely-if */
}
});
});
@@ -784,16 +819,14 @@ module.exports = {
var shipmentUUID = selectedOption[0].value;
var originalUUID = $('input[name=shipmentUUID]', form).val();
var element;
-
Object.keys(attrs).forEach(function (attr) {
element = attr === 'countryCode' ? 'country' : attr;
$('[name$=' + element + ']', form).val(attrs[attr]);
});
-
$('[name$=stateCode]', form).trigger('change');
-
if (shipmentUUID === 'new') {
$(form).attr('data-address-mode', 'new');
+ $(form).find('.shipping-address-block').removeClass('d-none');
} else if (shipmentUUID === originalUUID) {
$(form).attr('data-address-mode', 'shipment');
} else if (shipmentUUID.indexOf('ab_') === 0) {
@@ -805,6 +838,8 @@ module.exports = {
},
selectMultiShipAddress: function () {
+ var baseObj = this;
+
$('.multi-shipping .addressSelector').on('change', function () {
var form = $(this).closest('form');
var selectedOption = $('option:selected', this);
@@ -812,6 +847,7 @@ module.exports = {
var shipmentUUID = selectedOption[0].value;
var originalUUID = $('input[name=shipmentUUID]', form).val();
var pliUUID = $('input[name=productLineItemUUID]', form).val();
+ var createNewShipmentScoped = baseObj.methods && baseObj.methods.createNewShipment ? baseObj.methods.createNewShipment : createNewShipment;
var element;
Object.keys(attrs).forEach(function (attr) {
@@ -826,7 +862,7 @@ module.exports = {
if (shipmentUUID === 'new' && pliUUID) {
var createShipmentUrl = $(this).attr('data-create-shipment-url');
- createNewShipment(createShipmentUrl, { productLineItemUUID: pliUUID })
+ createNewShipmentScoped(createShipmentUrl, { productLineItemUUID: pliUUID })
.done(function (response) {
$.spinner().stop();
if (response.error) {
@@ -855,7 +891,7 @@ module.exports = {
} else if (shipmentUUID.indexOf('ab_') === 0) {
var url = $(form).attr('action');
var serializedData = $(form).serialize();
- createNewShipment(url, serializedData)
+ createNewShipmentScoped(url, serializedData)
.done(function (response) {
$.spinner().stop();
if (response.error) {
@@ -883,7 +919,7 @@ module.exports = {
} else {
var updatePLIShipmentUrl = $(form).attr('action');
var serializedAddress = $(form).serialize();
- createNewShipment(updatePLIShipmentUrl, serializedAddress)
+ createNewShipmentScoped(updatePLIShipmentUrl, serializedAddress)
.done(function (response) {
$.spinner().stop();
if (response.error) {
@@ -911,9 +947,15 @@ module.exports = {
},
updateShippingList: function () {
+ var baseObj = this;
+
$('select[name$="shippingAddress_addressFields_states_stateCode"]')
.on('change', function (e) {
- updateShippingMethodList($(e.currentTarget.form));
+ if (baseObj.methods && baseObj.methods.updateShippingMethodList) {
+ baseObj.methods.updateShippingMethodList($(e.currentTarget.form));
+ } else {
+ updateShippingMethodList($(e.currentTarget.form));
+ }
});
},
@@ -924,22 +966,36 @@ module.exports = {
},
enterMultiShipInfo: function () {
+ var baseObj = this;
+
$('.btn-enter-multi-ship').on('click', function (e) {
e.preventDefault();
- editOrEnterMultiShipInfo($(this), 'new');
+ if (baseObj.methods && baseObj.methods.editOrEnterMultiShipInfo) {
+ baseObj.methods.editOrEnterMultiShipInfo($(this), 'new');
+ } else {
+ editOrEnterMultiShipInfo($(this), 'new');
+ }
});
},
editMultiShipInfo: function () {
+ var baseObj = this;
+
$('.btn-edit-multi-ship').on('click', function (e) {
e.preventDefault();
- editOrEnterMultiShipInfo($(this), 'edit');
+ if (baseObj.methods && baseObj.methods.editOrEnterMultiShipInfo) {
+ baseObj.methods.editOrEnterMultiShipInfo($(this), 'edit');
+ } else {
+ editOrEnterMultiShipInfo($(this), 'edit');
+ }
});
},
saveMultiShipInfo: function () {
+ var baseObj = this;
+
$('.btn-save-multi-ship').on('click', function (e) {
e.preventDefault();
@@ -969,6 +1025,8 @@ module.exports = {
$.each(response.serverErrors, function (index, element) {
createErrorNotification(element);
});
+ } else if (response.redirectUrl) {
+ window.location.href = response.redirectUrl;
}
} else {
// Update UI from response
@@ -979,7 +1037,11 @@ module.exports = {
}
);
- viewMultishipAddress($rootEl);
+ if (baseObj.methods && baseObj.methods.viewMultishipAddress) {
+ baseObj.methods.viewMultishipAddress($rootEl);
+ } else {
+ viewMultishipAddress($rootEl);
+ }
}
if (response.order && response.order.shippable) {
@@ -1001,6 +1063,8 @@ module.exports = {
},
cancelMultiShipAddress: function () {
+ var baseObj = this;
+
$('.btn-cancel-multi-ship-address').on('click', function (e) {
e.preventDefault();
@@ -1014,13 +1078,21 @@ module.exports = {
var originalStateCode = restoreStateObj.shippingAddress.stateCode;
var stateCode = $('[name$=_stateCode]', form).val();
- updateShippingAddressFormValues(restoreStateObj);
+ if (baseObj.methods && baseObj.methods.updateShippingAddressFormValues) {
+ baseObj.methods.updateShippingAddressFormValues(restoreStateObj);
+ } else {
+ updateShippingAddressFormValues(restoreStateObj);
+ }
if (stateCode !== originalStateCode) {
$('[data-action=save]', form).trigger('click');
} else {
$(form).attr('data-address-mode', 'edit');
- editMultiShipAddress($rootEl);
+ if (baseObj.methods && baseObj.methods.editMultiShipAddress) {
+ baseObj.methods.editMultiShipAddress($rootEl);
+ } else {
+ editMultiShipAddress($rootEl);
+ }
}
}
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/summary.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/summary.js
index c51c2c4..c3b5a77 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/summary.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/checkout/summary.js
@@ -11,18 +11,18 @@ function updateTotals(totals) {
$('.grand-total-sum').text(totals.grandTotal);
if (totals.orderLevelDiscountTotal.value > 0) {
- $('.order-discount').show();
+ $('.order-discount').removeClass('hide-order-discount');
$('.order-discount-total').text('- ' + totals.orderLevelDiscountTotal.formatted);
} else {
- $('.order-discount').hide();
+ $('.order-discount').addClass('hide-order-discount');
}
if (totals.shippingLevelDiscountTotal.value > 0) {
- $('.shipping-discount').show();
+ $('.shipping-discount').removeClass('hide-shipping-discount');
$('.shipping-discount-total').text('- ' +
totals.shippingLevelDiscountTotal.formatted);
} else {
- $('.shipping-discount').hide();
+ $('.shipping-discount').addClass('hide-shipping-discount');
}
}
@@ -130,6 +130,14 @@ function updateOrderProductSummaryInformation(order) {
});
$('.product-summary-block').html($productSummary.html());
+
+ // Also update the line item prices, as they might have been altered
+ $('.grand-total-price').text(order.totals.subTotal);
+ order.items.items.forEach(function (item) {
+ if (item.priceTotal && item.priceTotal.renderedPrice) {
+ $('.item-total-' + item.UUID).empty().append(item.priceTotal.renderedPrice);
+ }
+ });
}
module.exports = {
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/cleave.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/cleave.js
index 3c0692c..98ec696 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/cleave.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/cleave.js
@@ -1,6 +1,6 @@
'use strict';
-var Cleave = require('cleave.js');
+var Cleave = require('cleave.js').default;
module.exports = {
handleCreditCardNumber: function (cardFieldSelector, cardTypeSelector) {
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/collapsibleItem.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/collapsibleItem.js
index 05ed6c4..cd72108 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/collapsibleItem.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/collapsibleItem.js
@@ -3,10 +3,16 @@ module.exports = function () {
var sizes = ['xs', 'sm', 'md', 'lg', 'xl'];
sizes.forEach(function (size) {
- var selector = '.collapsible-' + size + ' .title, .collapsible-' + size + '>.card-header';
+ var selector = '.collapsible-' + size + ' .title';
$('body').on('click', selector, function (e) {
e.preventDefault();
$(this).parents('.collapsible-' + size).toggleClass('active');
+
+ if ($(this).parents('.collapsible-' + size).hasClass('active')) {
+ $(this).attr('aria-expanded', true);
+ } else {
+ $(this).attr('aria-expanded', false);
+ }
});
});
};
diff --git a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/consentTracking.js b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/consentTracking.js
index 0e58092..dcc2f7a 100644
--- a/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/consentTracking.js
+++ b/sfra/cartridges/app_storefront_base/cartridge/client/default/js/components/consentTracking.js
@@ -1,22 +1,27 @@
'use strict';
+var focusHelper = require('../components/focus');
+
/**
* Renders a modal window that will track the users consenting to accepting site tracking policy
*/
function showConsentModal() {
- if (!$('.tracking-consent').data('caonline')) {
+ var trackingConsentData = $('.tracking-consent');
+ if (!trackingConsentData.data('caonline')) {
return;
}
- var urlContent = $('.tracking-consent').data('url');
- var urlAccept = $('.tracking-consent').data('accept');
- var urlReject = $('.tracking-consent').data('reject');
- var textYes = $('.tracking-consent').data('accepttext');
- var textNo = $('.tracking-consent').data('rejecttext');
- var textHeader = $('.tracking-consent').data('heading');
+ var urlContent = trackingConsentData.data('url');
+ var urlAccept = trackingConsentData.data('accept');
+ var urlReject = trackingConsentData.data('reject');
+ var textYes = trackingConsentData.data('accepttext');
+ var textNo = trackingConsentData.data('rejecttext');
+ var textHeader = trackingConsentData.data('heading');
+ var tokenName = trackingConsentData.data('tokenname');
+ var token = trackingConsentData.data('token');
var htmlString = ''
- + '
'
+ + '
'
+ '
'
+ ''
+ '
'
@@ -26,10 +31,10 @@ function showConsentModal() {
+ '
'
+ '