Skip to content

Commit

Permalink
Merge pull request #9 from EmicoEcommerce/bugfix-url-rewrite-without-…
Browse files Browse the repository at this point in the history
…redirect

Bugfix url rewrite without redirect
  • Loading branch information
ah-net authored Jun 20, 2023
2 parents f5ccbc7 + 354348e commit 451fc8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
20 changes: 18 additions & 2 deletions src/Model/FilterFormInputProvider/LandingPageInputProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Framework\Exception\NotFoundException;
use Tweakwise\Magento2Tweakwise\Model\FilterFormInputProvider\HashInputProvider;
use Tweakwise\Magento2Tweakwise\Model\FilterFormInputProvider\ToolbarInputProvider;
use Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\Url;

class LandingPageInputProvider implements FilterFormInputProviderInterface
{
Expand Down Expand Up @@ -44,6 +45,11 @@ class LandingPageInputProvider implements FilterFormInputProviderInterface
*/
protected HashInputProvider $hashInputProvider;

/**
* @var Url
*/
protected $layerUrl;

/**
* LandingPageProvider constructor.
* @param Config $twConfig
Expand All @@ -54,13 +60,15 @@ public function __construct(
LandingPageContext $landingPageContext,
RequestInterface $request,
ToolbarInputProvider $toolbarInputProvider,
HashInputProvider $hashInputProvider
HashInputProvider $hashInputProvider,
Url $layerUrl
) {
$this->twConfig = $twConfig;
$this->landingPageContext = $landingPageContext;
$this->request = $request;
$this->toolbarInputProvider = $toolbarInputProvider;
$this->hashInputProvider = $hashInputProvider;
$this->layerUrl = $layerUrl;
}

/**
Expand All @@ -81,7 +89,7 @@ public function getFilterFormInput(): array
$input = [
'__tw_ajax_type' => self::TYPE,
'__tw_object_id' => (int)$page->getPageId(),
'__tw_original_url' => $page->getUrlPath(),
'__tw_original_url' => $this->getOriginalUrl(),
];

$input['__tw_hash'] = $this->hashInputProvider->getHash($input);
Expand All @@ -99,4 +107,12 @@ protected function getPage(): LandingPageInterface
{
return $this->landingPageContext->getLandingPage();
}

/**
* @return string
*/
public function getOriginalUrl() : string
{
return $this->layerUrl->getUrlStrategy()->getOriginalUrl($this->request);
}
}
39 changes: 1 addition & 38 deletions src/Plugin/PathSlugStrategyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,49 +173,12 @@ public function afterGetCategoryFilterSelectUrl(
}

/**
* @deprecated
* @param MagentoHttpRequest $request
* @return string
*/
public function afterGetOriginalUrl(PathSlugStrategy $original, string $result, MagentoHttpRequest $request): string
{
$landingPage = $this->landingPageContext->getLandingPage();
if ($landingPage === null) {
return $result;
}

if ($twOriginalUrl = $request->getParam('__tw_original_url')) {
// This seems ugly, perhaps there is another way?
$query = [];
// Add page and sort
$page = $request->getParam('p');
$sort = $request->getParam('product_list_order');
$limit = $request->getParam('product_list_limit');
$mode = $request->getParam('product_list_mode');

if ($page &&
(int) $page > 1
) {
$query['p'] = $page;
}

if ($sort) {
$query['product_list_order'] = $sort;
}
if ($limit) {
$query['product_list_limit'] = $limit;
}
if ($mode) {
$query['product_list_mode'] = $mode;
}

$magentoUrl = $original->getMagentoUrl();

return filter_var(
$magentoUrl->getDirectUrl($twOriginalUrl, ['_query' => $query]),
FILTER_SANITIZE_URL
);
}

return $result;
}
}

0 comments on commit 451fc8d

Please sign in to comment.