Skip to content

Commit 393e8ad

Browse files
author
Yevhen Miroshnychenko
committed
Merge branch '2.3-develop' into MC-19421
2 parents d3498b8 + 3fe8a17 commit 393e8ad

File tree

12 files changed

+262
-120
lines changed

12 files changed

+262
-120
lines changed

app/code/Magento/Catalog/Block/Widget/Link.php

+23-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Widget to display catalog link
9-
*
10-
* @author Magento Core Team <[email protected]>
11-
*/
127
namespace Magento\Catalog\Block\Widget;
138

149
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1510
use Magento\UrlRewrite\Model\UrlFinderInterface;
1611
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1712

13+
/**
14+
* Render the URL of given entity
15+
*/
1816
class Link extends \Magento\Framework\View\Element\Html\Link implements \Magento\Widget\Block\BlockInterface
1917
{
2018
/**
@@ -63,10 +61,9 @@ public function __construct(
6361

6462
/**
6563
* Prepare url using passed id path and return it
66-
* or return false if path was not found in url rewrites.
6764
*
6865
* @throws \RuntimeException
69-
* @return string|false
66+
* @return string|false if path was not found in url rewrites.
7067
* @SuppressWarnings(PHPMD.NPathComplexity)
7168
*/
7269
public function getHref()
@@ -93,7 +90,7 @@ public function getHref()
9390
if ($rewrite) {
9491
$href = $store->getUrl('', ['_direct' => $rewrite->getRequestPath()]);
9592

96-
if (strpos($href, '___store') === false) {
93+
if ($this->addStoreCodeParam($store, $href)) {
9794
$href .= (strpos($href, '?') === false ? '?' : '&') . '___store=' . $store->getCode();
9895
}
9996
}
@@ -102,6 +99,22 @@ public function getHref()
10299
return $this->_href;
103100
}
104101

102+
/**
103+
* Checks whether store code query param should be appended to the URL
104+
*
105+
* @param \Magento\Store\Model\Store $store
106+
* @param string $url
107+
* @return bool
108+
* @throws \Magento\Framework\Exception\NoSuchEntityException
109+
*/
110+
private function addStoreCodeParam(\Magento\Store\Model\Store $store, string $url): bool
111+
{
112+
return $this->getStoreId()
113+
&& !$store->isUseStoreInUrl()
114+
&& $store->getId() !== $this->_storeManager->getStore()->getId()
115+
&& strpos($url, '___store') === false;
116+
}
117+
105118
/**
106119
* Parse id_path
107120
*
@@ -121,6 +134,7 @@ protected function parseIdPath($idPath)
121134

122135
/**
123136
* Prepare label using passed text as parameter.
137+
*
124138
* If anchor text was not specified get entity name from DB.
125139
*
126140
* @return string
@@ -150,9 +164,8 @@ public function getLabel()
150164

151165
/**
152166
* Render block HTML
153-
* or return empty string if url can't be prepared
154167
*
155-
* @return string
168+
* @return string empty string if url can't be prepared
156169
*/
157170
protected function _toHtml()
158171
{

0 commit comments

Comments
 (0)