4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Widget to display catalog link
9
- *
10
- * @author Magento Core Team <[email protected] >
11
- */
12
7
namespace Magento \Catalog \Block \Widget ;
13
8
14
9
use Magento \CatalogUrlRewrite \Model \ProductUrlRewriteGenerator ;
15
10
use Magento \UrlRewrite \Model \UrlFinderInterface ;
16
11
use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
17
12
13
+ /**
14
+ * Render the URL of given entity
15
+ */
18
16
class Link extends \Magento \Framework \View \Element \Html \Link implements \Magento \Widget \Block \BlockInterface
19
17
{
20
18
/**
@@ -63,10 +61,9 @@ public function __construct(
63
61
64
62
/**
65
63
* Prepare url using passed id path and return it
66
- * or return false if path was not found in url rewrites.
67
64
*
68
65
* @throws \RuntimeException
69
- * @return string|false
66
+ * @return string|false if path was not found in url rewrites.
70
67
* @SuppressWarnings(PHPMD.NPathComplexity)
71
68
*/
72
69
public function getHref ()
@@ -93,7 +90,7 @@ public function getHref()
93
90
if ($ rewrite ) {
94
91
$ href = $ store ->getUrl ('' , ['_direct ' => $ rewrite ->getRequestPath ()]);
95
92
96
- if (strpos ( $ href , ' ___store ' ) === false ) {
93
+ if ($ this -> addStoreCodeParam ( $ store , $ href ) ) {
97
94
$ href .= (strpos ($ href , '? ' ) === false ? '? ' : '& ' ) . '___store= ' . $ store ->getCode ();
98
95
}
99
96
}
@@ -102,6 +99,22 @@ public function getHref()
102
99
return $ this ->_href ;
103
100
}
104
101
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
+
105
118
/**
106
119
* Parse id_path
107
120
*
@@ -121,6 +134,7 @@ protected function parseIdPath($idPath)
121
134
122
135
/**
123
136
* Prepare label using passed text as parameter.
137
+ *
124
138
* If anchor text was not specified get entity name from DB.
125
139
*
126
140
* @return string
@@ -150,9 +164,8 @@ public function getLabel()
150
164
151
165
/**
152
166
* Render block HTML
153
- * or return empty string if url can't be prepared
154
167
*
155
- * @return string
168
+ * @return string empty string if url can't be prepared
156
169
*/
157
170
protected function _toHtml ()
158
171
{
0 commit comments