|
25 | 25 | use Magento\Framework\Registry;
|
26 | 26 | use Magento\ImportExport\Model\Import;
|
27 | 27 | use Magento\Store\Model\Store;
|
| 28 | +use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection; |
28 | 29 | use Psr\Log\LoggerInterface;
|
29 | 30 | use Magento\ImportExport\Model\Import\Source\Csv;
|
30 | 31 |
|
@@ -1647,6 +1648,63 @@ public function testImportWithNonExistingImage()
|
1647 | 1648 | }
|
1648 | 1649 | }
|
1649 | 1650 |
|
| 1651 | + /** |
| 1652 | + * @magentoDataFixture Magento/Catalog/_files/product_without_options.php |
| 1653 | + * @magentoDbIsolation enabled |
| 1654 | + * @magentoAppIsolation enabled |
| 1655 | + */ |
| 1656 | + public function testUpdateUrlRewritesOnImport() |
| 1657 | + { |
| 1658 | + $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); |
| 1659 | + |
| 1660 | + $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); |
| 1661 | + |
| 1662 | + $source = $this->objectManager->create( |
| 1663 | + \Magento\ImportExport\Model\Import\Source\Csv::class, |
| 1664 | + [ |
| 1665 | + 'file' => __DIR__ . '/_files/products_to_import_with_category.csv', |
| 1666 | + 'directory' => $directory |
| 1667 | + ] |
| 1668 | + ); |
| 1669 | + $errors = $this->_model->setParameters( |
| 1670 | + [ |
| 1671 | + 'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, |
| 1672 | + 'entity' => \Magento\Catalog\Model\Product::ENTITY |
| 1673 | + ] |
| 1674 | + )->setSource( |
| 1675 | + $source |
| 1676 | + )->validateData(); |
| 1677 | + |
| 1678 | + $this->assertTrue($errors->getErrorsCount() == 0); |
| 1679 | + |
| 1680 | + $this->_model->importData(); |
| 1681 | + |
| 1682 | + /** @var \Magento\Catalog\Model\Product $product */ |
| 1683 | + $product = $this->objectManager->create(\Magento\Catalog\Model\ProductRepository::class)->get('simple'); |
| 1684 | + |
| 1685 | + $repUrlRewriteCol = $this->objectManager->create( |
| 1686 | + UrlRewriteCollection::class |
| 1687 | + ); |
| 1688 | + |
| 1689 | + /** @var UrlRewriteCollection $collUrlRewrite */ |
| 1690 | + $collUrlRewrite = $repUrlRewriteCol->addFieldToSelect(['request_path']) |
| 1691 | + ->addFieldToFilter('entity_id', ['eq'=> $product->getEntityId()]) |
| 1692 | + ->addFieldToFilter('entity_type', ['eq'=> 'product']) |
| 1693 | + ->load(); |
| 1694 | + |
| 1695 | + $this->assertCount(2, $collUrlRewrite); |
| 1696 | + |
| 1697 | + $this->assertEquals( |
| 1698 | + sprintf('%s.html', $product->getUrlKey()), |
| 1699 | + $collUrlRewrite->getFirstItem()->getRequestPath() |
| 1700 | + ); |
| 1701 | + |
| 1702 | + $this->assertContains( |
| 1703 | + sprintf('men/tops/%s.html', $product->getUrlKey()), |
| 1704 | + $collUrlRewrite->getLastItem()->getRequestPath() |
| 1705 | + ); |
| 1706 | + } |
| 1707 | + |
1650 | 1708 | /**
|
1651 | 1709 | * @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
|
1652 | 1710 | * @magentoDbIsolation enabled
|
|
0 commit comments