Hi there,
With the live integration we get back tax information from the ERP. Initially I created a new order line of type Tax inside ProcessResponse to set the tax. However, that line doesn't seem to stick. I then followed the same approach as with the LiveDiscountProvider and implemented and registered a custom LiveTaxProvider as follows:
using System;
using System.Web;
using Dynamicweb.eCommerce.Orders;
using Dynamicweb.eCommerce.Prices;
using Dynamicweb.eCommerce.Products.Taxes;
using Dynamicweb.Extensibility;
namespace Dynamicweb.eCommerce.LiveIntegration
{
[AddInName("Live integration sales tax"),
AddInDescription("Apply sales tax retrieved via live integration.")]
public class LiveTaxProvider : TaxProvider
{
public override void AddTaxOrderLinesToOrder(Order order)
{
var o = HttpContext.Current.Session["LiveIntegrationTax" + order.ID];
if (o != null)
{
var totalTax = (double)o;
var tax = new Tax
{
Name = Name,
Amount = new PriceRaw(totalTax, order.Currency),
CalculateVat = true
};
var taxLine = new OrderLine
{
Date = DateTime.Now,
Modified = DateTime.Now,
ProductName = tax.Name,
ProductVariantText = this.Name,
Order = order,
OrderID = order.ID,
Quantity = 1.0,
Type = Base.ChkString((int)Base.ChkInteger(OrderLine.OrderLineType.Tax)),
};
taxLine.SetUnitPrice(tax.Price);
order.OrderLines.Add(taxLine);
}
}
}
}
which does seem to do the trick. Is this required indeed? And if so, should we have something similar in the standard code? Note, in my case I am storing just the tax value in session state, but I could follow the same pattern as with discounts and store the actual lines.
Thoughts?
Imar