Skip to content

Commit d116454

Browse files
Vasilii Burlacumage2pratik
Vasilii Burlacu
authored andcommitted
#16273: Fix bug in method getUrlInStore() of product model
# Method $product->getUrlInStore() returning extremely long URLs, could be a bug (cherry picked from commit 7558ac0)
1 parent 137fcbf commit d116454

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/code/Magento/Store/Url/Plugin/RouteParamsResolver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function __construct(
5151
* @param \Magento\Framework\Url\RouteParamsResolver $subject
5252
* @param array $data
5353
* @param bool $unsetOldParams
54+
* @throws \Magento\Framework\Exception\NoSuchEntityException
55+
*
5456
* @return array
5557
*/
5658
public function beforeSetRouteParams(
@@ -63,13 +65,19 @@ public function beforeSetRouteParams(
6365
unset($data['_scope']);
6466
}
6567
if (isset($data['_scope_to_url']) && (bool)$data['_scope_to_url'] === true) {
66-
$storeCode = $subject->getScope() ?: $this->storeManager->getStore()->getCode();
68+
/** @var Store $currentScope */
69+
$currentScope = $subject->getScope();
70+
$storeCode = $currentScope && $currentScope instanceof Store ?
71+
$currentScope->getCode() :
72+
$this->storeManager->getStore()->getCode();
73+
6774
$useStoreInUrl = $this->scopeConfig->getValue(
6875
Store::XML_PATH_STORE_IN_URL,
6976
StoreScopeInterface::SCOPE_STORE,
7077
$storeCode
7178
);
72-
if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) {
79+
80+
if ($useStoreInUrl && !$this->storeManager->hasSingleStore()) {
7381
$this->queryParamsResolver->setQueryParam('___store', $storeCode);
7482
}
7583
}

0 commit comments

Comments
 (0)