Developer forum

Forum » Development » Foreign key constraint for deleting an order

Foreign key constraint for deleting an order

Anders Ebdrup
Anders Ebdrup
Reply

Hi DW,

 

I have an issue with deleting an order by the api as we got this error:

The DELETE statement conflicted with the REFERENCE constraint "DW_FK_EcomOrderLines_EcomOrders"

If I look in the code we have this function:

        Public Shared Sub Delete(id As String)
            Dim args As New Notifications.Ecommerce.Order.BeforeDeleteArgs(id)
            NotificationManager.Notify(Notifications.Ecommerce.Order.BeforeDelete, args)

            If args.StopExecution Then Exit Sub

            Database.ExecuteNonQuery(CommandBuilder.Create("UPDATE R SET R.[RecurringOrderEndDate] = GETDATE() FROM [EcomRecurringOrder] R LEFT JOIN [EcomOrders] O ON R.RecurringOrderId = O.OrderRecurringOrderId WHERE (O.[OrderID]  = {0} AND (R.[RecurringOrderStartDate] IS NULL OR R.[RecurringOrderBaseOrderID] = {0}))", id))

            Dim query As String = "DELETE FROM EcomOrders WHERE OrderID = '" & id & "'"
            Database.ExecuteNonQuery(query)
            query = "DELETE FROM EcomOrderLines WHERE OrderLineOrderID = '" & id & "'"
            Database.ExecuteNonQuery(query)
            query = "DELETE FROM EcomOrderDebuggingInfo WHERE OrderDebuggingInfoOrderID = '" & id & "'"
            Database.ExecuteNonQuery(query)
            query = " update AccessUser set AccessUserCartID= '' where AccessUserCartID='" & id & "'"
            Database.ExecuteNonQuery(query)

            NotificationManager.Notify(Notifications.Ecommerce.Order.AfterDelete, New Notifications.Ecommerce.Order.AfterDeleteArgs(id))
        End Sub

I would mean that "DELETE FROM EcomOrders ..." should be after deleting orderlines and debug info to avoid with conflict?

 

Best regards, Anders


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Anders

Looks odd - good catch! I've created the bug TFS#37853, made a fix that will be available with the next update of Dynamicweb.Ecommerce package for 9.2 and 9.3

BR Nicolai

Votes for this answer: 1
 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Anders

The problem TFS#37583 "Foreign key constraint for deleting an order" has now been fixed in 9.3+ versions

You are able to find this build in the download section:

http://doc.dynamicweb.com/releases-and-downloads/releases

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum