diff --git a/app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js b/app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js index 9c0ef8bb58c07..22b37b2da0b2f 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/checkout-data.js @@ -259,6 +259,29 @@ define([ obj.inputFieldEmailValue = email; saveData(obj); + }, + + /** + * Pulling the checked email value from persistence storage + * + * @return {*} + */ + getCheckedEmailValue: function () { + var obj = getData(); + + return obj.checkedEmailValue ? obj.checkedEmailValue : ''; + }, + + /** + * Setting the checked email value pulled from persistence storage + * + * @param {String} email + */ + setCheckedEmailValue: function (email) { + var obj = getData(); + + obj.checkedEmailValue = email; + saveData(obj); } }; }); diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js b/app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js index b9c4aeb27ad32..90ad07da0ae37 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js @@ -54,6 +54,15 @@ define([ return this; }, + /** @inheritdoc */ + initConfig: function () { + this._super(); + + this.isPasswordVisible = this.resolveInitialPasswordVisibility(); + + return this; + }, + /** * Callback on changing email property */ @@ -81,20 +90,19 @@ define([ * Check email existing. */ checkEmailAvailability: function () { - var self = this; - this.validateRequest(); this.isEmailCheckComplete = $.Deferred(); this.isLoading(true); this.checkRequest = checkEmailAvailability(this.isEmailCheckComplete, this.email()); $.when(this.isEmailCheckComplete).done(function () { - self.isPasswordVisible(false); - }).fail(function () { - self.isPasswordVisible(true); - }).always(function () { - self.isLoading(false); - }); + this.isPasswordVisible(false); + }.bind(this)).fail(function () { + this.isPasswordVisible(true); + checkoutData.setCheckedEmailValue(this.email()); + }.bind(this)).always(function () { + this.isLoading(false); + }.bind(this)); }, /** @@ -153,6 +161,19 @@ define([ fullScreenLoader.stopLoader(); }); } + }, + + /** + * Resolves an initial sate of a login form. + * + * @returns {Boolean} - initial visibility state. + */ + resolveInitialPasswordVisibility: function () { + if (checkoutData.getInputFieldEmailValue() !== '') { + return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue(); + } + + return false; } }); });