Magento 2 Price Discrepancy: Why Logged-in Customers See Guest Prices (FPC Bug Fix)
Accurate pricing is the bedrock of any successful e-commerce store. For Magento 2 merchants, especially those leveraging customer group-specific pricing, ensuring that the correct price is displayed to the right customer at all times is paramount. However, a recent GitHub issue (#40474) brought to light a critical bug affecting Magento 2.4.8-p3 that could lead to logged-in customers seeing guest user prices on Product Detail Pages (PDP) and Product Listing Pages (PLP) due to an interaction with the Full Page Cache (FPC).
The Silent Threat: Guest Prices Persisting for Logged-in Users
Imagine a loyal customer, part of a special customer group, logging into your Magento store expecting to see their exclusive discounted prices. Instead, they are greeted with the standard guest prices on product pages. This isn't just a minor glitch; it's a significant user experience breakdown that can erode trust, lead to abandoned carts, and directly impact your conversion rates. The correct customer group price only appears much later, typically when the product is added to the cart, creating confusion and frustration.
This issue, specifically observed in Magento Open Source and Adobe Commerce 2.4.8-p3 running in production mode with the built-in FPC enabled, highlights a subtle but impactful flaw in how Magento handles cached content for different user segments. For businesses relying on tiered pricing, B2B models, or loyalty programs, this bug can severely undermine their sales strategy.
Unpacking the Technical Root Cause: FPC and Identifier Mismatch
The core of the problem, as meticulously investigated by the issue author ioweb-gr, lies in how Magento's FPC identifies and serves cached pages. The expectation is that FPC should vary content based on crucial factors like the X-Magento-Vary cookie and the user's HTTP context, ensuring that different customer segments (e.g., guests vs. logged-in users with specific group prices) receive appropriately cached content.
However, the investigation revealed a critical misconfiguration in the dependency injection (DI) preferences within the module-page-cache:
- The
Magento\Framework\App\PageCache\IdentifierInterfacepreference was incorrectly pointing toMagento\PageCache\Model\App\Request\Http\IdentifierForSave. - This
IdentifierForSaveclass, when an FPC hit occurred, was found to be empty. This meant it wasn't correctly leveraging theHttpContextor reading the vary cookie. - Consequently, the FPC was using an incorrect cache key, leading to cached guest prices being served to logged-in users, completely bypassing their customer group-specific pricing.
This behavior is particularly insidious because it doesn't manifest until a user logs in, and even then, only on pages served by the FPC. The moment a product is added to the cart, the cart logic correctly applies the customer group price, further confusing the user who might wonder why the price suddenly changed.
The Solution: Reverting to the Correct Identifier
The fix, as proposed and implemented by the community, involves a straightforward but critical adjustment to the di.xml configuration within the module-page-cache. The problematic preference needs to be reverted to its original, correct implementation:
Index: etc/di.xml
--- a/etc/di.xml
+++ b/etc/di.xml (date 1769703123582)
@@ -44,5 +44,5 @@
-
+
By changing the preference for Magento\Framework\App\PageCache\IdentifierInterface from Magento\PageCache\Model\App\Request\Http\IdentifierForSave back to Magento\Framework\App\PageCache\Identifier, we ensure that Magento's FPC correctly utilizes the HTTP context and the vary cookie to generate unique cache keys for different customer segments. This allows the system to serve the appropriate cached content, immediately reflecting the correct customer group price upon login.
The issue author noted that this IdentifierForSave preference was a relatively recent introduction, causing the regression in later versions like 2.4.8-p3. This underscores the importance of thorough testing during Magento upgrades and the need to monitor community channels for such critical bug reports.
Implementing the Fix and Best Practices
If your Magento 2.4.8-p3 store is experiencing this issue, here's how you can address it:
- Verify Your Version: Confirm you are running Magento Open Source or Adobe Commerce 2.4.8-p3. While the issue was not reproducible on the latest 2.4-develop branch by the Magento team, it's crucial to address it for the affected version.
- Create a Custom Module: The safest way to apply this fix is by creating a small custom Magento module that overrides this specific preference in its own
di.xml. This prevents direct modification of core files, which is a cardinal rule in Magento development. - Apply the Preference Change: Within your custom module's
etc/di.xml, add the following preference: - Clear Cache and Recompile: After implementing the change, run
php bin/magento cache:clean,php bin/magento cache:flush, andphp bin/magento setup:di:compileto ensure the changes are picked up. - Thorough Testing: Always test such changes rigorously in a staging environment before deploying to production. Verify guest pricing, logged-in customer group pricing, and ensure no other FPC-related issues arise.
For merchants considering a Magento upgrade or migration, issues like this highlight the complexities involved. At Shopping Mover, we specialize in seamless Magento migrations and upgrades, ensuring that your platform is not only up-to-date but also free from critical bugs that can impact your business. Our expertise in Magento development and integrations means we can proactively identify and resolve such issues, providing a stable and high-performing e-commerce environment.
Conclusion
The Magento 2.4.8-p3 FPC price bug for customer groups is a prime example of how a seemingly minor configuration oversight can lead to significant business challenges. By understanding the technical root cause – an incorrect DI preference for the page cache identifier – and applying the targeted fix, merchants can restore accurate pricing displays for their logged-in customers.
Staying informed about community-reported issues, maintaining a robust testing strategy, and partnering with experienced Magento development teams are crucial for long-term e-commerce success. Don't let pricing discrepancies deter your customers; ensure your Magento store delivers a flawless and trustworthy shopping experience.