Posted on 07/09/2022 08:09:46
Hi Andrew,
you can use this notification subscriber in your project so it will send order to ERP once the Order was captured, see the code below.
It should be triggered after each capture event.
(you will also need to add a reference to a nuget Dynamicweb.Ecommerce.DynamicwebLiveIntegration 7.0.+ version in your project)
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration;
using Dynamicweb.Extensibility.Notifications;
namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.NotificationSubscribers
{
/// <summary>
/// Sends the order to the ERP whe it's complete.
/// </summary>
/// <seealso cref="NotificationSubscriberBase" />
[Subscribe(Ecommerce.Notifications.Ecommerce.Order.AfterOrderCaptured)]
public class CartAfterOrderCaptured : NotificationSubscriberBase
{
/// <summary>
/// Handles the notification.
/// </summary>
/// <param name="notification">The notification.</param>
/// <param name="args">The args.</param>
public override void OnNotify(string notification, NotificationArgs args)
{
if (args != null)
{
var myArgs = (Ecommerce.Notifications.Ecommerce.Cart.CheckoutDoneOrderIsCompleteArgs)args;
if (myArgs.Order == null || myArgs.Order.OrderLines.Count <= 0)
{
return;
}
string shopId = myArgs.Order.ShopId;
Settings settings = SettingsManager.GetSettingsByShop(shopId);
if (!EnabledAndActive(settings))
{
return;
}
if (settings != null && Global.EnableCartCommunication(settings, myArgs.Order.Complete))
{
if (myArgs.Order.Complete && myArgs.Order.Currency != Common.Context.Currency)
{
// This can happen when redirected back from some CheckOut handler
// Common.Context.Currency can be set to the default Application currency,
// while the completed order can be in another currency
Common.Context.Currency = myArgs.Order.Currency;
}
bool? result = OrderHandler.UpdateOrder(settings, myArgs.Order, SubmitType.LiveOrderOrCart);
}
}
}
}
}
BR, Dmitrij