Best practice for custom price on an item set by the customer
Hi Matt.
We are using VEDNR version 1.8.6.
What would be the best practice for a customer to be able to set a price on an item by them self?
Here is the scenario:
We sell a flower bucket in 3 different sizes like: small (15gp), medium (30gp) and large (60gp). But we would like a 4th option "Custom price", where the customer can set a price by them self. The price has to be minimum, lets say 10gp. And in this scenario the customer want to spend 100gp on a flower bucket.
The best way to handle this would be when the adding the product to the cart, capture the amount the customer wishes to pay and store it as an order line property on the given order line. Then extend the default OrderLineCalculator and override the CalculateOrderLineUnitPrice method, checking to see if the order line has this property and if so, return that value as the order line unit price. If the property isn't there, then have it fallback to the default implementation.
// In a Controller
using (var uow = _vendrApi.Uow.Create(autoComplete: true))
{
var order = _vendrApi.GetOrCreateCurrentOrder(storeId)
.AsWritable(uow)
// Where do i set the custom price?
.AddProduct(productReference, variantReference, Convert.ToDecimal(quantity))
// Maybe like this?
.SetProperty("customprice", "100.00");
_vendrApi.SaveOrder(order);
}
// Do we need to add this somewhere?
public class MyOrderLineCalculator : OrderLineCalculator
{
public MyOrderLineCalculator(ITaxService taxService, IStoreService storeService, IProductPriceFreezerService productPriceFreezerService) : base(taxService, storeService, productPriceFreezerService) { }
public override Price CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
{
// What to do here?
return base.CalculateOrderLineUnitPrice(order, orderLine, currencyId, taxRate);
}
}
Best practice for custom price on an item set by the customer
Hi Matt.
We are using VEDNR version 1.8.6.
What would be the best practice for a customer to be able to set a price on an item by them self?
Here is the scenario:
We sell a flower bucket in 3 different sizes like: small (15gp), medium (30gp) and large (60gp). But we would like a 4th option "Custom price", where the customer can set a price by them self. The price has to be minimum, lets say 10gp. And in this scenario the customer want to spend 100gp on a flower bucket.
How would we be able to achive that?
Hi Bo,
The best way to handle this would be when the adding the product to the cart, capture the amount the customer wishes to pay and store it as an order line property on the given order line. Then extend the default
OrderLineCalculator
and override theCalculateOrderLineUnitPrice
method, checking to see if the order line has this property and if so, return that value as the order line unit price. If the property isn't there, then have it fallback to the default implementation.Hope this helps
Matt
Hi Matt.
Is it possible to give an example?
Maybe like this?
Yup, exactly that 👍
When adding the product, you'd do something like
Great.
I think we would still add it as variant.
is working on a reply...