0

Scenario: In an integration in Magento 2 with Full Caching.

We have two types of customers Type 1 and Type 2. Both these types of customers are saved under same Customer Group we are distinguishing the customers based on a customer type attribute.

Customer of type 1 can belong to different departments (1 to many). When he first visits the site after login, he is redirected to select his department.

This value is saved in customer session, on run time customer can change his department that value is updated in the existing customer session.

When we access a new page we get the updated session, but if we access a page that was accessed earlier, we get the old data from session.

Options tried:

  • We tried to load the data from customer session factory instead of customer session, but still we are facing the issue. Our understanding is that data which is saved in customer object is loaded as new, but since our data is saved under customer session it is not returning the latest data.
  • For some section of the page we have used sections to load the data, but in that scenario also, if a page is accessed earlier the correct data is not loaded in first refresh, in second refresh the data is loaded properly.
  • We also tried to update the session data from AJAX, but that was also not much useful since that data is not getting loaded on the pages.
  • We also tried to use context variables, but when we log the data while saving the context variable the correct data is logged but when we try to fetch the context data, no data was returned. Also even if different context variable is set for each department, the page seems to be rendered from cache.
  • We can’t use Cookie since this is sensitive data, this will be the last option.

In Magento 1 we had an option to generate new Cache key by extending app\code\local\Enterprise\PageCache\Model\Processor.php,

Example

if (isset($_COOKIE[Enterprise_PageCache_Model_Cookie::IS_USER_ALLOWED_SAVE_COOKIE])) { $uri .= '_' . $_COOKIE[Enterprise_PageCache_Model_Cookie::IS_USER_ALLOWED_SAVE_COOKIE]; }

Is there any similar option available in Magento 2. If yes, please share some reference links to integrate the same.

Deepika Janiyani
  • 1,487
  • 9
  • 17

0 Answers0