diff --git a/src/Model/Catalog/Layer/Url/RewriteResolver/LandingPageResolver.php b/src/Model/Catalog/Layer/Url/RewriteResolver/LandingPageResolver.php index c566f3f..2617482 100644 --- a/src/Model/Catalog/Layer/Url/RewriteResolver/LandingPageResolver.php +++ b/src/Model/Catalog/Layer/Url/RewriteResolver/LandingPageResolver.php @@ -60,6 +60,9 @@ public function __construct( /** * @inheritDoc + * + * phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedCatch + * phpcs:disable Generic.CodeAnalysis.EmptyStatement.DetectedCatch */ public function getRewrites(MagentoHttpRequest $request): array { @@ -107,6 +110,7 @@ protected function getPossibleLandingPagePaths(string $fullUriPath): array $lastPathPart .= '/' . $pathPart; $paths[] = $lastPathPart; } + $paths = array_reverse($paths); if (!$this->attributeLandingConfig->isAppendCategoryUrlSuffix()) { diff --git a/src/Model/FilterApplier/TweakwiseFilterApplier.php b/src/Model/FilterApplier/TweakwiseFilterApplier.php index aef1dce..87a4166 100644 --- a/src/Model/FilterApplier/TweakwiseFilterApplier.php +++ b/src/Model/FilterApplier/TweakwiseFilterApplier.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -40,11 +41,13 @@ public function applyFilters(LandingPageInterface $page) $navigationRequest->addAttributeFilter($filter->getFacet(), $filter->getValue()); } - if ($filterTemplateId = $page->getTweakwiseFilterTemplate()) { + $filterTemplateId = $page->getTweakwiseFilterTemplate(); + if ($filterTemplateId) { $navigationRequest->setTemplateId($filterTemplateId); } - if ($sortTemplateId = $page->getTweakwiseSortTemplate()) { + $sortTemplateId = $page->getTweakwiseSortTemplate(); + if ($sortTemplateId) { $navigationRequest->setSortTemplateId($sortTemplateId); } } diff --git a/src/Model/FilterFormInputProvider/LandingPageInputProvider.php b/src/Model/FilterFormInputProvider/LandingPageInputProvider.php index 0ab0e3f..7609319 100644 --- a/src/Model/FilterFormInputProvider/LandingPageInputProvider.php +++ b/src/Model/FilterFormInputProvider/LandingPageInputProvider.php @@ -4,6 +4,7 @@ * @author : Edwin Jacobs, email: ejacobs@emico.nl. * @copyright : Copyright Emico B.V. 2020. */ + namespace Tweakwise\AttributeLandingTweakwise\Model\FilterFormInputProvider; use Emico\AttributeLanding\Api\Data\LandingPageInterface; @@ -114,7 +115,7 @@ protected function getPage(): LandingPageInterface /** * @return string */ - public function getOriginalUrl() : string + public function getOriginalUrl(): string { return $this->layerUrl->getUrlStrategy()->getOriginalUrl($this->request); } diff --git a/src/Model/FilterHider/TweakwiseFilterHider.php b/src/Model/FilterHider/TweakwiseFilterHider.php index 6f811a9..3537329 100644 --- a/src/Model/FilterHider/TweakwiseFilterHider.php +++ b/src/Model/FilterHider/TweakwiseFilterHider.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -26,8 +27,7 @@ public function shouldHideFilter( LandingPageInterface $landingPage, FilterInterface $filter, Item $filterItem = null - ): bool - { + ): bool { if (!$filter instanceof TweakwiseFilter) { return false; } diff --git a/src/Model/FilterManager.php b/src/Model/FilterManager.php index 1fb74ed..a3fa65c 100644 --- a/src/Model/FilterManager.php +++ b/src/Model/FilterManager.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -92,7 +93,8 @@ static function (Item $item) { SORT_REGULAR ); - if ($url = $this->urlFinder->findUrlByFilters($filters, $layer->getCurrentCategory()->getEntityId())) { + $url = $this->urlFinder->findUrlByFilters($filters, $layer->getCurrentCategory()->getEntityId()); + if ($url) { return $url; } @@ -104,7 +106,8 @@ static function (Item $item) { */ public function getLandingsPageFilters() { - if (!$landingsPage = $this->landingPageContext->getLandingPage()) { + $landingsPage = $this->landingPageContext->getLandingPage(); + if (!$landingsPage) { return []; } @@ -122,18 +125,23 @@ public function getActiveFiltersExcludingLandingPageFilters(): array if ($landingPage === null) { return $filters; } + /** @var string|int $index */ foreach ($filters as $index => $filterItem) { - if ($this->filterHider->shouldHideFilter( - $landingPage, - $filterItem->getFilter(), - $filterItem - )) { + if ( + $this->filterHider->shouldHideFilter( + $landingPage, + $filterItem->getFilter(), + $filterItem + ) + ) { unset($filters[$index]); } } + $this->activeFiltersExcludingLandingPageFilters = $filters; } + return $this->activeFiltersExcludingLandingPageFilters; } @@ -150,15 +158,19 @@ public function getAllActiveFilters(): array if (!\is_array($filterItems)) { return []; } + // Do not consider category as active - $filterItems = \array_filter($filterItems, function (Item $filter) { - $source = $filter + $filterItems = \array_filter( + $filterItems, + function (Item $filter) { + $source = $filter ->getFilter() ->getFacet() ->getFacetSettings() ->getSource(); - return $source !== SettingsType::SOURCE_CATEGORY; - }); + return $source !== SettingsType::SOURCE_CATEGORY; + } + ); $this->activeFilters = $filterItems; return $this->activeFilters; } @@ -186,6 +198,7 @@ public function isFilterAvailableOnLandingPage(LandingPageInterface $landingPage return true; } } + return false; } } diff --git a/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php b/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php index 257c7a1..5979221 100644 --- a/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php +++ b/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php @@ -8,7 +8,6 @@ /** * Class DefaultRendererPlugin - * @package Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered */ class RendererPlugin { @@ -27,7 +26,7 @@ public function __construct(FilterManager $filterManager) } /** - * @param Template $renderer used Template here as this class is subscribed multiple times as a plugin + * @param Template $renderer * @param string $result * @param Item $filterItem * @return string diff --git a/src/Plugin/Model/AjaxNavigationResultPlugin.php b/src/Plugin/Model/AjaxNavigationResultPlugin.php index 2779f80..339017a 100644 --- a/src/Plugin/Model/AjaxNavigationResultPlugin.php +++ b/src/Plugin/Model/AjaxNavigationResultPlugin.php @@ -51,16 +51,17 @@ public function __construct( $this->url = $url; } - public function aroundGetResponseUrl(AjaxNavigationResult $ajaxNavigationResult, callable $proceed) { - $type = $this->request->getParam('__tw_ajax_type'); + public function aroundGetResponseUrl(AjaxNavigationResult $ajaxNavigationResult, callable $proceed) + { + $type = $this->request->getParam('__tw_ajax_type'); if ($type === 'landingpage' && $this->landingPageContext->getLandingPage()) { $filters = $this->filterManager->getActiveFiltersExcludingLandingPageFilters(); $url = $this->url->getFilterUrl($filters); return $url; - } + } - return $proceed(); + return $proceed(); } } diff --git a/src/Plugin/PathSlugStrategyPlugin.php b/src/Plugin/PathSlugStrategyPlugin.php index 75d28fb..0ae4114 100644 --- a/src/Plugin/PathSlugStrategyPlugin.php +++ b/src/Plugin/PathSlugStrategyPlugin.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -41,7 +42,7 @@ class PathSlugStrategyPlugin * @param LandingPageContext $landingPageContext * @param FilterManager $filterManager * @param UrlFactory $urlFactory - * @param Url $magentoUrl + * @param FilterSlugManager $filterSlugManager */ public function __construct( LandingPageContext $landingPageContext, @@ -133,11 +134,13 @@ public function aroundGetAttributeRemoveUrl( } else { $filters = $this->filterManager->getAllActiveFilters(); } + foreach ($filters as $key => $activeItem) { if ($activeItem === $item) { unset($filters[$key]); } } + return $pathSlugStrategy->buildFilterUrl($request, $filters); } @@ -186,7 +189,8 @@ public function afterGetCategoryFilterSelectUrl( } /** - * @deprecated + * @param PathSlugStrategy $original + * @param string $result * @param MagentoHttpRequest $request * @return string */ diff --git a/src/Plugin/QueryParameterStrategyPlugin.php b/src/Plugin/QueryParameterStrategyPlugin.php index b325de4..4b3ed3b 100644 --- a/src/Plugin/QueryParameterStrategyPlugin.php +++ b/src/Plugin/QueryParameterStrategyPlugin.php @@ -4,6 +4,7 @@ * @author : Edwin Jacobs, email: ejacobs@emico.nl. * @copyright : Copyright Emico B.V. 2020. */ + namespace Tweakwise\AttributeLandingTweakwise\Plugin; use Emico\AttributeLanding\Model\LandingPageContext; @@ -55,6 +56,8 @@ public function __construct( * @param QueryParameterStrategy $original * @param string $result * @return string + * + * phpcs:disable Magento2.Functions.DiscouragedFunction.Discouraged */ public function afterGetCategoryFilterSelectUrl( QueryParameterStrategy $original, @@ -98,8 +101,11 @@ public function afterGetCategoryFilterSelectUrl( /** * {@inheritdoc} */ - public function afterGetAttributeFilters(QueryParameterStrategy $original, array $result, MagentoHttpRequest $request) - { + public function afterGetAttributeFilters( + QueryParameterStrategy $original, + array $result, + MagentoHttpRequest $request + ) { $landingPage = $this->landingPageContext->getLandingPage(); if ($landingPage === null) { return $result; @@ -112,7 +118,7 @@ public function afterGetAttributeFilters(QueryParameterStrategy $original, array if (isset($result[$filter->getFacet()])) { foreach ($result[$filter->getFacet()] as $key => $value) { if ($value == $filter->getValue()) { - unset ($result[$filter->getFacet()][$key]); + unset($result[$filter->getFacet()][$key]); } } } diff --git a/src/Plugin/Seo/FilterHelperPlugin.php b/src/Plugin/Seo/FilterHelperPlugin.php index b19e72f..0e1b4e7 100644 --- a/src/Plugin/Seo/FilterHelperPlugin.php +++ b/src/Plugin/Seo/FilterHelperPlugin.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -43,11 +44,13 @@ public function __construct( */ public function aroundShouldPageBeIndexable(FilterHelper $helper, callable $proceed): bool { - if ($this->landingPageContext->isOnLandingPage() && + if ( + $this->landingPageContext->isOnLandingPage() && \count($this->filterManager->getActiveFiltersExcludingLandingPageFilters()) === 0 ) { return true; } + return $proceed(); } @@ -61,6 +64,7 @@ public function aroundGetActiveFilterItems(FilterHelper $helper, callable $proce if ($this->landingPageContext->isOnLandingPage()) { return $this->filterManager->getActiveFiltersExcludingLandingPageFilters(); } + return $proceed(); } diff --git a/src/Plugin/UrlPlugin.php b/src/Plugin/UrlPlugin.php index ac40f9c..48d7fe9 100644 --- a/src/Plugin/UrlPlugin.php +++ b/src/Plugin/UrlPlugin.php @@ -1,4 +1,5 @@ * @copyright (c) Emico B.V. 2017 @@ -78,7 +79,8 @@ public function aroundGetSelectFilter(Url $subject, Closure $proceed, Item $filt return $proceed($filterItem); } - if ($url = $this->filterManager->findLandingPageUrlForFilterItem($filterItem)) { + $url = $this->filterManager->findLandingPageUrlForFilterItem($filterItem); + if ($url) { return '/' . $url; } diff --git a/src/registration.php b/src/registration.php index 86e3b5e..69acde7 100644 --- a/src/registration.php +++ b/src/registration.php @@ -1,4 +1,5 @@