From c50ba7ab6c443f4e7ed325b2c86a9934599438e6 Mon Sep 17 00:00:00 2001
From: rsalmeanob <rafael.salmean@openbravo.com>
Date: Mon, 16 Nov 2020 12:05:31 +0100
Subject: [PATCH] Added localStorage save of the previous steps to prevent
 refresh crash
 hansoft://handsoft.services.openbravo.com;services_handsoft;dc4ff49e/Task/3721?ID=233
 https://issues.openbravo.com/view.php?id=45075

---
 .../source/actions/doBack.js                              | 8 +++++++-
 .../source/components/defaultStep.js                      | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/web/org.openbravo.retail.selfcheckout/source/actions/doBack.js b/web/org.openbravo.retail.selfcheckout/source/actions/doBack.js
index 9e3adb9..e233daa 100644
--- a/web/org.openbravo.retail.selfcheckout/source/actions/doBack.js
+++ b/web/org.openbravo.retail.selfcheckout/source/actions/doBack.js
@@ -17,8 +17,14 @@ enyo.kind({
     // in: event, state, receipt
     // out: state, receipt, nextStep
     var state = data.state;
-    var previous = state.get('previousStepNames') || [];
+    previous = data.state.get('previousStepNames');
+    if (!previous) {
+      previous = OB.UTIL.localStorage.getItem('SCOPreviousStepNames')
+        ? OB.UTIL.localStorage.getItem('SCOPreviousStepNames').split(',')
+        : [];
+    }
     data.nextStep = previous.pop(); // if empty array -> undefined. This is OK, engine will show 'TechnicalError'
     state.set('previousStepNames', previous);
+    OB.UTIL.localStorage.setItem('SCOPreviousStepNames', previous);
   }
 });
diff --git a/web/org.openbravo.retail.selfcheckout/source/components/defaultStep.js b/web/org.openbravo.retail.selfcheckout/source/components/defaultStep.js
index 95e0ba6..69116f4 100644
--- a/web/org.openbravo.retail.selfcheckout/source/components/defaultStep.js
+++ b/web/org.openbravo.retail.selfcheckout/source/components/defaultStep.js
@@ -72,13 +72,19 @@ enyo.kind({
 
     // this step recalculates back step
     if (this.recalculateBackStep) {
-      previous = data.state.get('previousStepNames') || [];
+      previous = data.state.get('previousStepNames');
+      if (!previous) {
+        previous = OB.UTIL.localStorage.getItem('SCOPreviousStepNames')
+          ? OB.UTIL.localStorage.getItem('SCOPreviousStepNames').split(',')
+          : [];
+      }
       previous.push(data.state.get('stepName'));
       if (previous.length > 5) {
         // Just store a few
         previous.shift();
       }
       data.state.set('previousStepNames', previous);
+      OB.UTIL.localStorage.setItem('SCOPreviousStepNames', previous);
     }
 
     // Call super
-- 
2.17.1

