Skip to content

Commit 02a93cb

Browse files
MC-40305: Can not delete upsell and crosssell products via import
1 parent 63434d2 commit 02a93cb

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function deleteProductsLinks(
220220
if (!empty($linksToDelete) && Import::BEHAVIOR_APPEND === $importEntity->getBehavior()) {
221221
foreach ($linksToDelete as $linkTypeId => $productIds) {
222222
if (!empty($productIds)) {
223-
$whereLinkId = $importEntity->getConnection()->quoteInto('link_type_id', $linkTypeId);
223+
$whereLinkId = $importEntity->getConnection()->quoteInto('link_type_id = ?', $linkTypeId);
224224
$whereProductId = $importEntity->getConnection()->quoteInto(
225225
'product_id IN (?)',
226226
array_unique($productIds)

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,15 +1721,23 @@ public function testValidateUrlKeysMultipleStores()
17211721
}
17221722

17231723
/**
1724+
* Test import product with product links and empty value
1725+
*
1726+
* @param string $pathToFile
1727+
* @param bool $expectedResultCrossell
1728+
* @param bool $expectedResultUpsell
1729+
*
17241730
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_with_product_links_data.php
17251731
* @magentoAppArea adminhtml
17261732
* @magentoDbIsolation enabled
17271733
* @magentoAppIsolation enabled
1734+
* @dataProvider getEmptyLinkedData
17281735
*/
1729-
public function testProductLinksWithEmptyValue()
1730-
{
1731-
// import data from CSV file
1732-
$pathToFile = __DIR__ . '/_files/products_to_import_with_product_links_with_empty_value.csv';
1736+
public function testProductLinksWithEmptyValue(
1737+
string $pathToFile,
1738+
bool $expectedResultCrossell,
1739+
bool $expectedResultUpsell
1740+
): void {
17331741
$filesystem = BootstrapHelper::getObjectManager()->create(Filesystem::class);
17341742

17351743
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
@@ -1759,8 +1767,29 @@ public function testProductLinksWithEmptyValue()
17591767
$product = BootstrapHelper::getObjectManager()->create(Product::class);
17601768
$product->load($productId);
17611769

1762-
$this->assertEmpty($product->getCrossSellProducts());
1763-
$this->assertEmpty($product->getUpSellProducts());
1770+
$this->assertEquals(empty($product->getCrossSellProducts()), $expectedResultCrossell);
1771+
$this->assertEquals(empty($product->getUpSellProducts()), $expectedResultUpsell);
1772+
}
1773+
1774+
/**
1775+
* Get data for empty linked product
1776+
*
1777+
* @return array[]
1778+
*/
1779+
public function getEmptyLinkedData(): array
1780+
{
1781+
return [
1782+
[
1783+
__DIR__ . '/_files/products_to_import_with_product_links_with_empty_value.csv',
1784+
true,
1785+
true,
1786+
],
1787+
[
1788+
__DIR__ . '/_files/products_to_import_with_product_links_with_empty_data.csv',
1789+
false,
1790+
true,
1791+
],
1792+
];
17641793
}
17651794

17661795
/**
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__

dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_with_product_links_data.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,26 @@
1818
$objectManager = Bootstrap::getObjectManager();
1919
/** @var ProductRepositoryInterface $productRepository */
2020
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
21-
$product = $productRepository->get('simple_ms_1');
21+
/** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
22+
$productCrosssellLink = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
23+
->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
24+
$productCrosssellLink->setSku('simple');
25+
$productCrosssellLink->setLinkedProductSku('simple_ms_1');
26+
$productCrosssellLink->setPosition(2);
27+
$productCrosssellLink->setLinkType('crosssell');
28+
$productUpsellLink = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
29+
->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
30+
$productUpsellLink->setSku('simple');
31+
$productUpsellLink->setLinkedProductSku('simple_ms_1');
32+
$productUpsellLink->setPosition(1);
33+
$productUpsellLink->setLinkType('upsell');
34+
$productRelatedLink = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
35+
->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
36+
$productRelatedLink->setSku('simple');
37+
$productRelatedLink->setLinkedProductSku('simple_ms_1');
38+
$productRelatedLink->setPosition(3);
39+
$productRelatedLink->setLinkType('related');
40+
2241
$productModel = $objectManager->create(
2342
\Magento\Catalog\Model\Product::class
2443
);
@@ -51,10 +70,6 @@
5170
true
5271
)->setCategoryIds(
5372
[333]
54-
)->setUpSellLinkData(
55-
[$product->getId() => ['position' => 1]]
56-
)->setCrossSellLinkData(
57-
[$product->getId() => ['position' => 2]]
58-
)->setRelatedLinkData(
59-
[$product->getId() => ['position' => 3]]
73+
)->setProductLinks(
74+
[$productCrosssellLink, $productUpsellLink, $productRelatedLink]
6075
)->save();

0 commit comments

Comments
 (0)