Magento 2.4.9 Persistent Cart Bug: Why 'Remember Me' Isn't Always Remembering

Magento 2.4.9 Persistent Cart Bug: Why "Remember Me" Isn't Always Remembering

The persistent shopping cart feature is a cornerstone of a seamless e-commerce experience, allowing customers to return to their carts even after their session expires. However, a recently reported issue on Magento 2's GitHub (Issue #41634) highlights a significant regression in Magento Open Source 2.4.9 that could be silently undermining customer retention and conversion rates.

The Core Problem: Unexpected Cart Clearance

Reported by yauhenirybachenka-byte, the issue describes a scenario where the persistent cart cookie, and consequently the persistent session, is unexpectedly cleared. This happens when the standard PHP session (PHPSESSID) expires, even if the "Remember Me" option was selected during login and the persistent_shopping_cart cookie remains intact. This behavior deviates from the expected functionality, where only an explicit sign-out should clear the persistent cart.

Steps to Reproduce the Regression

The reporter provided clear steps to replicate this bug, making it easy for developers to confirm its presence in their environments:

  1. Ensure a clean Magento Open Source 2.4.9 installation with the module-persistent version 100.4.9.
  2. Configure the Persistent Shopping Cart settings: Enable = Yes, Remember Me = Yes (default checked), Persist Shopping Cart = Yes, Clear Persistence on Sign Out = Yes (default).
  3. Set web/cookie/cookie_lifetime to a short duration (e.g., 120 seconds) to quickly trigger session expiry.
  4. Log in as a customer, ensuring "Remember Me" is checked, and add a product to the cart.
  5. Allow the PHPSESSID to expire (or manually delete it), while keeping the persistent_shopping_cart cookie.

The expected outcome is that the persistent cart should be restored upon revisiting the site. However, the actual result is that the persistent_shopping_cart cookie is deleted, and the persistent session is unset.

Unmasking the Culprit: A Code Path Analysis

The issue description goes further, identifying the specific code path responsible for this unwanted behavior. The Persistent\Model\Session->removePersistentCookie method is invoked, leading to the removal of the persistent cookie. This call originates from within the Persistent\Observer\SetCheckoutSessionPersistentDataObserver->execute observer, which is triggered by the custom_quote_process event. This event, in turn, is dispatched when methods like Checkout\Model\Session->getQuote or Checkout\CustomerData\Cart->getQuote are called – essentially, any action that attempts to load the customer's quote.

Persistent\Model\Session->removePersistentCookie
Persistent\Observer\SetCheckoutSessionPersistentDataObserver->execute:88
Event\Manager->dispatch              // custom_quote_process
Checkout\Model\Session->getQuote
Checkout\CustomerData\Cart->getQuote // customer/section/load

This detailed breakdown is invaluable for developers attempting to debug or implement a temporary workaround for this S2 severity bug. The fact that it's labeled as a regression from version 2.4.6 suggests a change in the core module-persistent module between these versions introduced this flaw.

Impact on Merchants and Developers

For e-commerce merchants, this bug directly translates to a degraded customer experience and potential loss of sales. Customers who expect their carts to be remembered might abandon their shopping journey if their items disappear unexpectedly. For developers, this issue highlights the complexities of managing session and cookie persistence in Magento 2, especially across different versions. While no immediate solution or workaround was provided within the original issue comments (as of this writing), understanding the exact trigger and code path is the first step towards mitigation.

This issue underscores the importance of thorough testing, particularly for core features like persistent carts, during Magento 2 upgrades or migrations. As Magento continues to evolve, staying informed about such regressions is crucial for maintaining stable and high-performing e-commerce platforms.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools