Developer forum

Forum » Development » Bug in new user registration when cart has items

Bug in new user registration when cart has items

Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

i am getting bug on new user register when items in the cart. 

   at Dynamicweb.Ecommerce.Cart.CartSession.Add(String key, Object value)
   at Dynamicweb.Ecommerce.Common.Context.SetCart(Order cart, User user, OrderContext orderContext)
   at Dynamicweb.Ecommerce.Frontend.Cart.CartService.LoadCart(User user, OrderContext orderContext)
   at Dynamicweb.Ecommerce.Common.Context.GetCart(OrderContext orderContext)
   at Dynamicweb.Ecommerce.Cart.UserSavedSubscriber.OnNotify(String notification, NotificationArgs args)
   at Dynamicweb.Extensibility.Notifications.NotificationManager.Notify(String notification, NotificationArgs eventArgs)
   at Dynamicweb.Security.UserManagement.User.Save()
   at Kids21.Service.MembersonApi.CreateProfileDW(String CustomerNumber, String Token) in D:\Dynamicweb\Source\Club21\Source\Kids21Project\Service\MembersonApi.cs:line 448

seems error generate from     Public Class UserSavedSubscriber Inherits NotificationSubscriber

 

currently using Dynamicweb.Ecommerce 1.9.54

 

 


Replies

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

I was not able to catch any issue during creating new user in checkout or via creating via Extranet when cart has product, discount and tax orderlines. Please, specify your case and specific conditions if exist. Thanks.

BR, Oleg QA  

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

here its

Dynamicweb.Security.UserManagement.User newUser = new Dynamicweb.Security.UserManagement.User();

....properties

newUser.Save();  //this generates the error 

 
Viktor Letavin Dynamicweb Employee
Viktor Letavin
Reply

Hi,

At what moment or where you trying to save user? Is it like specific request from the template which is you handling using your own api, or some notification?

BR, Viktor.

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

This application uses CRM where user sync from crm at login time. if user is not available in DW at login time we create user from internal c# code, not template level.

when you dnt have item in cart, function works fine

But when you have items in cart, this issue occurs 

 
Viktor Letavin Dynamicweb Employee
Viktor Letavin
Reply

But still is it during handling some cart/order notification? or some admin UI extension? How do you trigger the user save process? I cannot reproduct the issue if I have no identical set-up.

BR, Viktor.

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

i didnt hadle anything related to cart on this time

seems error generated from this notification    at Dynamicweb.Ecommerce.Cart.UserSavedSubscriber.OnNotify(String notification, NotificationArgs args)

 
Nicolai Pedersen
Reply

Hi Shiwanka.

You need to give us all information before starting a thread. We spend a lot of time on this...

It seems like you have created a webapi? Which is session less?

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

Hi Nicolai

yes its webapi, means we can not use dw api outside of session envirnment?

this issue only if you have item in the cart, if not it works fine...

 
Nicolai Pedersen
Reply

Hi Shiwanka.

Of course you can use the API. But parts of it is relying on the current user or cart which is handled by sessions. So when you fiddle with that in a stateless environment, you need to handle it.

You can enable session state for this endpoint.

Alternatively you can supress notifications by wrapping you code in a notification context and suppress all notifications

using (var notificationContext = new NotificationContext(NotificationContext.NotificationState.SuppressNotifications))
{
​///Your code here...
}
 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

but web api is inside same DW project. if i put this, does it going to suppress all notifications or inside using statement? 

 
Nicolai Pedersen
Reply

You can still enable session state for the controller. Google it.

If you use the above using statement with the notification context, no notifications will fire inside the using block. So you can wrap it around the User.Save() call.

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

Thanks i will try 

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

HI Nicolai

is there any suggestion to enable session with APIRegistrationBase ? 

 
Nicolai Pedersen
Reply

Just add IrequireSessionState interface should do it: https://docs.microsoft.com/en-us/dotnet/api/system.web.sessionstate.irequiressessionstate?view=netframework-4.8

 

You must be logged in to post in the forum