Skip to content

Commit

Permalink
Merge pull request #31 from EmicoEcommerce/fix-return-landingpage-url
Browse files Browse the repository at this point in the history
Fix: return landingpage url
  • Loading branch information
ah-net authored Sep 19, 2024
2 parents 7ce708c + 15b7a61 commit a63f1b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Plugin/PathSlugStrategyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 3 additions & 1 deletion src/Plugin/UrlPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a63f1b7

Please sign in to comment.