Developer forum

Forum » Development » Ledgers numbering

Ledgers numbering

Rui Silva
Reply

Hi all,

I have a solution in 9.3.6 that is going to use the ledgers feature to pay ledgers. My custom code creates a new ledger record that will be sent to the cart to be paid by a standard checkout handler. No issues until this step, and the created record has an Id like ‘LEDGER99’. When this ledger cart is passed to the checkout handler the system changes the Id to a ‘ORDER999’ that feels a little strange.

Is there any way to avoid this new Id to the Ledger cart?

Thanks,

Rui Silva


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Rui

Hm - you can this:

Create a custom field on the order to store information about your ledgerid. Then on Notifications.Ecommerce.Cart.OrderIsPassedToCheckoutHandler, check if the passed order is a ledgeritem and call order.UpdateOrderId(newOrderID) and give it your ledgerid. In this way, the ledgerid is put back on the order. It will give you 'holes' in the order id sequence though.

BR Nicolai

Votes for this answer: 1
 
Rui Silva
Reply

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

 

 
Nicolai Pedersen
Reply

ok, great. Thanks for sharing

 

You must be logged in to post in the forum