Skip to content

Commit

Permalink
Merge pull request #3504 from rbayet/fix-3500-tracker-prevent-loss-of…
Browse files Browse the repository at this point in the history
…-vary-cookie

[Tracker] Fixes #3500 loss of X-Magento-Vary cookie
  • Loading branch information
rbayet authored Jan 30, 2025
2 parents 8736199 + 0fd2291 commit d01a1f7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteTracker
* @author Richard BAYET <[email protected]>
* @copyright 2025 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteTracker\Model\App\Response\Http;

use Magento\Framework\App\PageCache\NotCacheableInterface;
use Magento\Framework\App\Response\Http;

/**
* Custom Http Response object for the elasticsuite/tracker/hit legacy controller.
* Using this object instead of a classic Http response object
* - prevents \Magento\PageCache\Model\App\Response\HttpPlugin from being triggered in the first place
* - and if it was triggered, makes sure that the sendVary method is not called
* - which would result in the loss of the Vary cookie if the user is logged in.
*
* @category Smile
* @package Smile\ElasticsuiteTracker
*/
class TrackerResponse extends Http implements NotCacheableInterface
{
}
12 changes: 12 additions & 0 deletions src/module-elasticsuite-tracker/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@
<type name="Magento\Framework\Session\SessionStartChecker">
<plugin name="elasticsuite_tracker_disable_session" type="Smile\ElasticsuiteTracker\Plugin\SessionStartCheckerPlugin"/>
</type>
<!-- Prevent lack of session start to lead to an empty HttpContext and a removal of the Vary cookie by the FPC in h.png/pixel mode -->
<virtualType name="TrackerResponseContext"
type="Magento\Framework\App\Action\Context">
<arguments>
<argument name="response" xsi:type="object">Smile\ElasticsuiteTracker\Model\App\Response\Http\TrackerResponse</argument>
</arguments>
</virtualType>
<type name="Smile\ElasticsuiteTracker\Controller\Tracker\Hit">
<arguments>
<argument name="context" xsi:type="object">TrackerResponseContext</argument>
</arguments>
</type>

<!-- Example of extending the page map identifier -->
<type name="Smile\ElasticsuiteTracker\Model\Event\Processor\MapPageIdentifier">
Expand Down

0 comments on commit d01a1f7

Please sign in to comment.