diff --git a/src/Plugin/Block/Product/ListProduct.php b/src/Plugin/Block/Product/ListProduct.php new file mode 100644 index 0000000..e7d9caf --- /dev/null +++ b/src/Plugin/Block/Product/ListProduct.php @@ -0,0 +1,78 @@ +request->getParam('id'); + if ( + !$this->isAttributeLandingRequest() || + !$landingPageId || + !$this->cacheHelper->personalMerchandisingCanBeApplied() || + $route !== 'page_cache/block/esi' + ) { + return [$route, $params]; + } + + try { + $landingPage = $this->landingPageRepository->getById($landingPageId); + } catch (NoSuchEntityException | LocalizedException $e) { + return [$route, $params]; + } + + $filters = $landingPage->getFilters(); + $filterTemplate = $landingPage->getTweakwiseFilterTemplate(); + $sortTemplate = $landingPage->getTweakwiseSortTemplate(); + + foreach ($filters as $filter) { + $params['_query'][$filter->getFacet()] = $filter->getValue(); + } + + if (!empty($filterTemplate)) { + $params['_query']['tn_ft'] = $filterTemplate; + } + + if (!empty($sortTemplate)) { + $params['_query']['tn_st'] = $sortTemplate; + } + + return [$route, $params]; + } + + /** + * @return bool + */ + private function isAttributeLandingRequest(): bool + { + return $this->request->getModuleName() === 'emico_attributelanding'; + } +} diff --git a/src/etc/di.xml b/src/etc/di.xml index 455f574..ac7fa49 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -64,4 +64,8 @@ type="Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered\RendererPlugin"/> + + +