Skip to content

Commit 49b8adc

Browse files
author
Oleksandr Iegorov
committed
MC-21727: It is impossible to remove Related, Up-Sells and Cross-Sells products via the import procedure
1 parent 2e359d1 commit 49b8adc

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\Catalog\Api\ProductCustomOptionRepositoryInterface;
1717
use Magento\Catalog\Api\ProductRepositoryInterface;
1818
use Magento\Catalog\Model\Category;
19+
use Magento\Catalog\Model\Product;
20+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1921
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
2022
use Magento\Framework\App\Bootstrap;
2123
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -29,6 +31,7 @@
2931
use Magento\Store\Model\Store;
3032
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection;
3133
use Psr\Log\LoggerInterface;
34+
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
3235

3336
/**
3437
* Class ProductTest
@@ -312,7 +315,6 @@ public function testStockState()
312315
* @throws \Magento\Framework\Exception\LocalizedException
313316
* @throws \Magento\Framework\Exception\NoSuchEntityException
314317
* @magentoAppIsolation enabled
315-
316318
*
317319
* @return void
318320
*/
@@ -1574,6 +1576,49 @@ public function testValidateUrlKeysMultipleStores()
15741576
$this->assertTrue($errors->getErrorsCount() == 0);
15751577
}
15761578

1579+
/**
1580+
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_product_links_data.php
1581+
* @magentoAppArea adminhtml
1582+
* @magentoDbIsolation enabled
1583+
* @magentoAppIsolation enabled
1584+
*/
1585+
public function testProductLinksWithEmptyValue()
1586+
{
1587+
// import data from CSV file
1588+
$pathToFile = __DIR__ . '/_files/products_to_import_with_product_links_with_empty_value.csv';
1589+
$filesystem = BootstrapHelper::getObjectManager()->create(Filesystem::class);
1590+
1591+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1592+
$source = $this->objectManager->create(
1593+
Csv::class,
1594+
[
1595+
'file' => $pathToFile,
1596+
'directory' => $directory
1597+
]
1598+
);
1599+
$errors = $this->_model->setSource(
1600+
$source
1601+
)->setParameters(
1602+
[
1603+
'behavior' => Import::BEHAVIOR_APPEND,
1604+
'entity' => 'catalog_product'
1605+
]
1606+
)->validateData();
1607+
1608+
$this->assertTrue($errors->getErrorsCount() == 0);
1609+
$this->_model->importData();
1610+
1611+
$objectManager = BootstrapHelper::getObjectManager();
1612+
$resource = $objectManager->get(ProductResource::class);
1613+
$productId = $resource->getIdBySku('simple');
1614+
/** @var \Magento\Catalog\Model\Product $product */
1615+
$product = BootstrapHelper::getObjectManager()->create(Product::class);
1616+
$product->load($productId);
1617+
1618+
$this->assertEmpty($product->getCrossSellProducts());
1619+
$this->assertEmpty($product->getUpSellProducts());
1620+
}
1621+
15771622
/**
15781623
* @magentoAppArea adminhtml
15791624
* @magentoDbIsolation enabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,crosssell_skus,crosssell_position,upsell_skus,upsell_position
2+
simple,__EMPTY__VALUE__,__EMPTY__VALUE__,__EMPTY__VALUE__,__EMPTY__VALUE__

0 commit comments

Comments
 (0)