Skip to content

Commit 2f8f469

Browse files
author
Vasilii Burlacu
committed
#16273: Fix bug in method getUrlInStore() of product model
# Method $product->getUrlInStore() returning extremely long URLs, could be a bug
1 parent 597dbbe commit 2f8f469

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
@@ -52,6 +52,8 @@ public function __construct(
5252
* @param callable $proceed
5353
* @param array $data
5454
* @param bool $unsetOldParams
55+
* @throws \Magento\Framework\Exception\NoSuchEntityException
56+
*
5557
* @return \Magento\Framework\Url\RouteParamsResolver
5658
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5759
*/
@@ -66,13 +68,19 @@ public function aroundSetRouteParams(
6668
unset($data['_scope']);
6769
}
6870
if (isset($data['_scope_to_url']) && (bool)$data['_scope_to_url'] === true) {
69-
$storeCode = $subject->getScope() ?: $this->storeManager->getStore()->getCode();
71+
/** @var Store $currentScope */
72+
$currentScope = $subject->getScope();
73+
$storeCode = $currentScope && $currentScope instanceof Store ?
74+
$currentScope->getCode() :
75+
$this->storeManager->getStore()->getCode();
76+
7077
$useStoreInUrl = $this->scopeConfig->getValue(
7178
Store::XML_PATH_STORE_IN_URL,
7279
StoreScopeInterface::SCOPE_STORE,
7380
$storeCode
7481
);
75-
if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) {
82+
83+
if ($useStoreInUrl && !$this->storeManager->hasSingleStore()) {
7684
$this->queryParamsResolver->setQueryParam('___store', $storeCode);
7785
}
7886
}

0 commit comments

Comments
 (0)