Magento2: ImportExport: BEHAVIOR_REPLACE deletes products?

Created on 4 Aug 2016  路  10Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1.0

Steps to reproduce

  1. Import Product with BEHAVIOR_REPLACE set
  2. Import Product with BEHAVIOR_REPLACE set again

Expected result

  1. Same product ID is used, but all the values provided by the import are replaced

Actual result

  1. Product gets deleted and recreated...

It REALLY shouldn't delete the product because all other information related to this product gets lost. If a merchant has written anything store view specific, we want to retrieve reports by product ID, reviews placed on this product, etc.

I'm not sure how something like this happened, the BEHAVIOR_REPLACE doesn't mean replace the product, it means, replace complex values like custom options, configurable products or category associations (wtf?).

I will update this issue with suggestions how to solve this mess and how to solve the importer issues.

ImportExport Clear Description Confirmed Format is valid Ready for Work Reach Digital Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x bug report

All 10 comments

Replace https://github.com/magento/magento2/blob/develop/app/code/Magento/CatalogImportExport/Model/Import/Product.php#L920

With:

$this->_saveProductsData();

The complete _replaceProducts method should be deleted from the class, git blame should be started and the developer responsible should treat the complete company apple pie! 馃構

It seems to be not as easy as removing the above lines. I'm getting the following when importing configurable products. Will report back when I know more.

SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`promopost`.`catalog_product_super_attribute_label`, CONSTRAINT `FK_309442281DF7784210ED82B2CC51E5D5` FOREIGN KEY (`product_super_attribute_id`) REFERENCES `catalog_product_super_attribute` (`), query was: INSERT INTO `catalog_product_super_attribute` (`product_super_attribute_id`,`position`,`product_id`,`attribute_id`) VALUES (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?), (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `product_super_attribute_id` = VALUES(`product_super_attribute_id`), `position` = VALUES(`position`), `product_id` = VALUES(`product_id`), `attribute_id` = VALUES(`attribute_id`)

Two things:

  1. I didn't solve the integrity constraint violation.
  2. The table it gives the integrity constraint violation on doesn't have to be filled with the importer..

This methods generates the data:
https://github.com/magento/magento2/blob/6ea7d2d85cded3fa0fbcf4e7aa0dcd4edbf568a6/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php#L698-L724

You can see here that it generates a label for the attribute, but it currently isn't possible to set store view specific labels and we don't even want a label unique to each product.

So for now I've overwritten the method and just emptied it.

@paales thank you for your feedback.

This is the expected behavior for Replace action. Please read Magento user guide for more details.

I'm closing the ticket. Please feel free to reopen if you have additional questions.

it's definitely not intuitive behavior that needs further investigation. @ilol can you look into that?

This is bug.

Internal ticket is created MAGETWO-67547.

@paales, thank you for your report.
We've created internal ticket(s) MAGETWO-67547 to track progress on the issue.

I agree with @paales. REPLACE should be refactored or removed. Add/Update is also so wrong in many cases. When running add import it will add images to products, it will not overwrite them. Okay, I can understand but REPLACE is also no option like @paales is saying. In my opinion we should have one command for add/update/replace. :-)

This issue was moved to magento-engcom/import-export-improvements#89

Was this page helpful?
0 / 5 - 0 ratings