Developer forum

Forum » Ecommerce - Standard features » Empty order created when a users cart does not exists

Empty order created when a users cart does not exists

Anders Ebdrup
Reply

Hi Dynamicweb,

 

I have a problem where an empty order is created when a user is logged in. It is due to the property "IsCart" in the "Order"-object, which is not initialized when creating a new cart, so it will then be "false" instead of "true", and when saving the new cart for the first time an empty order is created.

 

When trying to load a user's cart with code in CartCatch.vb:

                'Load user-cart
                If Not IsNothing(user) Then
                    Dim cartID As String = Base.ChkString(Context.CartSession.Get(userCartIdKey))
                    If Not String.IsNullOrEmpty(cartID) Then
                        EcomCart = If(Order.GetOrderByID(cartID), New Order())
                        If String.IsNullOrEmpty(EcomCart.ID) Then
                            'Load user-cookie-cart if no cart was loaded from session
                            Dim cookieUserKey As String = Context.ConvertKeyToCartContextAwareKey(cookieKey & user.ID)
                            If EcomCart Is Nothing AndAlso HttpContext.Current.Request.Cookies(cookieUserKey) IsNot Nothing Then
                                EcomCart = If(Order.GetOrderByID(Base.ChkString(HttpContext.Current.Request.Cookies(cookieUserKey).Value)), New Order())
                                If String.IsNullOrEmpty(EcomCart.ID) Then
                                    EcomCart = Nothing
                                End If
                            End If
                        End If
                    End If
                End If

A new cart is created here: EcomCart = If(Order.GetOrderByID(cartID), New Order()) and the property "IsCart" in the Order-object will now be false as it is not initialized, so when saving the "cart" for the first time the cart will be saved with an order id in Order.vb:



            If objDataset.Tables(0).Rows.Count > 0 Then
                objRow = objDataset.Tables(0).Rows(0)
            Else
                objRow = objDataset.Tables(0).NewRow
                objDataset.Tables(0).Rows.Add(objRow)
                If IsCart() Then
                    ID() = NumberGenerator.GetNumber("CART")
                Else
                    ID() = NumberGenerator.GetNumber("ORDER")
                End If
            End If

 

I am hoping this problem can be fixed as it is generating a lot of empty orders in the backend and in the integrated ERP-system.

 

A solution could be to change this line:

EcomCart = If(Order.GetOrderByID(cartID), New Order())

To:

EcomCart = If(Order.GetOrderByID(cartID), New Order() With {.IsCart = True, .LanguageID = Common.Context.LanguageID})

 

Best regards, Anders


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Anders,

I've implemented a fix that will be available with the next hotfox for 8.4.1.

- Jeppe

 
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Anders

The problem regarding "Empty order created when a users cart does not exists" TFS#15367  has now been fixed in version 8.4.1.12

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

http://developer.dynamicweb-cms.com/downloads/dynamicweb-8.aspx

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

Kind Regards

Dynamicweb Support

Kristian Kirkholt

Votes for this answer: 1

 

You must be logged in to post in the forum