4
  • Login in
  • Add product to cart
  • In top bar there is text "Welcome Michael Surname", but there is still option to sign-in and sign-up next to it.
  • Go to cart > checkout
  • Login prompt is displayed enter image description here

minicart code

<div data-block="minicart" class="minicart-wrapper">
    <a class="action showcart desktop" href="<?= /* @escapeNotVerified */ $block->getShoppingCartUrl() ?>"
       data-bind="scope: 'minicart_content'">
       <svg class="cart-icon"><use xlink:href="<?php echo $this->getViewFileUrl('images/icon-sprite.svg#cart');?>"></use></svg>
            <span class="counter qty empty"
              data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
            <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
            <span class="counter-label">
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            </span>
        </span>
    </a>
    <a class="action showcart mobile" href="<?= /* @escapeNotVerified */ $block->getShoppingCartUrl() ?>"
       data-bind="scope: 'minicart_content'">
       <svg class="cart-icon"><use xlink:href="<?php echo $this->getViewFileUrl('images/icon-sprite.svg#cart');?>"></use></svg>
            <span class="counter qty empty">
            <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
        </span>
    </a>
    <?php if ($block->getIsNeedToDisplaySideBar()): ?>
        <div class="block block-minicart empty"
             data-role="dropdownDialog"
             data-mage-init='{"dropdownDialog":{
                "appendTo":"[data-block=minicart]",
                "triggerTarget":".showcart.desktop",
                "timeout": "2000",
                "closeOnMouseLeave": false,
                "closeOnEscape": true,
                "triggerClass":"active",
                "parentClass":"active",
                "buttons":[]}}'>
            <div id="minicart-content-wrapper" data-bind="scope: 'minicart_content'">
                <div data-bind="css: { empty: !!getCartParam('summary_count') == false }">
                <!-- ko template: getTemplate() --><!-- /ko -->
                </div>
            </div>
            <?= $block->getChildHtml('minicart.addons') ?>
        </div>
    <?php endif ?>
    <script>
        window.checkout = <?= /* @escapeNotVerified */ $block->getSerializedConfig() ?>;
    </script>
    <script type="text/x-magento-init">
    {
        "[data-block='minicart']": {
            "Magento_Ui/js/core/app": <?= /* @escapeNotVerified */ $block->getJsLayout() ?>
        },
        "*": {
            "Magento_Ui/js/block-loader": "<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
        }
    }
    </script>
</div>
10
  • because you disable guest checkout from adminpanel or you customize checkout module ?? May 1, 2018 at 12:43
  • Yes i have disable guest checkout but it showing when i'm already logged ig by login page May 1, 2018 at 13:08
  • Which Magento version are you using? May 1, 2018 at 13:38
  • version is 2.2.2 May 5, 2018 at 6:55
  • 1
    Can you share your minicart code that you customize?
    – Sohel Rana
    Jul 13, 2018 at 17:41

2 Answers 2

3

i have faced similar issue earlier and have got resolved the issue, hope it helps.It's better to extend it in custom module but for quick check you test it in core and later can extend it in your module.Goto to your SesionManager.php in path

vendor/magento/framework/Session/SessionManager.php

Search for the function regenerateId() and replace the below code

public function regenerateId()
    {
        if (headers_sent()) {
            return $this;
        }

        if ($this->isSessionExists()) {
            $oldSessionId = session_id();            
            session_regenerate_id();   //regen the session
            $new_session_id = session_id();

            $_SESSION['new_session_id'] = $new_session_id;

            // Set destroy timestamp
            $_SESSION['destroyed'] = time();

            // Write and close current session;
            session_commit();
            $oldSession = $_SESSION;   //called after destroy - see destroy!
            // Start session with new session ID
            session_id($new_session_id);
            ini_set('session.use_strict_mode', 0);
            session_start();
            ini_set('session.use_strict_mode', 1);
            $_SESSION = $oldSession;
            // New session does not need them
            unset($_SESSION['destroyed']);
            unset($_SESSION['new_session_id']);  
        } else {
            session_start();
        }
        $this->storage->init(isset($_SESSION) ? $_SESSION : []);

        if ($this->sessionConfig->getUseCookies()) {
            $this->clearSubDomainSessionCookie();
        }
        return $this;
    }

then search for start() and replace it with

 public function start()
    {
        if (!$this->isSessionExists()) {
            \Magento\Framework\Profiler::start('session_start');

            try {
                $this->appState->getAreaCode();
            } catch (\Magento\Framework\Exception\LocalizedException $e) {
                throw new \Magento\Framework\Exception\SessionException(
                    new \Magento\Framework\Phrase(
                        'Area code not set: Area code must be set before starting a session.'
                    ),
                    $e
                );
            }

            // Need to apply the config options so they can be ready by session_start
            $this->initIniOptions();
            $this->registerSaveHandler();
            if (isset($_SESSION['new_session_id'])) {
             // Not fully expired yet. Could be lost cookie by unstable network.
             session_commit();
             session_id($_SESSION['new_session_id']);
             }
            // potential custom logic for session id (ex. switching between hosts)
            $this->setSessionId($this->sidResolver->getSid($this));
            session_start();
            if (isset($_SESSION['destroyed'])) {
               if ($_SESSION['destroyed'] < time()-300) {
                   $this->destroy(['clear_storage' => true]);

               }
            }
            $this->validator->validate($this);

            register_shutdown_function([$this, 'writeClose']);

            $this->_addHost();
            \Magento\Framework\Profiler::stop('session_start');
        }
        $this->storage->init(isset($_SESSION) ? $_SESSION : []);
        return $this;
    }

Note:It worked for me and i got this solution from github #Tickect:12362 you can check for reference from the link.

0

After multiple updates we repeatly get these problems with customers hanging in re-login loop. To break out from this loop I did a little dirty customization in sidebar.js and proceed-to-checkout.js in [template]/Magento_Checkout/web/js:

            if (!customer().firstname) {
                var sections = ['cart', 'customer'];
                 customerData.invalidate(sections);
                 customerData.reload(sections, true);
            }

before:

if (!customer().firstname && cart().isGuestCheckoutAllowed === false) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.