diff --git a/composer.json b/composer.json index 793d82c..2293a22 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Provides compatibility between Attribute landing module and Tweakwise module.", "license": "OSL-3.0", "require": { - "php": "^8.0", + "php": "^8.1", "tweakwise/magento2-tweakwise": ">=5.7.4", "emico/m2-attributelanding": ">=4.1" }, diff --git a/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php b/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php index 5979221..8ddad8e 100644 --- a/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php +++ b/src/Plugin/Block/LayeredNavigation/RenderLayered/RendererPlugin.php @@ -2,6 +2,7 @@ namespace Tweakwise\AttributeLandingTweakwise\Plugin\Block\LayeredNavigation\RenderLayered; +use Emico\AttributeLanding\Model\LandingPageContext; use Tweakwise\AttributeLandingTweakwise\Model\FilterManager; use Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\Filter\Item; use Magento\Framework\View\Element\Template; @@ -16,13 +17,19 @@ class RendererPlugin */ protected $filterManager; + /** + * @var LandingPageContext + */ + protected $landingPageContext; + /** * DefaultRendererPlugin constructor. * @param FilterManager $filterManager */ - public function __construct(FilterManager $filterManager) + public function __construct(FilterManager $filterManager, LandingPageContext $landingPageContext) { $this->filterManager = $filterManager; + $this->landingPageContext = $landingPageContext; } /** @@ -36,7 +43,18 @@ public function afterRenderAnchorHtmlTagAttributes( string $result, Item $filterItem ) { - if (!$this->filterManager->findLandingPageUrlForFilterItem($filterItem)) { + + $returnToDefaultPage = false; + + $landingPage = $this->landingPageContext->getLandingPage(); + if ($landingPage) { + $landingPageUrl = $landingPage->getUrlPath(); + if (stripos($result, $landingPageUrl) === false) { + $returnToDefaultPage = true; + } + } + + if (!$this->filterManager->findLandingPageUrlForFilterItem($filterItem) && !$returnToDefaultPage) { return $result; } diff --git a/src/Plugin/PathSlugStrategyPlugin.php b/src/Plugin/PathSlugStrategyPlugin.php index 0ae4114..823713e 100644 --- a/src/Plugin/PathSlugStrategyPlugin.php +++ b/src/Plugin/PathSlugStrategyPlugin.php @@ -196,6 +196,15 @@ public function afterGetCategoryFilterSelectUrl( */ public function afterGetOriginalUrl(PathSlugStrategy $original, string $result, MagentoHttpRequest $request): string { - return $result; + $landingPage = $this->landingPageContext->getLandingPage(); + if ($landingPage === null) { + return $result; + } + + if (strpos($result, $landingPage->getUrlPath()) !== false) { + return $result; + } + + return $landingPage->getUrlPath(); } } diff --git a/src/Plugin/UrlPlugin.php b/src/Plugin/UrlPlugin.php index bb99d49..8226f91 100644 --- a/src/Plugin/UrlPlugin.php +++ b/src/Plugin/UrlPlugin.php @@ -116,7 +116,9 @@ public function aroundGetRemoveFilter(Url $subject, Closure $proceed, Item $filt if (preg_match('|' . $landingPage->getUrlRewriteRequestPath() . '(.*)|', $removeUrl, $matches)) { $category = $this->getLayer()->getCurrentCategory(); $categoryUrl = $category->getUrl(); - $removeUrl = $categoryUrl . $matches[1]; + + //ensure there is one slash between category and the rest of the url + $removeUrl = rtrim($categoryUrl, '/') . '/' . ltrim($matches[1], '/'); } return $removeUrl; diff --git a/src/view/adminhtml/web/js/filter-attributes.js b/src/view/adminhtml/web/js/filter-attributes.js index 5df50fe..8223132 100644 --- a/src/view/adminhtml/web/js/filter-attributes.js +++ b/src/view/adminhtml/web/js/filter-attributes.js @@ -85,6 +85,7 @@ define([ inputValue.show(); } else { inputAttribute.hide(); + selectValue.val(facetValue); if (selectValue.val() != 'tw_other') { inputValue.hide(); inputAttribute.val(facetValue);