Skip to content

Commit

Permalink
Merge pull request #35 from EmicoEcommerce/beta-2
Browse files Browse the repository at this point in the history
Merge beta into master
  • Loading branch information
ah-net authored Sep 24, 2024
2 parents 27b6967 + c9de69b commit 48200b4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
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
1 change: 1 addition & 0 deletions src/view/adminhtml/web/js/filter-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ define([
inputValue.show();
} else {
inputAttribute.hide();
selectValue.val(facetValue);
if (selectValue.val() != 'tw_other') {
inputValue.hide();
inputAttribute.val(facetValue);
Expand Down

0 comments on commit 48200b4

Please sign in to comment.