Skip to content

Commit

Permalink
Fix missing query params if rewrite exists
Browse files Browse the repository at this point in the history
  • Loading branch information
vseager committed Apr 25, 2023
1 parent 584e7f8 commit d9a79a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions Model/Config/Source/StoreLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getAllStoresLang($obj = false)

try {
if ($type == 'category') {
$storeCategory = $this->categoryRepository->get($obj->getId(), $store->getId());
$storeCategory = $this->categoryRepository->get($obj->getId(), $store->getId());

if (!$storeCategory->getIsActive()) {
continue;
Expand All @@ -142,20 +142,28 @@ public function getAllStoresLang($obj = false)
UrlRewrite::STORE_ID => $store->getId(),
]
);


$stripSlash = false;

if ($rewrite) {
$urlPath = $rewrite->getRequestPath();
$langUlr = $store->getBaseUrl() . $urlPath;
$urlPath = $rewrite->getRequestPath();
$stripSlash = substr_compare($urlPath, '/', -1) !== 0; // Check if rewrite has a slash
} else {
$selectedFilters = $this->layeredNavState->getActiveFilters();

$queryParams = [];
foreach($selectedFilters as $filter){
$queryParams[$filter->getFilter()->getRequestVar()] = $filter->getValue();
}

$urlPath = $storeCategory->getUrlPath();
$langUlr = $store->getUrl($urlPath, ['_query' => $queryParams]);
}

$selectedFilters = $this->layeredNavState->getActiveFilters();
$queryParams = [];

foreach($selectedFilters as $filter){
$queryParams[$filter->getFilter()->getRequestVar()] = $filter->getValue();
}

$langUlr = $store->getUrl($urlPath, ['_query' => $queryParams]);

if ($stripSlash) {
// Remove slash to avoid redirect
$langUlr = substr_replace($langUlr, '', strrpos($langUlr, '/'), 1);
}

if ($this->urlModifier) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "outeredge/magento-hreflang-alternateurl-module",
"description": "Magento Alternate URL & hreflang Module by outer/edge",
"type": "magento2-module",
"version": "1.1.0",
"version": "1.1.1",
"license": [
"MIT"
],
Expand Down

0 comments on commit d9a79a2

Please sign in to comment.