-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Adding 2 configurable products to cart with custom options causes Integrity constraint violation #7488
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
Comments
Is there a workaroud for this issue in order to add consecutive products (with custom options) to the cart? Maybe some way of reseting the cart before adding the second product? I'm almost sure the error is due to some mixing/garbage information from the first added product affecting the next one to be added. |
This is far from acceptable but since there's no update or aknowledgement of this issue, here is my workaround to insert more than one product with custom options to the cart:
|
Hi @veloraven Did you guys have the chance to take a look into this issue? This is still present in 2.1.3 The sample code in the OP uses object manager to make it easier to copy/reproduce. The actual code I'm using uses DI as best practices suggest. |
Problem still present in 2.1.4... :-( |
I found a quick fix. The problem is the item is not set correctly on item option. Magento\Quote\Model\Quote\Item::saveItemOption (around line 732 : magento 2.1.4)
There must be an issue during the process of addProduct to the quote. |
I also faced similar issue with few customized product. In my case the add to cart with custom options work fine. But I get the same exact issue when I reorder the same customized product. As @eInyzant suggested I can add option to the quote item by using plugin on Any suggestions on this why it's happening on reorder? We are stuck with the development due to this issue right now. Any fix or suggestion would be a life saver for us now. Edit |
This is caused by cache corruption. The easiest fix is to clone a product instance in _prepareProduct() (Magento\ConfigurableProduct\Model\Product\Type\Configurable:958): if ($subProduct) {
$subProduct = $this->getProductByAttributes($attributes, $product);
} change to: if ($subProduct) {
$subProduct = clone $this->getProductByAttributes($attributes, $product);
} Not sure if there is some better solution for the problem. Let me know if more details are needed. |
Any update on this issue? In which version will be resolved? |
Also running into this problem. Need to add the product in two separate requests. Above solutions did not fix it. |
@pguedesbr, thank you for your report. |
[Magento 2.2.0] Before: In fact I have a plugin ( |
More understanding the custom option issue, I have a problem, the configurable product's custom options are missing when click 'add to cart' button. But only a few products are missing, we need deleted the option and re-created them to resume the function. But we have found the issue still occurs after the day but a different configurable product. Thanks |
Have any found the solution i am also facing the same issue ? thanks |
If you debug inside saveItemOptions() you can see that $option has item_id equal to null. |
@magento-engcom-team could you please check the status of MAGETWO-84526 ? Thanks |
Hi,
If anyone has exact code/patch for a workaround would be great. |
Hello @pguedesbr @vflirt @elioermini Thank you for contribution and collaboration! The initially described issue was fixed in the scope of #13036 PR by @vinayshah |
Hi!, Some solution? Same problem in magento 2.2.5. |
Understanding this issue is closed, however i'd like to comment that the fix for this issue may have introduced a different problem. I have a very similar scenario where I add a configurable product to the cart via code twice. The same product, but with different lengths. I noticed that when adding the second product, it used the options of the first product. I triple checked my code. It seems like a cache issue with a product instance. Using the above solution - cloning a product instance fixes the problem for me and adding the same product twice to cart shows both products. |
@aliomattux thank you. I encountered the same issue when trying to add a configurable product to the quote twice with different options, but nothing worked as expected. The solution, after many hours of searching, was to clone the product in my loop.
|
Uh oh!
There was an error while loading. Please reload this page.
Preconditions
Steps to reproduce
Expected result
Actual result
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`quote_item_option`, CONSTRAINT `QUOTE_ITEM_OPTION_ITEM_ID_QUOTE_ITEM_ITEM_ID` FOREIGN KEY (`item_id`) REFERENCES `quote_item` (`item_id`) ON DELETE CASCADE), query was: INSERT INTO `quote_item_option` (`product_id`, `code`, `value`) VALUES (?, ?, ?)
For 2.1.10 version and later it can be reproduced with the little different scenario:
The text was updated successfully, but these errors were encountered: