When trying to add a new item to shopping cart, getting a error message

Manoj K asked on April 29, 2019 06:07

I'm using kentico 12. With the help from the KB article(https://docs.kentico.com/k12/e-commerce-features/developing-on-line-stores/implementing-a-checkout-process/using-a-shopping-cart-on-mvc-sites#UsingashoppingcartonMVCsites-Displayingtheshoppingcart), I am trying to add a new product to the shopping cart. I am doing it as a public user. But I'm getting the following error.

"\r\n[DataConnection.HandleError]: \r\n\r\nQuery: \r\nINSERT INTO COM_ShoppingCartSKU ([ShoppingCartID], [SKUID], [SKUUnits], [CartItemCustomData], [CartItemGuid], [CartItemParentGuid], [CartItemValidTo], [CartItemBundleGUID], [CartItemText], [CartItemAutoAddedUnits]) \r\nVALUES (@ShoppingCartID, @SKUID, @SKUUnits, @CartItemCustomData, @CartItemGuid, @CartItemParentGuid, @CartItemValidTo, @CartItemBundleGUID, @CartItemText, @CartItemAutoAddedUnits);\r\n\r\nSELECT SCOPE_IDENTITY() AS [ID]\r\n\r\nCaused exception: \r\nThe INSERT statement conflicted with the FOREIGN KEY constraint \"FK_COM_ShoppingCartSKU_ShoppingCartID_COM_ShoppingCart\"."

I have checked in the DB. It is creating a new record in the ShoppingCart table but nothing in the "ShoppingCartSKU" table. And the SKU ID is valid.

Please help me. Thanks in advance.

Recent Answers

Matt Nield answered on April 29, 2019 18:15 (last edited on April 29, 2019 18:16)

The error message is saying that it couldn't create the ShoppingCartSKU record because of the constraint violation.

It's difficult to say without values, but the constraint that is being violated requires that the @ShoppingCartID value existing in COM_ShoppingCart.ShoppingCartID. If you look at the parameters, are you sure that the value that you are passing in @ShoppingCartID is correct?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.