Skip to content

Commit 118808a

Browse files
committed
MC-41550: product URL rewrite for specific website not generated after mass update
1 parent 679b382 commit 118808a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Plugin/Catalog/Model/Product/UpdateProductWebsiteUrlRewritesTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CatalogUrlRewrite\Plugin\Catalog\Model\Product;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
1112
use Magento\Catalog\Api\ProductRepositoryInterface;
1213
use Magento\Catalog\Model\Product\Action;
1314
use Magento\Store\Api\StoreWebsiteRelationInterface;
@@ -69,4 +70,49 @@ public function testUpdateUrlRewrites()
6970
$url
7071
);
7172
}
73+
74+
/**
75+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
76+
* @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php
77+
*/
78+
public function testUpdateUrlRewritesForSecondProduct()
79+
{
80+
/** @var Website $website */
81+
$websiteRepository = Bootstrap::getObjectManager()->get(WebsiteRepository::class);
82+
$website = $websiteRepository->get('test');
83+
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
84+
// test the first product
85+
$product = $productRepository->get('simple1', false, null, true);
86+
// store filter condition about the first product in collection
87+
$productCollection = Bootstrap::getObjectManager()->get(ProductCollection::class);
88+
$productCollection->addFieldToFilter('entity_id', $product->getId());
89+
$this->action->updateWebsites([$product->getId()], [$website->getId()], 'add');
90+
$storeIds = $this->storeWebsiteRelation->getStoreByWebsiteId($website->getId());
91+
$this->assertStringContainsString(
92+
$product->getUrlKey() . '.html',
93+
$product->setStoreId(reset($storeIds))->getProductUrl()
94+
);
95+
$this->action->updateWebsites([$product->getId()], [$website->getId()], 'remove');
96+
$product->setRequestPath('');
97+
$url = $product->setStoreId(reset($storeIds))->getProductUrl();
98+
$this->assertStringNotContainsString(
99+
$product->getUrlKey() . '.htmll',
100+
$url
101+
);
102+
// test the second product
103+
$product = $productRepository->get('simple2', false, null, true);
104+
$this->action->updateWebsites([$product->getId()], [$website->getId()], 'add');
105+
$storeIds = $this->storeWebsiteRelation->getStoreByWebsiteId($website->getId());
106+
$this->assertStringContainsString(
107+
$product->getUrlKey() . '.html',
108+
$product->setStoreId(reset($storeIds))->getProductUrl()
109+
);
110+
$this->action->updateWebsites([$product->getId()], [$website->getId()], 'remove');
111+
$product->setRequestPath('');
112+
$url = $product->setStoreId(reset($storeIds))->getProductUrl();
113+
$this->assertStringNotContainsString(
114+
$product->getUrlKey() . '.html',
115+
$url
116+
);
117+
}
72118
}

0 commit comments

Comments
 (0)