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

Mass-adding products to category fails. #414

Closed
reviskar opened this issue May 4, 2017 · 6 comments
Closed

Mass-adding products to category fails. #414

reviskar opened this issue May 4, 2017 · 6 comments
Assignees
Labels

Comments

@reviskar
Copy link

reviskar commented May 4, 2017

Mass-adding products to category results in duplicate entry insert.

Preconditions

Magento Version : CE 2.1.5 && CE 2.1.6
ElasticSuite Version : 2.3.4 && 2.3.5

Environment : Dev/Prod

Third party modules : -

Steps to reproduce

  1. Go to Products->Categories
  2. Open tab "Products in Category"
  3. Search for some products
  4. Select all using "select all checkbox" in the top left corner of the table
  5. Hit "Save"

Expected result

  1. All products saved to the category with no errors present

Actual result

  1. An error occurs: Something went wrong while saving the category.
  2. Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
  3. PDO EXCEPTION:INSERT INTOcatalog_category_product (category_id,product_id,position) VALUES (?, ?, ?), (?, ?, ?)

What I think that happens is, that the "Select all" checkbox is treated as a product checkbox, so vendor/magento/module-catalog/Model/ResourceModel/Category.php:391 gets an element that is with the string 'on' as an array key. That translates into a product array element with product_id => 0. When trying to save that element an exception is thrown.
I've just re-validated this error with a fresh magento install and only "smile/elasticsuite" as a composer dependancy.

Thanks in advance.

@romainruaud
Copy link
Collaborator

Hello @reviskar and thank you for submitting this issue.

Does this occur only with ElasticSuite enabled ?

I will take a look on this one,

@reviskar
Copy link
Author

reviskar commented May 4, 2017

Hi and thanks for the fast reaction!

Yeah. Just to be sure I installed fresh Magento CE 2.1.6, added a few products, did everything as mentioned in "Steps to reproduce" and confirmed everything worked in vanilla Magento2. Then used composer to require smile/elasticsearch and got the error described above.

At the moment, as a very, very messy hotfix, I've created a patch that adds a check to the Category Resource class.

@romainruaud
Copy link
Collaborator

Okay,

I reproduce your bug on my environment, I will try to provide a fix for this one.

Best regards,

@afoucret
Copy link
Contributor

PR have been merged.

@vseager
Copy link
Contributor

vseager commented Dec 4, 2020

I have got this exact issue on Magento 2.4.1 and Elasticsuite 2.10.3

@OvalMedia
Copy link

2.10.5 / magento 2.4.2-p1: problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants