Skip to content

Commit 12bcddc

Browse files
authored
ENGCOM-4772: Don't skip row on import if image not available. #22382
2 parents a970760 + 36b9219 commit 12bcddc

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ protected function _prepareRowForDb(array $rowData)
12471247
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
12481248
* @SuppressWarnings(PHPMD.NPathComplexity)
12491249
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1250+
* phpcs:disable Generic.Metrics.NestingLevel
12501251
*/
12511252
protected function _saveLinks()
12521253
{
@@ -1256,7 +1257,7 @@ protected function _saveLinks()
12561257
$nextLinkId = $this->_resourceHelper->getNextAutoincrement($mainTable);
12571258

12581259
// pre-load 'position' attributes ID for each link type once
1259-
foreach ($this->_linkNameToId as $linkName => $linkId) {
1260+
foreach ($this->_linkNameToId as $linkId) {
12601261
$select = $this->_connection->select()->from(
12611262
$resource->getTable('catalog_product_link_attribute'),
12621263
['id' => 'product_link_attribute_id']
@@ -1374,6 +1375,7 @@ protected function _saveLinks()
13741375
}
13751376
return $this;
13761377
}
1378+
// phpcs:enable
13771379

13781380
/**
13791381
* Save product attributes.
@@ -1608,6 +1610,7 @@ public function getImagesFromRow(array $rowData)
16081610
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
16091611
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
16101612
* @throws LocalizedException
1613+
* phpcs:disable Generic.Metrics.NestingLevel
16111614
*/
16121615
protected function _saveProducts()
16131616
{
@@ -1798,7 +1801,13 @@ protected function _saveProducts()
17981801
$uploadedImages[$columnImage] = $uploadedFile;
17991802
} else {
18001803
unset($rowData[$column]);
1801-
$this->skipRow($rowNum, ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE);
1804+
$this->addRowError(
1805+
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
1806+
$rowNum,
1807+
null,
1808+
null,
1809+
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
1810+
);
18021811
}
18031812
} else {
18041813
$uploadedFile = $uploadedImages[$columnImage];
@@ -1974,6 +1983,7 @@ protected function _saveProducts()
19741983

19751984
return $this;
19761985
}
1986+
// phpcs:enable
19771987

19781988
/**
19791989
* Prepare array with image states (visible or hidden from product page)

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_catalog_product_reindex_schedule.php
3535
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3636
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
37+
* phpcs:disable Generic.PHP.NoSilencedErrors, Generic.Metrics.NestingLevel, Magento2.Functions.StaticFunction
3738
*/
3839
class ProductTest extends \Magento\TestFramework\Indexer\TestCase
3940
{
@@ -1590,6 +1591,45 @@ public function testAddUpdateProductWithInvalidUrlKeys() : void
15901591
}
15911592
}
15921593

1594+
/**
1595+
* Make sure the non existing image in the csv file won't erase the qty key of the existing products.
1596+
*
1597+
* @magentoDataFixture Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_non_existing_image.csv
1598+
* @magentoDbIsolation enabled
1599+
* @magentoAppIsolation enabled
1600+
*/
1601+
public function testImportWithNonExistingImage()
1602+
{
1603+
$products = [
1604+
'simple_new' => 100,
1605+
];
1606+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
1607+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1608+
$source = $this->objectManager->create(
1609+
\Magento\ImportExport\Model\Import\Source\Csv::class,
1610+
[
1611+
'file' => __DIR__ . '/_files/products_to_import_with_non_existing_image.csv',
1612+
'directory' => $directory
1613+
]
1614+
);
1615+
1616+
$errors = $this->_model->setParameters(
1617+
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product']
1618+
)
1619+
->setSource($source)
1620+
->validateData();
1621+
1622+
$this->assertTrue($errors->getErrorsCount() == 0);
1623+
$this->_model->importData();
1624+
1625+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
1626+
foreach ($products as $productSku => $productQty) {
1627+
$product = $productRepository->get($productSku);
1628+
$stockItem = $product->getExtensionAttributes()->getStockItem();
1629+
$this->assertEquals($productQty, $stockItem->getQty());
1630+
}
1631+
}
1632+
15931633
/**
15941634
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
15951635
* @magentoDbIsolation disabled
@@ -1781,6 +1821,7 @@ function (ProductInterface $item) {
17811821
if ($product->getId()) {
17821822
$productRepository->delete($product);
17831823
}
1824+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
17841825
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
17851826
//Product already removed
17861827
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label1,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,crosssell_skus,upsell_skus,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
2+
simple_new,,Default,simple,,base,New Product,,,,1,Taxable Goods,"Catalog, Search",10,,,,new-product,New Product,New Product,New Product ,/no/exists/image/magento_image.jpg,Image Label,magento_small_image.jpg,Small Image Label,magento_thumbnail.jpg,Thumbnail Label,magento_image.jpg,Image Label,10/20/15 07:05,10/20/15 07:05,,,Block after Info Column,,,,,,,,,,,,,"has_options=1,quantity_and_stock_status=In Stock,required_options=1",100,0,1,0,0,1,1,1,10000,1,1,1,1,1,0,1,1,0,0,0,1,,,,"magento_additional_image_one.jpg, magento_additional_image_two.jpg","Additional Image Label One,Additional Image Label Two",,,,,,,,

0 commit comments

Comments
 (0)