Posted on 30/05/2023 10:18:38
Hi Jan,
then you need to implement the custom subscriber to the Live integration event: OnBeforeSendingOrderToErp
and have the code like that:
using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications;
using Dynamicweb.Environment;
using Dynamicweb.Security.UserManagement;
namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples.Notifications
{
/// <summary>
/// Class OrderBeforeSendToErpSubscriber.
/// </summary>
/// <seealso cref="NotificationSubscriber" />
[Subscribe(Order.OnBeforeSendingOrderToErp)]
public class OrderBeforeSendToErpSubscriber : NotificationSubscriber
{
/// <summary>
/// Call to invoke observer.
/// </summary>
/// <param name="notification">The notification.</param>
/// <param name="args">The args.</param>
public override void OnNotify(string notification, NotificationArgs args)
{
var myArgs = (Order.OnBeforeSendingOrderToErpArgs)args;
// TODO: Add code here
if(!myArgs.CreateOrder && ExecutingContext.IsFrontEnd())
{
var user = User.GetUserByID(myArgs.Order.CustomerAccessUserId);
if (user == null)
{
myArgs.Cancel = true;
}
}
}
}
}
And set the checkbox "Carts and orders for anonymous users" to on. Then the subscriber will cancel order sending when the order is not complete and there is no logged in user.
BR, Dmitrij