Skip to content

Commit

Permalink
[FEATURE] Force redirect from original store code to the stripped sto…
Browse files Browse the repository at this point in the history
…re code
  • Loading branch information
lewisvoncken committed Apr 24, 2020
1 parent ef78839 commit 5762272
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 7 deletions.
81 changes: 81 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
## 2.1.0 (2020-04-24)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.1.0)

* [BUGFIX] Made the Store Plugin Global to solve issue invalid urls in the sitemap.xml *(Lewis Voncken)*
* [FEATURE] Force redirect from original store code to the stripped store code *(Lewis Voncken)*


## 2.0.5 (2020-03-16)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.5)

* [BUGFIX] Solved invalid issue when using www in domain *(Mr. Lewis)*


## 2.0.4 (2020-03-04)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.4)

* [BUGFIX] Modified website matching by stripping schema and www. *(Egor Dmitriev)*


## 2.0.3 (2020-03-02)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.3)

* [BUGFIX] Fixed direct links to an aliased storeview. *(Egor Dmitriev)*


## 2.0.2 (2020-02-24)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.2)

* [BUGFIX] Fixed fallback such that urls with code in form of website_code still work. *(Egor Dmitriev)*


## 2.0.1 (2019-12-18)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.1)

* [BUGFIX] fixed storeswitcher functionality. Fixed issue with navigating on a non default store. Before all pages would load the default store in de back. Now the correct store *(thomas mondeel)*
* Update README.md *(thokiller)*
* [BUGFIX] fixed switching from homepage *(thomas mondeel)*


## 2.0.0 (2019-12-11)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/2.0.0)

* [FEATURE/BUGFIX] made module compatible with Magento 2.3.* *(thokiller)*


## 1.0.3 (2018-05-11)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/1.0.3)

* [BUGFIX] Solved fatal php error Call to a member function getCode on a boolean *(Lewis Voncken)*


## 1.0.2 (2017-08-24)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/1.0.2)

* [BUGFIX] Solved error in composer .json because of wrong name *(Bart Lubbersen)*


## 1.0.1 (2017-08-24)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/1.0.1)

* [TASK] Add license to composer *(Bart Lubbersen)*


## 1.0.0 (2017-08-24)

[View Release]([email protected]:experius/Magento2-Module-Multiple-Website-Store-Code-Url.git/commits/tag/1.0.0)

* [TASK] Initial commit *(Bart Lubbersen)*
* [TASK] Make configuration only available on default level because url param plugin wont know store yet [TASK] Make module independent on Core module [TASK] Add composer and readme file *(Bart Lubbersen)*


41 changes: 34 additions & 7 deletions Plugin/Magento/Store/App/Request/StorePathInfoValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Experius\MultipleWebsiteStoreCodeUrl\Plugin\Magento\Store\App\Request;

use Experius\MultipleWebsiteStoreCodeUrl\Helper\Data;
use Experius\MultipleWebsiteStoreCodeUrl\Helper\Settings;
use Magento\Framework\App\Request\PathInfo;
use Magento\Store\Api\StoreCookieManagerInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\ResponseFactory;

/**
* Class StorePathInfoValidator
Expand All @@ -24,7 +27,7 @@ class StorePathInfoValidator
private $settings;

/**
* @var \Experius\MultipleWebsiteStoreCodeUrl\Helper\Data
* @var Data
*/
private $helper;

Expand All @@ -34,29 +37,38 @@ class StorePathInfoValidator
private $storeCookieManager;

/**
* @var \Magento\Framework\App\Request\PathInfo
* @var PathInfo
*/
private $pathInfo;
/**
* @var ResponseFactory
*/
private $responseFactory;

/**
* StorePathInfoValidator constructor.
*
* @param StoreManagerInterface $storeManager
* @param Settings $settings
* @param Data $helper
* @param StoreCookieManagerInterface $storeCookieManager
* @param \Magento\Framework\App\Request\PathInfo $pathInfo
* @param PathInfo $pathInfo
* @param ResponseFactory $responseFactory
*/
public function __construct(
StoreManagerInterface $storeManager,
Settings $settings,
\Experius\MultipleWebsiteStoreCodeUrl\Helper\Data $helper,
Data $helper,
StoreCookieManagerInterface $storeCookieManager,
\Magento\Framework\App\Request\PathInfo $pathInfo
PathInfo $pathInfo,
ResponseFactory $responseFactory
) {
$this->storeManager = $storeManager;
$this->settings = $settings;
$this->helper = $helper;
$this->storeCookieManager = $storeCookieManager;
$this->pathInfo = $pathInfo;
$this->responseFactory = $responseFactory;
}

/**
Expand All @@ -72,7 +84,7 @@ public function afterGetValidStoreCode(
$request,
$pathInfo = ''
) {
if ($result != null || !$this->settings->shouldRemoveWebsiteCodeFromStoreUrl()) {
if (!$this->settings->shouldRemoveWebsiteCodeFromStoreUrl()) {
return $result;
}
if (empty($pathInfo)) {
Expand All @@ -81,6 +93,13 @@ public function afterGetValidStoreCode(
$request->getBaseUrl()
);
}
$pathParts = explode('/', ltrim($pathInfo, '/'), 2);
if ($result) {
if (strpos($pathParts[0], '_') === false) {
return $result;
}

}
$websiteCode = $this->storeCookieManager->getStoreCodeFromCookie();

if(!$websiteCode && $website = $this->helper->getRequestToWebsite($request)) {
Expand All @@ -89,7 +108,15 @@ public function afterGetValidStoreCode(
if (!$websiteCode) {
return $result;
}
$pathParts = explode('/', ltrim($pathInfo, '/'), 2);

if ($result && strpos($request->getRequestUri(), "/{$websiteCode}_") !== false) {
$requestUri = str_replace("/{$websiteCode}_", "", $request->getRequestUri());
$response = $this->responseFactory->create();
$response->setRedirect($request->getDistroBaseUrl() . $requestUri, 301);
$response->sendResponse();
exit;
}

$storeCode = "{$websiteCode}_{$pathParts[0]}";
try {
/** @var \Magento\Store\Api\Data\StoreInterface $store */
Expand Down

0 comments on commit 5762272

Please sign in to comment.