we are currently evaluating Vendr for a shop implementation.
Our more or less single "pain-point" is that Vendr is calculating prices based on the property on the actual product. In our use-case the product price is calculated based on values the customer provides. These values will get send to an API which then returns the price.
In our case these are two dates, the selected product and some additional information.
Is it possible to set a fixed price when a product is added to the cart and disable all calculation based on the product node?
Nik is pretty close but the IProductCalculator is only used when you ask a ProductSnapshot to calculate a price, which usually only occurs when you want to display the product price on a product page.
What you would want to use is an IOrderLineCalculator as this is used for calculating the price on an order line during order calculation, ie, after the item is added to the order.
There are two approaches you could take here:
Which I think might be what you are thinking, is to do the price calculation externally in your own code, then store the product price on the order line as a property. You could then implement a custom IOrderLineCalculator that in it's CalculateOrderLineUnitPrice you check to see if the order line property is defined, and if it is, return that price for the order line. If not, and assuming you inherit from our base calculator, then you could fallback to the original calculation logic (for order lines where there isn't a defined price).
Rather than storing the price on the order line manually, you store the details that price is based upon and then in the IOrderLineCalculator you put your logic here for getting the price. You could then cache the result (possibly using our PriceFreezer to store the returned unit price).
The two are essentially the same, it just depends where you want to put your calculation logic.
I have the same situation (I'm using Umbraco 8 + Vendr 1.8), the product's price is calling from API but to add a product to the cart, I still need to add a vendr: Price property to my product content type and set a dummy price to my products. Is there any way to avoid the adding dummy price like that? I expect have no price properties if possible.
If you didn't want to have a price property on your node, you'd probably need to override the default Product Adapter (https://vendr.net/docs/core/3.0.0/key-concepts/product-adapters/) and change how it return no value for the Price property of the product snapshot.
Dynamic price from API for products
Hi,
we are currently evaluating Vendr for a shop implementation. Our more or less single "pain-point" is that Vendr is calculating prices based on the property on the actual product. In our use-case the product price is calculated based on values the customer provides. These values will get send to an API which then returns the price.
In our case these are two dates, the selected product and some additional information.
Is it possible to set a fixed price when a product is added to the cart and disable all calculation based on the product node?
Regards David
Hi David,
I'm pretty sure you can. I think you can create your own ProductCalculator which is responsible for calculating the prices of an order line.
https://vendr.net/docs/core/1.5.0/key-concepts/calculators/#content
You might need a "OrderLineCalculator" though
Cheers
Nik
Nik is pretty close but the
IProductCalculator
is only used when you ask aProductSnapshot
to calculate a price, which usually only occurs when you want to display the product price on a product page.What you would want to use is an
IOrderLineCalculator
as this is used for calculating the price on an order line during order calculation, ie, after the item is added to the order.There are two approaches you could take here:
IOrderLineCalculator
that in it'sCalculateOrderLineUnitPrice
you check to see if the order line property is defined, and if it is, return that price for the order line. If not, and assuming you inherit from our base calculator, then you could fallback to the original calculation logic (for order lines where there isn't a defined price).IOrderLineCalculator
you put your logic here for getting the price. You could then cache the result (possibly using our PriceFreezer to store the returned unit price).The two are essentially the same, it just depends where you want to put your calculation logic.
Hope this helps
Matt
Hi Matt,
I have the same situation (I'm using Umbraco 8 + Vendr 1.8), the product's price is calling from API but to add a product to the cart, I still need to add a vendr: Price property to my product content type and set a dummy price to my products. Is there any way to avoid the adding dummy price like that? I expect have no price properties if possible.
Could you give some advices?
Thanks, Nick
If you didn't want to have a price property on your node, you'd probably need to override the default Product Adapter (https://vendr.net/docs/core/3.0.0/key-concepts/product-adapters/) and change how it return no value for the Price property of the product snapshot.
Thanks Matt, it works. Here's my code:
Cheers, Nick
Hi Matt,
sorry for the late response, needed some time to test it all out. :)
We decided to go with the property and custom OrderLineCalculator which works like a charm.
Setting the property:
order.WithOrderLine(orderLine.Id).SetProperty("apiPrice", "15");
Calculator:
Thanks for the help!
Fantastic!
And thanks for sharing your working code. I’m sure that’ll come in real handy for others wishing to do similar 🙌🏻
is working on a reply...