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