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?
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).
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 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.
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
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?
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 soThe 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).
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
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.
is working on a reply...