0

I am facing this annoying issue in Magento 2.0.7 where, after checking out, the items are not cleared from the mine cart.

Those items in the mini cart are loading from the cache storage.

Is there any way we can clear that cache?

I checked the local storage in my browser, and it has data stored in "cart":{} parameter of the JSON string. Which if I manually clear, the mini cart gets empty.

  • @ Taral Patoliya Hope you can find solution the at magento.stackexchange.com/questions/100615/… – Krishna ijjada Jul 25 '16 at 7:13
  • @krishnaijjada There are only a handful of questions about the above issue, and the question you mensioned above is one of them. but they could not solve the issue. – Taral Patoliya Jul 25 '16 at 7:16
  • Should check the latest version. This issue has been fixed. See my answer. – Khoa TruongDinh Jul 26 '16 at 13:14
7

There is a temporary solution for you, we need to override vendor/magento/module-checkout/view/frontend/web/js/view/payment/default.js because if we take a look at this file, we can see:

        /**
         * After place order callback
         */
        afterPlaceOrder: function () {
            // Override this function and put after place order logic here
        },

We will write the code to remove local storegare here.

We can read more here: Getting the product SKU in the header mini-cart to understand more about the mini cart data.

Note: we should find the root cause of your issue.

UPDATE: 26-Jul-16

A fix from Magento Community here.

app/code/Magento/Checkout/Model/Session.php

         $this->_quote = null;
          $this->setQuoteId(null);
          $this->setLastSuccessQuoteId(null);
 +        $this->setLoadInactive(false);
 +        $this->replaceQuote($this->getQuote()->save());
          return $this;
      }

app/code/Magento/Checkout/view/frontend/templates/success.phtml

          <a class="action primary continue" href="<?php /* @escapeNotVerified */ echo $block->getUrl() ?>"><span><?php /* @escapeNotVerified */ echo __('Continue Shopping') ?></span></a>
          </div>
      </div>
 +    <script>
 +        require([
 +            'Magento_Customer/js/customer-data'
 +        ], function (customerData) {
 +            var sections = ['cart'];
 +            customerData.invalidate(sections);
 +            customerData.reload(sections, true);
 +        });
 +    </script>
  </div>
  • This works when user already signed in. still getting the problem when guest user placing order, any solutions for guest user? – Vishwa Feb 14 '18 at 6:24
0
$metadata = $this->_cookieMetadataFactory
    ->createPublicCookieMetadata()
    ->setPath('/');
$sectiondata = json_decode($this->_cookieManager->getCookie('section_data_ids'));
$sectiondata->cart += 1000;
$this->_cookieManager->setPublicCookie(
    'section_data_ids',
    json_encode($sectiondata),
    $metadata
);

use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;

CookieManagerInterface $cookieManager,
CookieMetadataFactory $cookieMetadataFactory,
0

Please add below small script in following file path. it's work for me.

app/design/frontend/<Vendor>/<theme>/Magento_Checkout/templates/cart/noItems.phtml

app/design/frontend/<Vendor>/<theme>/Magento_Checkout/templates/success.phtml

<script>
require([
     'Magento_Customer/js/customer-data'
 ], function (customerData) {
     var sections = ['cart'];
     customerData.invalidate(sections);
     //customerData.reload(sections, true);
 });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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