Developer forum

Forum » Integration » Standard Live Integration sends order to ERP even when the series hasn't started yet

Standard Live Integration sends order to ERP even when the series hasn't started yet

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

When I create a subscription using recurring orders and indicate I don't want to start until a future date (say, tomorrow), the order process completes fine, creates the recurring order to start tomorrow but then *also sends the order to the ERP*! That shouldn't happen as it would create the order there immediately, and not tomorrow.

Two questions:

1. Can this be improved in standard live integration?

2. What can I do today t prevent this without  a new version of LI? I think I can subscribe to Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Order.OnBeforeSendingOrderToErp and Cancel the submission when it's a recurring order and its first date is in the future. But how do I find this out? Do I use the RecurringOrder class and load an instance with the Order's RecurringOrderId and then check the StartDate or is there a simpler way?

Thanks!

Imar


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Imar

I believe it can become a feature that recurring order templates are kept in Dynamicweb and only actual orders are send to ERP.

You can use RecurringOrder.GetRecurringOrderByTemplateId to get hold of the recurring series - it has a StartDate and a nexteDeliverydate that you can use.

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks, yes, it would make sense to have this as a standard feature.

I'll try GetRecurringOrderByTemplateId and see if that works. However, I think previously the BaseOrderId was empty or null on the recurring order by the time my code ran so it may not give me what I need. I have added more logging to our code to find out what data is available and when and switch to your solution when possible. For now, I have this, which seems to get the job done:

[Subscribe(Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Order.OnBeforeSendingOrderToErp)]
public class DoNotSendRecurringOrderThatHasNotStarted : NotificationSubscriber
{
  private static readonly ILogger Logger = LogManager.Current.GetLogger(nameof(DoNotSendRecurringOrderThatHasNotStarted));
  
  public override void OnNotify(string notification, NotificationArgs args)
  {
    var localArgs = (Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Order.OnBeforeSendingOrderToErpArgs)args;
    if (!localArgs.CreateOrder || localArgs.Order.RecurringOrderId == 0)
    {
      return;
    }
    var recurringOrder = RecurringOrder.GetRecurringOrderById(localArgs.Order.RecurringOrderId);
    if (recurringOrder == null)
    {
      return;
    }
    if (recurringOrder.StartDate.HasValue && recurringOrder.StartDate.Value > DateTime.Now)
    {
      Logger.Info("Canceling submission to ERP because order is in the future");
      localArgs.Cancel = true;
      return;
    }
    Logger.Info("Not canceling submission to ERP because order is NOT in the future");
  }
}

Thanks,

Imar

 

You must be logged in to post in the forum