From 98e7951b5a55e5f1fe2e8a3f63c4386623000c6c Mon Sep 17 00:00:00 2001
From: Oleksandr Miroshnichenko <omiroshnichenko@magento.com>
Date: Mon, 11 Dec 2017 11:17:43 +0200
Subject: [PATCH] 8410: Custom Checkout Step and Shipping Step are Highlighted

---
 .../view/frontend/web/js/model/step-navigator.js   | 14 ++++++++++++--
 .../Checkout/view/frontend/web/js/view/payment.js  | 14 --------------
 .../Checkout/view/frontend/web/js/view/shipping.js | 11 -----------
 .../Checkout/frontend/js/view/shipping.test.js     |  2 +-
 4 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/step-navigator.js b/app/code/Magento/Checkout/view/frontend/web/js/model/step-navigator.js
index bfcd0d02585..2341748bc4e 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/model/step-navigator.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/model/step-navigator.js
@@ -66,7 +66,7 @@ define([
          * @param {*} sortOrder
          */
         registerStep: function (code, alias, title, isVisible, navigate, sortOrder) {
-            var hash;
+            var hash, active;
 
             if ($.inArray(code, this.validCodes) !== -1) {
                 throw new DOMException('Step code [' + code + '] already registered in step navigator');
@@ -87,6 +87,12 @@ define([
                 navigate: navigate,
                 sortOrder: sortOrder
             });
+            active = this.getActiveItemIndex();
+            steps.each(function (elem, index) {
+                if (active !== index) {
+                    elem.isVisible(false);
+                }
+            });
             this.stepCodes.push(code);
             hash = window.location.hash.replace('#', '');
 
@@ -111,10 +117,14 @@ define([
         getActiveItemIndex: function () {
             var activeIndex = 0;
 
-            steps.sort(this.sortItems).forEach(function (element, index) {
+            steps.sort(this.sortItems).some(function (element, index) {
                 if (element.isVisible()) {
                     activeIndex = index;
+
+                    return true;
                 }
+
+                return false;
             });
 
             return activeIndex;
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/payment.js b/app/code/Magento/Checkout/view/frontend/web/js/view/payment.js
index 309395d4475..c17e5e40d5c 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/view/payment.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/view/payment.js
@@ -46,22 +46,8 @@ define([
 
         /** @inheritdoc */
         initialize: function () {
-            var self = this;
-
             this._super();
             checkoutDataResolver.resolvePaymentMethod();
-
-            //If some step is active this step will become inactive.
-            if (stepNavigator.steps()) {
-                stepNavigator.steps().some(function (element) {
-                    if (element.isVisible()) {
-                        self.isVisible(false);
-
-                        return true;
-                    }
-                });
-            }
-
             stepNavigator.registerStep(
                 'payment',
                 null,
diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js
index 52078488af4..619de95e467 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js
@@ -82,17 +82,6 @@ define([
             this._super();
 
             if (!quote.isVirtual()) {
-                //If some step is active this step will become inactive.
-                if (stepNavigator.steps()) {
-                    stepNavigator.steps().some(function (element) {
-                        if (element.isVisible()) {
-                            self.visible(false);
-
-                            return true;
-                        }
-                    });
-                }
-
                 stepNavigator.registerStep(
                     'shipping',
                     '',
diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js
index b25c36de28a..be27e16a137 100644
--- a/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js
+++ b/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js
@@ -42,7 +42,7 @@ define(['squire', 'ko', 'jquery', 'jquery/validate'], function (Squire, ko, $) {
             'Magento_Checkout/js/action/select-shipping-method': jasmine.createSpy(),
             'Magento_Checkout/js/model/shipping-rate-registry': jasmine.createSpy(),
             'Magento_Checkout/js/action/set-shipping-information': jasmine.createSpy(),
-            'Magento_Checkout/js/model/step-navigator': jasmine.createSpyObj('navigator', ['registerStep', 'steps']),
+            'Magento_Checkout/js/model/step-navigator': jasmine.createSpyObj('navigator', ['registerStep']),
             'Magento_Ui/js/modal/modal': jasmine.createSpy('modal').and.returnValue(modalStub),
             'Magento_Checkout/js/model/checkout-data-resolver': jasmine.createSpyObj(
                 'dataResolver',
-- 
GitLab