Skip to content

Commit f79ebaa

Browse files
ENGCOM-8754: REST API Product update url_key doesnt re-gerenate url_rewites when single store enabled #32009
2 parents 6254146 + 2305d63 commit f79ebaa

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
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;

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -508,28 +508,17 @@ public function testGetStoreIds()
508508
/**
509509
* @dataProvider getSingleStoreIds
510510
* @param bool $isObjectNew
511+
* @return void
511512
*/
512-
public function testGetStoreSingleSiteModelIds(
513-
bool $isObjectNew
514-
) {
513+
public function testGetStoreSingleSiteModelIds(bool $isObjectNew): void
514+
{
515515
$websiteIDs = [0 => 2];
516-
$this->model->setWebsiteIds(
517-
!$isObjectNew ? $websiteIDs : array_flip($websiteIDs)
518-
);
516+
$this->model->setWebsiteIds(!$isObjectNew ? $websiteIDs : array_flip($websiteIDs));
519517

520518
$this->model->isObjectNew($isObjectNew);
521519

522-
$this->storeManager->expects(
523-
$this->exactly(
524-
(int)!$isObjectNew
525-
)
526-
)
527-
->method('isSingleStoreMode')
528-
->willReturn(true);
529-
530-
$this->website->expects(
531-
$this->once()
532-
)->method('getStoreIds')
520+
$this->website->expects($this->once())
521+
->method('getStoreIds')
533522
->willReturn($websiteIDs);
534523

535524
$this->assertEquals($websiteIDs, $this->model->getStoreIds());

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)