CurrentCustomer
Magento\Customer\Helper\Session\CurrentCustomer
What it does
This helper class provides a unified way to access the current customer's data in Magento 2, with special handling for full page cache scenarios.
When the page cache is enabled, it returns a depersonalized customer object (containing only the customer group) to maintain cache effectiveness, while returning full customer data for AJAX requests or non-cached pages.
Developers use this class instead of directly accessing the customer session to ensure proper behavior with Magento's caching mechanisms.
Public Methods
- getCustomer()
- getCustomerId()
- setCustomerId()