Posted on 19/07/2024 10:55:48
I don't think the issue is related to the general cookie handling or opt-in level, but you might want to check for any cookie issues reported by the browser.
If the cookie opt-in level is set to 0 (CookieOptInLevel.None) then no cookies will be set. So if the "Dynamicweb.CookieOptInLevel" cookie has the value 0 then it might be causing the issue that you are experiencing. Otherwise, the cookie is treated as functional and will be set (unless you have added it to the tracking category or a custom category).
I think the issue here is that the cart ends up in an invalid state at some point (maybe just temporarily).
It can be difficult to detect those issues, but maybe you can try to add a notification subscriber for debugging?
Here is a subscriber with some basic debugging (you might want to include additional checks)...
[Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Order.BeforeSave)]
public sealed class DebugCartNotificationSubscriber : NotificationSubscriber
{
public override void OnNotify(string notification, NotificationArgs args)
{
var notificationArgs = (Notifications.Ecommerce.Order.BeforeSaveArgs)args;
var order = notificationArgs.Order;
if (ExecutingContext.IsBackEnd())
return;
if (!order.IsCart)
return;
var currentUserId = User.GetCurrentFrontendUserId();
var currentOrderContextId = Common.Context.CartContext?.Id;
var logger = LogManager.System.GetLogger("DebugCart");
void invalidCartError(string message)
{
var info = $"Invalid cart: {message} (Id: {order.Id}, AutoId: {order.AutoId}, StateId: {order.StateId}, UserId: {order.CustomerAccessUserId}, CurrentUserId: {currentUserId}, OrderContextId: {order.OrderContextId}, CurrentOrderContextId: {currentOrderContextId})";
logger.Error(info);
}
if (order.Complete)
invalidCartError("Complete");
if (order.Deleted)
invalidCartError("Deleted");
if (!order.IsCartEditable)
invalidCartError("Not editable");
}
}