The problem is even when i disable the "persistent checkout", it still work as normal.
Its a magento default module, so i think this is a magento 2 bug. enter image description here

After a day working on this, i still don't know how this work. I mean i guess they use cookie or session to store the cart after customer log out.
Then after guest login, they will use that session or cookie to update the cart.
But i don't know how they do that.

The module is "module-persistent" (default magento module).

  • have you clean the configuration cache? Commented Jan 21, 2019 at 14:24
  • Yes i did serveral time, as i said, i was working on this all day long, so the first thing i have thinking of is "clear cache" :D
    – fudu
    Commented Jan 21, 2019 at 14:34

1 Answer 1


Well, so after a day looking for solution, i've found something.
But this is only a temporary solution.
So here is the idea:
We override the magento/customer/account/logout by plugin, then we will truncate the cart.


<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Controller\Account\Logout">
        <plugin name="remove_cart_before_logout" type="Fudu\Customer\Plugin\Controller\Account\Logout" sortOrder="1" />


namespace Fudu\Customer\Plugin\Controller\Account;

use Magento\Customer\Controller\Account\Logout as CustomerLogout;

class Logout
    public function __construct(
        \Magento\Checkout\Model\Session $session,
        \Magento\Checkout\Model\Cart $cart,
        \Magento\Persistent\Helper\Data $persistentData
        $this->_session = $session;
        $this->cart = $cart;
        $this->persistentData = $persistentData;

    public function beforeExecute(CustomerLogout $subject)

Also, we have to override this file too, in case customer doesn't logout, they close the tab and open a private browser:


<?xml version="1.0"?>
    <preference for="Magento\Checkout\Model\Session" type="Gssi\Checkout\Model\Session" />


public function loadCustomerQuote()
        if (!$this->_customerSession->getCustomerId()) {
            return $this;

        // put this in, and everything is still the same.
            return $this;

        $this->_eventManager->dispatch('load_customer_quote_before', ['checkout_session' => $this]);

        try {
            $customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
            $customerQuote = $this->quoteFactory->create();

        if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
            if ($this->getQuoteId()) {


            if ($this->_quote) {
            $this->_quote = $customerQuote;
        } else {
        return $this;

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.