Skip to content

Commit 494eb40

Browse files
#30316: REST API Product update url_key doesnt re-gerenate url_rewites when single store enabled
1 parent 5e57ddd commit 494eb40

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,6 @@ public function getStoreIds()
828828
if (!$this->hasStoreIds()) {
829829
$storeIds = [];
830830
if ($websiteIds = $this->getWebsiteIds()) {
831-
if (!$this->isObjectNew() && $this->_storeManager->isSingleStoreMode()) {
832-
$websiteIds = array_keys($websiteIds);
833-
}
834831
foreach ($websiteIds as $websiteId) {
835832
$websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
836833
$storeIds[] = $websiteStores;

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Authorization\Model\Role;
1212
use Magento\Authorization\Model\RoleFactory;
1313
use Magento\Authorization\Model\Rules;
14+
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory;
1415
use Magento\Authorization\Model\RulesFactory;
1516
use Magento\Catalog\Api\Data\ProductInterface;
1617
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
@@ -34,6 +35,7 @@
3435
use Magento\Store\Model\WebsiteRepository;
3536
use Magento\TestFramework\Helper\Bootstrap;
3637
use Magento\TestFramework\TestCase\WebapiAbstract;
38+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
3739

3840
/**
3941
* Test for \Magento\Catalog\Api\ProductRepositoryInterface
@@ -84,23 +86,31 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
8486
* @var AdminTokenServiceInterface
8587
*/
8688
private $adminTokens;
89+
8790
/**
8891
* @var array
8992
*/
9093
private $fixtureProducts = [];
9194

95+
/**
96+
* @var UrlRewriteCollectionFactory
97+
*/
98+
private $urlRewriteCollectionFactory;
99+
92100
/**
93101
* @inheritDoc
94102
*/
95103
protected function setUp(): void
96104
{
97105
parent::setUp();
98106

99-
$this->roleFactory = Bootstrap::getObjectManager()->get(RoleFactory::class);
100-
$this->rulesFactory = Bootstrap::getObjectManager()->get(RulesFactory::class);
101-
$this->adminTokens = Bootstrap::getObjectManager()->get(AdminTokenServiceInterface::class);
107+
$objectManager = Bootstrap::getObjectManager();
108+
$this->roleFactory = $objectManager->get(RoleFactory::class);
109+
$this->rulesFactory = $objectManager->get(RulesFactory::class);
110+
$this->adminTokens = $objectManager->get(AdminTokenServiceInterface::class);
111+
$this->urlRewriteCollectionFactory = $objectManager->get(UrlRewriteCollectionFactory::class);
102112
/** @var DomainManagerInterface $domainManager */
103-
$domainManager = Bootstrap::getObjectManager()->get(DomainManagerInterface::class);
113+
$domainManager = $objectManager->get(DomainManagerInterface::class);
104114
$domainManager->addDomains(['example.com']);
105115
}
106116

@@ -2156,6 +2166,32 @@ public function testUpdateProductWithMediaGallery(): void
21562166
$this->assertEquals($img2, $imageRolesPerStore[$defaultScope]['thumbnail']);
21572167
}
21582168

2169+
/**
2170+
* Update url_key attribute and check it in url_rewrite collection
2171+
*
2172+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
2173+
* @magentoConfigFixture default_store general/single_store_mode/enabled 1
2174+
*
2175+
* @return void
2176+
*/
2177+
public function testUpdateUrlKeyAttribute(): void
2178+
{
2179+
$newUrlKey = 'my-new-url';
2180+
2181+
$productData = [
2182+
ProductInterface::SKU => 'simple',
2183+
'custom_attributes' => [['attribute_code' => 'url_key', 'value' => $newUrlKey]],
2184+
];
2185+
2186+
$this->updateProduct($productData);
2187+
2188+
$urlRewriteCollection = $this->urlRewriteCollectionFactory->create();
2189+
$urlRewriteCollection->addFieldToFilter(UrlRewrite::ENTITY_TYPE, 'product')
2190+
->addFieldToFilter('request_path', $newUrlKey . '.html');
2191+
2192+
$this->assertCount(1, $urlRewriteCollection);
2193+
}
2194+
21592195
/**
21602196
* @return string
21612197
*/

0 commit comments

Comments
 (0)