Posted on 17/11/2017 15:03:08
Hi Nicolai,
I’ve think on something like that and implemented this:
[Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.OrderIsPassedToCheckoutHandler)]
public class BeforePayment : NotificationSubscriber
{
public override void OnNotify(string notification, NotificationArgs args)
{
if (!(args is Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.OrderIsPassedToCheckoutHandlerArgs))
{
return;
}
var checkoutArgs =
(Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.OrderIsPassedToCheckoutHandlerArgs) args;
if (!PaymentLedger.IsLedger(checkoutArgs.Order))
{
return;
}
try
{
var newId = Dynamicweb.Ecommerce.Common.NumberGenerator.GetNumber("LEDGERENTRIES");
var oldId = checkoutArgs.Order.Id;
Database.ExecuteNonQuery($"UPDATE EcomOrders SET OrderID = '{newId}' WHERE OrderID = '{oldId}'");
Database.ExecuteNonQuery(
$"UPDATE EcomOrderLines SET OrderLineOrderID = '{newId}' WHERE OrderLineOrderID = '{oldId}'");
Database.ExecuteNonQuery(
$"UPDATE EcomOrderDebuggingInfo SET OrderDebuggingInfoOrderID = '{newId}' WHERE OrderDebuggingInfoOrderID = '{oldId}'");
checkoutArgs.Order.Id = newId;
}
catch (Exception anyError)
{
LogHelper.Log($"Error updating payment ledger {checkoutArgs.Order.Id}. Error = {anyError}",
PaymentLedger.Logfolder);
}
}
}
Is does work fine, and the Ledger gets the right number in the end.
Thanks,
Rui Silva