|
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 |
|
@@ -626,7 +627,7 @@ function ($input) {
|
626 | 627 | explode(',', $optionData)
|
627 | 628 | )
|
628 | 629 | );
|
629 |
| - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge |
| 630 | + // phpcs:ignore Magento2.Performance.ForeachArrayMerge |
630 | 631 | $option = array_merge(...$option);
|
631 | 632 |
|
632 | 633 | if (!empty($option['type']) && !empty($option['name'])) {
|
@@ -693,14 +694,14 @@ protected function mergeWithExistingData(
|
693 | 694 | }
|
694 | 695 | } else {
|
695 | 696 | $existingOptionId = array_search($optionKey, $expectedOptions);
|
696 |
| - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge |
| 697 | + // phpcs:ignore Magento2.Performance.ForeachArrayMerge |
697 | 698 | $expectedData[$existingOptionId] = array_merge(
|
698 | 699 | $this->getOptionData($option),
|
699 | 700 | $expectedData[$existingOptionId]
|
700 | 701 | );
|
701 | 702 | if ($optionValues) {
|
702 | 703 | foreach ($optionValues as $optionKey => $optionValue) {
|
703 |
| - // phpcs:ignore Magento2.Performance.ForeachArrayMerge.ForeachArrayMerge |
| 704 | + // phpcs:ignore Magento2.Performance.ForeachArrayMerge |
704 | 705 | $expectedValues[$existingOptionId][$optionKey] = array_merge(
|
705 | 706 | $optionValue,
|
706 | 707 | $expectedValues[$existingOptionId][$optionKey]
|
@@ -1710,6 +1711,63 @@ public function testImportWithNonExistingImage()
|
1710 | 1711 | }
|
1711 | 1712 | }
|
1712 | 1713 |
|
| 1714 | + /** |
| 1715 | + * @magentoDataFixture Magento/Catalog/_files/product_without_options.php |
| 1716 | + * @magentoDbIsolation enabled |
| 1717 | + * @magentoAppIsolation enabled |
| 1718 | + */ |
| 1719 | + public function testUpdateUrlRewritesOnImport() |
| 1720 | + { |
| 1721 | + $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class); |
| 1722 | + |
| 1723 | + $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); |
| 1724 | + |
| 1725 | + $source = $this->objectManager->create( |
| 1726 | + \Magento\ImportExport\Model\Import\Source\Csv::class, |
| 1727 | + [ |
| 1728 | + 'file' => __DIR__ . '/_files/products_to_import_with_category.csv', |
| 1729 | + 'directory' => $directory |
| 1730 | + ] |
| 1731 | + ); |
| 1732 | + $errors = $this->_model->setParameters( |
| 1733 | + [ |
| 1734 | + 'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, |
| 1735 | + 'entity' => \Magento\Catalog\Model\Product::ENTITY |
| 1736 | + ] |
| 1737 | + )->setSource( |
| 1738 | + $source |
| 1739 | + )->validateData(); |
| 1740 | + |
| 1741 | + $this->assertTrue($errors->getErrorsCount() == 0); |
| 1742 | + |
| 1743 | + $this->_model->importData(); |
| 1744 | + |
| 1745 | + /** @var \Magento\Catalog\Model\Product $product */ |
| 1746 | + $product = $this->objectManager->create(\Magento\Catalog\Model\ProductRepository::class)->get('simple'); |
| 1747 | + |
| 1748 | + $repUrlRewriteCol = $this->objectManager->create( |
| 1749 | + UrlRewriteCollection::class |
| 1750 | + ); |
| 1751 | + |
| 1752 | + /** @var UrlRewriteCollection $collUrlRewrite */ |
| 1753 | + $collUrlRewrite = $repUrlRewriteCol->addFieldToSelect(['request_path']) |
| 1754 | + ->addFieldToFilter('entity_id', ['eq'=> $product->getEntityId()]) |
| 1755 | + ->addFieldToFilter('entity_type', ['eq'=> 'product']) |
| 1756 | + ->load(); |
| 1757 | + |
| 1758 | + $this->assertCount(2, $collUrlRewrite); |
| 1759 | + |
| 1760 | + $this->assertEquals( |
| 1761 | + sprintf('%s.html', $product->getUrlKey()), |
| 1762 | + $collUrlRewrite->getFirstItem()->getRequestPath() |
| 1763 | + ); |
| 1764 | + |
| 1765 | + $this->assertContains( |
| 1766 | + sprintf('men/tops/%s.html', $product->getUrlKey()), |
| 1767 | + $collUrlRewrite->getLastItem()->getRequestPath() |
| 1768 | + ); |
| 1769 | + } |
| 1770 | + |
1713 | 1771 | /**
|
1714 | 1772 | * @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
|
1715 | 1773 | * @magentoDbIsolation enabled
|
|
0 commit comments