Copied to clipboard

Flag this post as spam?

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


  • Tomasz Kowalski 135 posts 445 karma points
    Jul 15, 2022 @ 12:57
    Tomasz Kowalski
    0

    Save OrderLineProperty in Custom order line calculator

    Hi,

    I have a custom OrderLineCalculator, which works fine, but I would like do save some calculation results in order line's property.

    I tried to inject IUnitOfWork, IOrderService and ISessionManager into this calculator, but I'm getting an error while starting the application:

    "Cannot consume scoped service 'Vendr.Core.Session.ISessionManager' from singleton 'Vendr.Core.Calculators.IOrderLineCalculator'."

    Fair enough. But is there other way do do it? Or do I need to rethink the price calculation process?

    Umbraco 10 and Vendr 2.3.1

    Kind regards

    Tomasz

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 15, 2022 @ 13:05
    Matt Brailsford
    0

    Tomasz.

    Generally speaking, you don't really want to write to ther order whilst it's calculating as when you save the order this will trigger a calculation to occur and you could end up in an infinite loop.

    Maybe you can explain what you are trying to achieve and I can see if there is another way?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 15, 2022 @ 13:17
    Matt Brailsford
    0

    Saying this, Recalculate must have been called on a writable order and so you may be able to modify the order that is being calculated like so

    public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
    {
        if (order is Order writableOrder) {
            writableOrder.WithOrderLine(orderLine.Id)
                .SetProperty("key", "value");
        }
    }
    

    The only thing I would say is a problem here though is that if the calculation process fails for any reason, the order line property will still have been set and so there is a risk of it being in an invalid state (should the property have to relate to the price).

  • Tomasz Kowalski 135 posts 445 karma points
    Jul 15, 2022 @ 13:22
    Tomasz Kowalski
    0

    Hi Matt,

    thanks for the quick response (as always!)

    I thought so..., I had experienced the infinite loop once i TC...

    The product has 3 rent prices: per day, week and month. I need to calculate how many monts/weeks/day is there in the rental period, but there is some specific rules that depends both on price and number of weeks. Fx. if price for 2 weeks is grater then for one month, take the cheaper one.

    As I wrote, the calculator works fine, but it will be nice to show, how the price was calculated.

    I try another approach.

    Tomasz

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

    I think I commented something that might work at the same time as you. Take a look at my other response (https://our.umbraco.com/packages/website-utilities/vendr/vendr-support/109507-save-orderlineproperty-in-custom-order-line-calculator#comment-339662) and see if that helps / works.

Please Sign in or register to post replies

Write your reply to:

Draft