Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't skip row on import if image not available. #22382

Merged
merged 3 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ protected function _prepareRowForDb(array $rowData)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* phpcs:disable Generic.Metrics.NestingLevel
*/
protected function _saveLinks()
{
Expand All @@ -1256,7 +1257,7 @@ protected function _saveLinks()
$nextLinkId = $this->_resourceHelper->getNextAutoincrement($mainTable);

// pre-load 'position' attributes ID for each link type once
foreach ($this->_linkNameToId as $linkName => $linkId) {
foreach ($this->_linkNameToId as $linkId) {
$select = $this->_connection->select()->from(
$resource->getTable('catalog_product_link_attribute'),
['id' => 'product_link_attribute_id']
Expand Down Expand Up @@ -1374,6 +1375,7 @@ protected function _saveLinks()
}
return $this;
}
// phpcs:enable

/**
* Save product attributes.
Expand Down Expand Up @@ -1608,6 +1610,7 @@ public function getImagesFromRow(array $rowData)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* @throws LocalizedException
* phpcs:disable Generic.Metrics.NestingLevel
*/
protected function _saveProducts()
{
Expand Down Expand Up @@ -1798,7 +1801,13 @@ protected function _saveProducts()
$uploadedImages[$columnImage] = $uploadedFile;
} else {
unset($rowData[$column]);
$this->skipRow($rowNum, ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE);
$this->addRowError(
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE,
$rowNum,
null,
null,
ProcessingError::ERROR_LEVEL_NOT_CRITICAL
);
}
} else {
$uploadedFile = $uploadedImages[$columnImage];
Expand Down Expand Up @@ -1974,6 +1983,7 @@ protected function _saveProducts()

return $this;
}
// phpcs:enable

/**
* Prepare array with image states (visible or hidden from product page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_catalog_product_reindex_schedule.php
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* phpcs:disable Generic.PHP.NoSilencedErrors, Generic.Metrics.NestingLevel, Magento2.Functions.StaticFunction
*/
class ProductTest extends \Magento\TestFramework\Indexer\TestCase
{
Expand Down Expand Up @@ -1590,6 +1591,45 @@ public function testAddUpdateProductWithInvalidUrlKeys() : void
}
}

/**
* Make sure the non existing image in the csv file won't erase the qty key of the existing products.
*
* @magentoDataFixture Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_non_existing_image.csv
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testImportWithNonExistingImage()
{
$products = [
'simple_new' => 100,
];
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(
\Magento\ImportExport\Model\Import\Source\Csv::class,
[
'file' => __DIR__ . '/_files/products_to_import_with_non_existing_image.csv',
'directory' => $directory
]
);

$errors = $this->_model->setParameters(
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product']
)
->setSource($source)
->validateData();

$this->assertTrue($errors->getErrorsCount() == 0);
$this->_model->importData();

$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
foreach ($products as $productSku => $productQty) {
$product = $productRepository->get($productSku);
$stockItem = $product->getExtensionAttributes()->getStockItem();
$this->assertEquals($productQty, $stockItem->getQty());
}
}

/**
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
* @magentoDbIsolation disabled
Expand Down Expand Up @@ -1781,6 +1821,7 @@ function (ProductInterface $item) {
if ($product->getId()) {
$productRepository->delete($product);
}
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
//Product already removed
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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
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",,,,,,,,