Magento2: Cannot remove a product from a category during product update

Created on 16 Aug 2017  路  6Comments  路  Source: magento/magento2


Preconditions


  1. Magento Community Edition 2.1.8
  2. Import Entity Type Products, Add/Update Import Behaviour

Steps to reproduce

  1. Import Products with changed categories

Expected result

  1. Current category/product associations are replaced, like product names, descriptions would be

Actual result

  1. Only new product/category associations are added, previous ones are not removed. This is because on this line https://github.com/magento/magento2/blob/2.1.8/app/code/Magento/CatalogImportExport/Model/Import/Product.php#L1307 there is no check to see what categories products are no longer in.


The only workaround for this is to change Import Behaviour to Replace, but this recreates the entire product

Format is valid

Most helpful comment

I do not understand how this could be correct behaviour - it offers no way to update products without knowing their prior categories -i have never met a merchant who could do this, they know in which categories the product should now be in. I believe your logic is not pratical in real world scenarios. In the add/update scenario - the category has changed - the product should be updated to reflect this. Forcing us to use "replace" has too many negative consequences as we are not replacing a product we are updating it. What procedure whould you suggest to move a product from one category to another via import?

All 6 comments

@jameswithers, thank you for your report.
We were able to reproduce this issue by following the steps you provided. But it seems this is a correct Magento behaivour. Please see http://docs.magento.com/m2/ce/user_guide/system/data-import.html for details.

I do not understand how this could be correct behaviour - it offers no way to update products without knowing their prior categories -i have never met a merchant who could do this, they know in which categories the product should now be in. I believe your logic is not pratical in real world scenarios. In the add/update scenario - the category has changed - the product should be updated to reflect this. Forcing us to use "replace" has too many negative consequences as we are not replacing a product we are updating it. What procedure whould you suggest to move a product from one category to another via import?

Baffling.

This is clearly a bug, and it is quite baffling that this issue keeps getting shut down as "expected behavior".

"Add/Update" can only be understood as "add if the sku doesn't exist, update if the sku exists". And for every other attribute of the product, the import process works like that.

Except categories - this is the only attribute where the values aren't updated, they are added to.

This is clearly wrong, and the solution cannot be that complicated - either simply check what current categories are not included in the import value, and remove them, OR, remove all current categories for the product, and then add all the categories from the import.

I am new to Magento so I don't know my way around the core code. If anybody around here is more versed and can identify where in the code categories are handled during import, I may be able to offer help fixing this bug.

Because of this bug there is currently no batch process for "moving" products from one category to another.

Was this page helpful?
0 / 5 - 0 ratings