diff --git a/Model/App/Request/Http/IdentifierForSave.php b/Model/App/Request/Http/IdentifierForSave.php index 26b8715..8a1213b 100644 --- a/Model/App/Request/Http/IdentifierForSave.php +++ b/Model/App/Request/Http/IdentifierForSave.php @@ -25,7 +25,8 @@ class IdentifierForSave implements IdentifierInterface public function __construct( private Http $request, private Context $context, - private Json $serializer + private Json $serializer, + private IdentifierStoreReader $identifierStoreReader ) { } @@ -42,6 +43,8 @@ class IdentifierForSave implements IdentifierInterface $this->context->getVaryString() ]; + $data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data); + return sha1($this->serializer->serialize($data)); } } diff --git a/etc/di.xml b/etc/di.xml index acaee4b..5685ed7 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -6,10 +6,6 @@ */ --> - - - diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 7f4d05a..3d9047a 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -31,4 +31,14 @@ Magento\PageCache\Model\App\Request\Http\IdentifierForSave + + + Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader + + + + + Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader + + diff --git a/Model/App/Request/Http/IdentifierStoreReader.php b/Model/App/Request/Http/IdentifierStoreReader.php new file mode 100644 index 0000000..b92ce65 --- /dev/null +++ b/Model/App/Request/Http/IdentifierStoreReader.php @@ -0,0 +1,67 @@ +designExceptions = $designExceptions; + $this->request = $request; + $this->config = $config; + } + + /** + * Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual + * + * @param \Magento\Framework\App\PageCache\Identifier $identifier + * @param string $result + * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getPageTagsWithStoreCacheTags($data): ?array + { + if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) { + $ruleDesignException = $this->designExceptions->getThemeByRequest($this->request); + if ($ruleDesignException !== false) { + $data['DESIGN'] = $ruleDesignException; + } + + if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) { + $data[StoreManager::PARAM_RUN_TYPE] = $runType; + } + + if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) { + $data[StoreManager::PARAM_RUN_CODE] = $runCode; + } + } + + return $data; + } +}