From 9fbbe54f1a31ec80c585d97aa5a2df858bcfcb38 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:27:08 +0200 Subject: [PATCH 1/6] fix: ALP varnish bug --- src/Block/Product/ListProduct.php | 88 +++++++++++++++++++++++++++++++ src/etc/di.xml | 1 + 2 files changed, 89 insertions(+) create mode 100644 src/Block/Product/ListProduct.php diff --git a/src/Block/Product/ListProduct.php b/src/Block/Product/ListProduct.php new file mode 100644 index 0000000..221425b --- /dev/null +++ b/src/Block/Product/ListProduct.php @@ -0,0 +1,88 @@ +request->getModuleName() === 'emico_attributelanding') { + $landingPageId = (int)$this->request->getParam('id'); + if (!empty($landingPageId)) { + $landingPage = $this->landingPageRepository->getById($landingPageId); + $filters = $this->registry->registry('tw_filters' . $landingPageId); + $filterTemplate = $landingPage->getTweakwiseFilterTemplate(); + $sortTemplate = $landingPage->getTweakwiseSortTemplate(); + + foreach ($filters as $filter) { + $queryParams[$filter->getFacet()] = $filter->getValue(); + } + + if (!empty($filterTemplate)) { + $queryParams['tn_ft'] = $filterTemplate; + } + + if (!empty($sortTemplate)) { + $queryParams['tn_st'] = $sortTemplate; + } + } + } + + return parent::getUrl($route, $params, $queryParams); + } +} diff --git a/src/etc/di.xml b/src/etc/di.xml index 455f574..17b038b 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -1,6 +1,7 @@ + From dc172bfbe5eb098846693f9c09f11a2255d79bc9 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:35:45 +0200 Subject: [PATCH 2/6] Style fix --- src/Block/Product/ListProduct.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Block/Product/ListProduct.php b/src/Block/Product/ListProduct.php index 221425b..9594251 100644 --- a/src/Block/Product/ListProduct.php +++ b/src/Block/Product/ListProduct.php @@ -58,7 +58,6 @@ public function __construct( * @param array $params * @return string */ - public function getUrl($route = '', $params = [], $queryParams = []) { if ($this->request->getModuleName() === 'emico_attributelanding') { From bbfc9b563705bb7fdc868f1ed98fc54b99422c7c Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:26:57 +0200 Subject: [PATCH 3/6] Update ListProduct.php --- src/Block/Product/ListProduct.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Block/Product/ListProduct.php b/src/Block/Product/ListProduct.php index 9594251..41d018d 100644 --- a/src/Block/Product/ListProduct.php +++ b/src/Block/Product/ListProduct.php @@ -64,7 +64,7 @@ public function getUrl($route = '', $params = [], $queryParams = []) $landingPageId = (int)$this->request->getParam('id'); if (!empty($landingPageId)) { $landingPage = $this->landingPageRepository->getById($landingPageId); - $filters = $this->registry->registry('tw_filters' . $landingPageId); + $filters = $this->registry->registry('alp_filters' . $landingPageId); $filterTemplate = $landingPage->getTweakwiseFilterTemplate(); $sortTemplate = $landingPage->getTweakwiseSortTemplate(); From c399c9d6bcaec8dd26d2cea50253b977f9439af8 Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 25 Oct 2024 14:13:17 +0200 Subject: [PATCH 4/6] Use plugin instead of preference --- src/Block/Product/ListProduct.php | 87 ------------------------ src/Plugin/Block/Product/ListProduct.php | 78 +++++++++++++++++++++ src/etc/di.xml | 5 +- 3 files changed, 82 insertions(+), 88 deletions(-) delete mode 100644 src/Block/Product/ListProduct.php create mode 100644 src/Plugin/Block/Product/ListProduct.php diff --git a/src/Block/Product/ListProduct.php b/src/Block/Product/ListProduct.php deleted file mode 100644 index 41d018d..0000000 --- a/src/Block/Product/ListProduct.php +++ /dev/null @@ -1,87 +0,0 @@ -request->getModuleName() === 'emico_attributelanding') { - $landingPageId = (int)$this->request->getParam('id'); - if (!empty($landingPageId)) { - $landingPage = $this->landingPageRepository->getById($landingPageId); - $filters = $this->registry->registry('alp_filters' . $landingPageId); - $filterTemplate = $landingPage->getTweakwiseFilterTemplate(); - $sortTemplate = $landingPage->getTweakwiseSortTemplate(); - - foreach ($filters as $filter) { - $queryParams[$filter->getFacet()] = $filter->getValue(); - } - - if (!empty($filterTemplate)) { - $queryParams['tn_ft'] = $filterTemplate; - } - - if (!empty($sortTemplate)) { - $queryParams['tn_st'] = $sortTemplate; - } - } - } - - return parent::getUrl($route, $params, $queryParams); - } -} diff --git a/src/Plugin/Block/Product/ListProduct.php b/src/Plugin/Block/Product/ListProduct.php new file mode 100644 index 0000000..88b9fa5 --- /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 = $this->registry->registry(sprintf('alp_filters_%s', $landingPageId)) ?? []; + $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]; + } + + private function isAttributeLandingRequest(): bool + { + return $this->request->getModuleName() === 'emico_attributelanding'; + } +} diff --git a/src/etc/di.xml b/src/etc/di.xml index 17b038b..ac7fa49 100644 --- a/src/etc/di.xml +++ b/src/etc/di.xml @@ -1,7 +1,6 @@ - @@ -65,4 +64,8 @@ type="Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered\RendererPlugin"/> + + + From b8715e0974b409d5d8e76720c70d8b65d81d05ce Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 25 Oct 2024 14:14:13 +0200 Subject: [PATCH 5/6] Added phpdoc --- src/Plugin/Block/Product/ListProduct.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Plugin/Block/Product/ListProduct.php b/src/Plugin/Block/Product/ListProduct.php index 88b9fa5..cc89f30 100644 --- a/src/Plugin/Block/Product/ListProduct.php +++ b/src/Plugin/Block/Product/ListProduct.php @@ -71,6 +71,9 @@ public function beforeGetUrl(Subject $subject, $route = '', $params = []) return [$route, $params]; } + /** + * @return bool + */ private function isAttributeLandingRequest(): bool { return $this->request->getModuleName() === 'emico_attributelanding'; From 5d25581aae43b802dc4308c9d15784c8c72816fc Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 1 Nov 2024 08:47:03 +0100 Subject: [PATCH 6/6] Get filters from landing page instead of registry --- src/Plugin/Block/Product/ListProduct.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Plugin/Block/Product/ListProduct.php b/src/Plugin/Block/Product/ListProduct.php index cc89f30..e7d9caf 100644 --- a/src/Plugin/Block/Product/ListProduct.php +++ b/src/Plugin/Block/Product/ListProduct.php @@ -8,7 +8,6 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Framework\Registry; use Tweakwise\Magento2Tweakwise\Block\Product\ListProduct as Subject; use Tweakwise\Magento2Tweakwise\Helper\Cache; @@ -18,13 +17,11 @@ class ListProduct * @param RequestInterface $request * @param Cache $cacheHelper * @param LandingPageRepositoryInterface $landingPageRepository - * @param Registry $registry */ public function __construct( private readonly RequestInterface $request, private readonly Cache $cacheHelper, - private readonly LandingPageRepositoryInterface $landingPageRepository, - private readonly Registry $registry + private readonly LandingPageRepositoryInterface $landingPageRepository ) { } @@ -52,7 +49,7 @@ public function beforeGetUrl(Subject $subject, $route = '', $params = []) return [$route, $params]; } - $filters = $this->registry->registry(sprintf('alp_filters_%s', $landingPageId)) ?? []; + $filters = $landingPage->getFilters(); $filterTemplate = $landingPage->getTweakwiseFilterTemplate(); $sortTemplate = $landingPage->getTweakwiseSortTemplate();