Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: return landingpage url #31

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 readonly LandingPageContext $landingPageContext;

/**
* DefaultRendererPlugin constructor.
* @param FilterManager $filterManager
*/
public function __construct(FilterManager $filterManager)
public function __construct(FilterManager $filterManager, LandingPageContext $landingPageContext)
ah-net marked this conversation as resolved.
Show resolved Hide resolved
{
$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
Loading