Skip to content

Commit e00e0f7

Browse files
ENGCOM-4843: $product->getUrlInStore() does not allow to override the scope in backend context #21876
- Merge Pull Request #21876 from Nazar65/magento2:issue-21478 - Merged commits: 1. c50975a
2 parents 19fab05 + c50975a commit e00e0f7

File tree

2 files changed

+57
-4
lines changed
  • app/code/Magento/Backend/Model
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Product

2 files changed

+57
-4
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Class \Magento\Backend\Model\UrlInterface
1414
*
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1617
* @api
1718
* @since 100.0.2
1819
*/
@@ -366,6 +367,19 @@ protected function _getMenu()
366367
return $this->_menu;
367368
}
368369

370+
/**
371+
* Set scope entity
372+
*
373+
* @param mixed $scopeId
374+
* @return \Magento\Framework\UrlInterface
375+
*/
376+
public function setScope($scopeId)
377+
{
378+
parent::setScope($scopeId);
379+
$this->_scope = $this->_scopeResolver->getScope($scopeId);
380+
return $this;
381+
}
382+
369383
/**
370384
* Set custom auth session
371385
*
@@ -402,13 +416,13 @@ public function getAreaFrontName()
402416
}
403417

404418
/**
405-
* Retrieve action path.
406-
* Add backend area front name as a prefix to action path
419+
* Retrieve action path, add backend area front name as a prefix to action path
407420
*
408421
* @return string
409422
*/
410423
protected function _getActionPath()
411424
{
425+
412426
$path = parent::_getActionPath();
413427
if ($path) {
414428
if ($this->getAreaFrontName()) {
@@ -448,8 +462,7 @@ protected function _getConfigCacheId($path)
448462
}
449463

450464
/**
451-
* Get config data by path
452-
* Use only global config values for backend
465+
* Get config data by path, use only global config values for backend
453466
*
454467
* @param string $path
455468
* @return null|string

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/UrlTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,46 @@ public function testGetUrlInStore()
4242
$this->assertStringEndsWith('simple-product.html', $this->_model->getUrlInStore($product));
4343
}
4444

45+
/**
46+
* @magentoDataFixture Magento/Store/_files/second_store.php
47+
* @magentoConfigFixture default_store web/unsecure/base_url http://sample.com/
48+
* @magentoConfigFixture default_store web/unsecure/base_link_url http://sample.com/
49+
* @magentoConfigFixture fixturestore_store web/unsecure/base_url http://sample-second.com/
50+
* @magentoConfigFixture fixturestore_store web/unsecure/base_link_url http://sample-second.com/
51+
* @magentoDataFixture Magento/Catalog/_files/product_simple_multistore.php
52+
* @dataProvider getUrlsWithSecondStoreProvider
53+
* @magentoAppArea adminhtml
54+
*/
55+
public function testGetUrlInStoreWithSecondStore($storeCode, $expectedProductUrl)
56+
{
57+
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
58+
\Magento\Catalog\Model\ProductRepository::class
59+
);
60+
/** @var \Magento\Store\Model\Store $store */
61+
$store = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
62+
->create(\Magento\Store\Model\Store::class);
63+
$store->load($storeCode, 'code');
64+
/** @var \Magento\Store\Model\Store $store */
65+
66+
$product = $repository->get('simple');
67+
68+
$this->assertEquals(
69+
$expectedProductUrl,
70+
$this->_model->getUrlInStore($product, ['_scope' => $store->getId(), '_nosid' => true])
71+
);
72+
}
73+
74+
/**
75+
* @return array
76+
*/
77+
public function getUrlsWithSecondStoreProvider()
78+
{
79+
return [
80+
'case1' => ['fixturestore', 'http://sample-second.com/index.php/simple-product-one.html'],
81+
'case2' => ['default', 'http://sample.com/index.php/simple-product-one.html']
82+
];
83+
}
84+
4585
public function testGetProductUrl()
4686
{
4787
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(

0 commit comments

Comments
 (0)