I'm using Vendr v1.8.6 to build an eCommerce website with multiple warehouses, the warehouses have different tax rate and currency so I would like to dynamic generate tax rate of the orders.
I've implemented a custom OrderCalculator like this:
public class CustomOrderCalculator : IOrderCalculator
{
public OrderCalculation CalculateOrder(OrderReadOnly order)
{
OrderCalculation calculation = new OrderCalculation(order.CurrencyId);
if (order.Properties["taxrate"] != null && decimal.TryParse(order.Properties["taxrate"].Value, out decimal taxRate))
{
if (taxRate > 0)
{
calculation.TaxRate = new TaxRate(taxRate);
}
}
Pipeline.Invoke<CalculateOrderPipeline, OrderCalculationPipelineArgs, OrderCalculation>((IUnitOfWork uow) => new OrderCalculationPipelineArgs(uow, calculation, order));
return calculation;
}
}
(The 'taxrate' will be add to the order as a propety)
But it didn't work as I expected, the order's tax rate didn't change, still getting from the standard tax class that I defined before.
I think the problem is that you invoke the calculation pipeline which has a task in to to calculate the tax rate so it's just overriding your tax rate.
You might just be better off leaving the order calculator as the default and instead replace the CalculateOrderTaxRateTask in the pipeline.
public class MyCalculateOrderTaxRateTask : PipelineTaskWithTypedArgsBase<OrderCalculationPipelineArgs, OrderCalculation>
{
public override PipelineResult<OrderCalculation> Execute(OrderCalculationPipelineArgs args)
{
if (CONDITION) {
args.Calculation.TaxRate = {YOUR CALC HERE};
}
return Ok(args.Model);
}
}
Order tax rate is not accurate
Hi Matt,
I'm using Vendr v1.8.6 to build an eCommerce website with multiple warehouses, the warehouses have different tax rate and currency so I would like to dynamic generate tax rate of the orders.
I've implemented a custom OrderCalculator like this:
(The 'taxrate' will be add to the order as a propety)
But it didn't work as I expected, the order's tax rate didn't change, still getting from the standard tax class that I defined before.
Could you correct me if I'm doing wrong?
Thanks,Nick
I think the problem is that you invoke the calculation pipeline which has a task in to to calculate the tax rate so it's just overriding your tax rate.
You might just be better off leaving the order calculator as the default and instead replace the
CalculateOrderTaxRateTask
in the pipeline.then in your startup script
NB I can't fully remember if this is the API for v1 but this is the general idea
Thanks Matt, It works as a charm
Cheers, Nick
is working on a reply...