Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 12, 2022 @ 11:07
    David Brendel
    0

    Can't update order from scheduled job

    Hi Matt,

    I'm currently trying to update orders out of a scheduled job. The code runs through without any problems/errors but the order itself isn't updated. I don't have any error logs either.

    The code which updates the order looks like this:

    using var uow = _vendrApi.Uow.Create();
    var writableOrder = orderSearchResult.AsWritable(uow);
    writableOrder.SetOrderStatus(successOrderStatus);
    writableOrder.SetProperties(new Dictionary<string, string>
    {
        { Constants.Checkout.Order.ApiResponse.BookingCode, bookingResponse.BookingCode },
        { Constants.Checkout.Order.ApiResponse.IdentificationId, bookingResponse.IdentificationId },
    });
    _orderService.SaveOrder(writableOrder);
    uow.Complete();
    

    This code runs for every order which is in a specific failed state as we have to send them over a third party api. The job runs every 30min and grabs every order in the specific state like this:

    var orderSearchResults = _vendrApi
        .SearchOrders(x =>
                        x.FromStore(store.Id).And(x.HasOrderStatus(failedOrderStatus.Id)), itemsPerPage: 100);
    

    Any hints what could cause the saving to not happen?

    Regards David

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 12, 2022 @ 12:32
    Matt Brailsford
    0

    Hi David,

    It looks OK to me.

    Usually where there is no error it's often because there is something somewhere creating a UoW that doesn't get completed and so chain of units fails and is rolled back.

    Do you have any event handlers or anything that could be failing to call complete on a UoW?

    Matt

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 13, 2022 @ 06:45
    David Brendel
    0

    Hi Matt,

    there are no event handlers that we use. At least none from Vendr or where we try to manipulate an order.

    Every other place where we change properties or status, everything is saved properly. Is there a way to see if the UoW isn't completed properly?

    David

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 13, 2022 @ 07:43
    Matt Brailsford
    0

    Unfortunately our UoW (currently) wraps Umbraco's IScope and it doesn't really give you much info as to why a scope was ended.

    Have you looked in the DB to see if the order was actually updated and maybe it's just the cache that is stale?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 14, 2022 @ 13:40
    David Brendel
    0

    Hi Matt,

    so I tried again today. The DB entry hasn't updated after I tried it. Strange thing I found is that I could add a tag to the order. And that saved perfectly.

    Will try a bit more. Little strange behaviour that the tag is saved.

    David

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 14, 2022 @ 13:44
    Matt Brailsford
    0

    Hmm, that is weird.

    Maybe create an event handler for "order saving" or something and do some extra logging to see if you have something overwriting it for some reason?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 14, 2022 @ 14:07
    David Brendel
    0

    Ok one more test and it seems that setting the order status is the issue. I could execute the code this way and the order was saved without issue. When I set the new order status nothing happens.

    So this works:

    using var uow = _vendrApi.Uow.Create();
    var writableOrder = orderSearchResult.AsWritable(uow);
    writableOrder.RemoveTag("Test");
    //writableOrder.SetOrderStatus(successOrderStatus);
    writableOrder.SetProperties(new Dictionary<string, string>
    {
        { Constants.Checkout.Order.ApiResponse.BookingCode, "bla!" },
        { Constants.Checkout.Order.ApiResponse.IdentificationId, "identification bla!" },
    });
    _vendrApi.SaveOrder(writableOrder);
    uow.Complete();
    

    WIll try adding a handler and see if that gives some clues.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 14, 2022 @ 14:21
    Matt Brailsford
    0

    Ahhh, I think the issue might be that your SearchOrder is searching unfinalized orders too (you'll need to add to the where clause if you only want finalized orders) and then I think this is causing an issue I've seen somewhere else (which has recently been fixed) in that, our activity logger would log when an order status changed, but it assumed only finalized orders would have their status changed. Because you are pulling back all orders (even carts) you are probably changing the status of some unfinalized orders and so that is causing the activity logger to fail.

    You'll either need to filter your search further to exclude unfinalized orders, or if you need to handle carts too, you might need to remove the LogOrderStatusChangeActivity domain event (let me know if you need this and I'll shared the code to do it as Domain events aren't meant to be "changed" by users)

    Matt

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 25, 2022 @ 13:03
    David Brendel
    0

    Hi Matt,

    sorry for the late response, I was on holiday last week.

    I tried the NotificationHandler to see if everything is set correctly. If I change the status of the order the "saved" one is never called.

    I checked and the order is correctly set to finalized.

    So I guess for whatever reason the domain event prevents the order from being saved. Not sure why.

    Can you point me on how to remove or change the domain event so I can maybe check what is causing the problem.

    David

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 25, 2022 @ 13:38
    Matt Brailsford
    100

    Hey David,

    That's very strange if the order is finalized. You can try removing the domain even with the following

    builder.WithCollectionBuilder<EventHandlerCollectionBuilder<OrderStatusChanged>>()
    .Remove<LogOrderStatusChangeActivity>();
    

    Let me know if that works.

    Matt

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Apr 26, 2022 @ 06:33
    David Brendel
    0

    Thanks Matt!

    That did the trick and now everything is updating. Not sure what prevents it when the domain event is active but I take it for now. :)

Please Sign in or register to post replies

Write your reply to:

Draft