Skip to content

Commit

Permalink
magento#30316: REST API Product update url_key doesnt re-gerenate url…
Browse files Browse the repository at this point in the history
…_rewites when single store enabled
  • Loading branch information
engcom-Charlie committed Feb 9, 2021
1 parent 5e57ddd commit 494eb40
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
3 changes: 0 additions & 3 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,6 @@ public function getStoreIds()
if (!$this->hasStoreIds()) {
$storeIds = [];
if ($websiteIds = $this->getWebsiteIds()) {
if (!$this->isObjectNew() && $this->_storeManager->isSingleStoreMode()) {
$websiteIds = array_keys($websiteIds);
}
foreach ($websiteIds as $websiteId) {
$websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
$storeIds[] = $websiteStores;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Authorization\Model\Role;
use Magento\Authorization\Model\RoleFactory;
use Magento\Authorization\Model\Rules;
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory;
use Magento\Authorization\Model\RulesFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
Expand All @@ -34,6 +35,7 @@
use Magento\Store\Model\WebsiteRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;

/**
* Test for \Magento\Catalog\Api\ProductRepositoryInterface
Expand Down Expand Up @@ -84,23 +86,31 @@ class ProductRepositoryInterfaceTest extends WebapiAbstract
* @var AdminTokenServiceInterface
*/
private $adminTokens;

/**
* @var array
*/
private $fixtureProducts = [];

/**
* @var UrlRewriteCollectionFactory
*/
private $urlRewriteCollectionFactory;

/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();

$this->roleFactory = Bootstrap::getObjectManager()->get(RoleFactory::class);
$this->rulesFactory = Bootstrap::getObjectManager()->get(RulesFactory::class);
$this->adminTokens = Bootstrap::getObjectManager()->get(AdminTokenServiceInterface::class);
$objectManager = Bootstrap::getObjectManager();
$this->roleFactory = $objectManager->get(RoleFactory::class);
$this->rulesFactory = $objectManager->get(RulesFactory::class);
$this->adminTokens = $objectManager->get(AdminTokenServiceInterface::class);
$this->urlRewriteCollectionFactory = $objectManager->get(UrlRewriteCollectionFactory::class);
/** @var DomainManagerInterface $domainManager */
$domainManager = Bootstrap::getObjectManager()->get(DomainManagerInterface::class);
$domainManager = $objectManager->get(DomainManagerInterface::class);
$domainManager->addDomains(['example.com']);
}

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

/**
* Update url_key attribute and check it in url_rewrite collection
*
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
* @magentoConfigFixture default_store general/single_store_mode/enabled 1
*
* @return void
*/
public function testUpdateUrlKeyAttribute(): void
{
$newUrlKey = 'my-new-url';

$productData = [
ProductInterface::SKU => 'simple',
'custom_attributes' => [['attribute_code' => 'url_key', 'value' => $newUrlKey]],
];

$this->updateProduct($productData);

$urlRewriteCollection = $this->urlRewriteCollectionFactory->create();
$urlRewriteCollection->addFieldToFilter(UrlRewrite::ENTITY_TYPE, 'product')
->addFieldToFilter('request_path', $newUrlKey . '.html');

$this->assertCount(1, $urlRewriteCollection);
}

/**
* @return string
*/
Expand Down

0 comments on commit 494eb40

Please sign in to comment.