|
8 | 8 | namespace Magento\CatalogUrlRewrite\Plugin\Catalog\Model\Product;
|
9 | 9 |
|
10 | 10 | use Magento\Catalog\Api\Data\ProductInterface;
|
| 11 | +use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; |
11 | 12 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
12 | 13 | use Magento\Catalog\Model\Product\Action;
|
13 | 14 | use Magento\Store\Api\StoreWebsiteRelationInterface;
|
@@ -69,4 +70,49 @@ public function testUpdateUrlRewrites()
|
69 | 70 | $url
|
70 | 71 | );
|
71 | 72 | }
|
| 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 | + } |
72 | 118 | }
|
0 commit comments