public static coreModel.TaxEvaluationContext ToTaxEvaluationContext(this WorkContext workContext, IEnumerable <Product> products = null) { var retVal = new coreModel.TaxEvaluationContext { Id = workContext.CurrentStore.Id, Currency = workContext.CurrentCurrency.Code, Type = "", Customer = new coreModel.Contact { Id = workContext.CurrentCustomer.Id, Name = workContext.CurrentCustomer.UserName } }; if (products != null) { retVal.Lines = products.SelectMany(x => x.ToListAndSaleTaxLines()).ToList(); } return(retVal); }
public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart cart) { var retVal = new coreModel.TaxEvaluationContext { Id = cart.Id, Code = cart.Name, Currency = cart.Currency.Code, Type = "Cart", Lines = new List <coreModel.TaxLine>() }; foreach (var lineItem in cart.Items) { var extendedTaxLine = new coreModel.TaxLine { Id = lineItem.Id, Code = "extended", Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.ExtendedPrice.Amount }; retVal.Lines.Add(extendedTaxLine); var listTaxLine = new coreModel.TaxLine { Id = lineItem.Id, Code = "list", Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.ListPrice.Amount }; retVal.Lines.Add(listTaxLine); if (lineItem.ListPrice != lineItem.SalePrice) { var saleTaxLine = new coreModel.TaxLine { Id = lineItem.Id, Code = "sale", Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.SalePrice.Amount }; retVal.Lines.Add(saleTaxLine); } } foreach (var shipment in cart.Shipments) { var totalTaxLine = new coreModel.TaxLine { Id = shipment.Id, Code = "total", Name = shipment.ShipmentMethodCode, TaxType = shipment.TaxType, Amount = (double)shipment.Total.Amount }; retVal.Lines.Add(totalTaxLine); var priceTaxLine = new coreModel.TaxLine { Id = shipment.Id, Code = "price", Name = shipment.ShipmentMethodCode, TaxType = shipment.TaxType, Amount = (double)shipment.ShippingPrice.Amount }; retVal.Lines.Add(priceTaxLine); if (shipment.DeliveryAddress != null) { //*** alex fix shipping address & customerId to the taxevalcontext retVal.Address = new coreModel.Address { FirstName = shipment.DeliveryAddress.FirstName, LastName = shipment.DeliveryAddress.LastName, Organization = shipment.DeliveryAddress.Organization, Line1 = shipment.DeliveryAddress.Line1, Line2 = shipment.DeliveryAddress.Line2, City = shipment.DeliveryAddress.City, PostalCode = shipment.DeliveryAddress.PostalCode, RegionId = shipment.DeliveryAddress.RegionId, RegionName = shipment.DeliveryAddress.RegionName, CountryCode = shipment.DeliveryAddress.CountryCode, CountryName = shipment.DeliveryAddress.CountryName, Phone = shipment.DeliveryAddress.Phone, AddressType = ((int)shipment.DeliveryAddress.Type).ToString() }; } retVal.Customer = new coreModel.Contact { Id = cart.CustomerId, Name = cart.CustomerName }; //*** end alex fix shipping address & customerId to the taxevalcontext } return(retVal); }
public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart cart) { var retVal = new coreModel.TaxEvaluationContext { Id = cart.Id, Code = cart.Name, Currency = cart.Currency.Code, Type = "Cart", Lines = new List <coreModel.TaxLine>() }; foreach (var lineItem in cart.Items) { var extendedTaxLine = new coreModel.TaxLine { Id = lineItem.Id + "&extended", Code = lineItem.Sku, Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.ExtendedPrice.Amount }; retVal.Lines.Add(extendedTaxLine); var listTaxLine = new coreModel.TaxLine { Id = lineItem.Id + "&list", Code = lineItem.Sku, Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.ListPrice.Amount }; retVal.Lines.Add(listTaxLine); if (lineItem.ListPrice != lineItem.SalePrice) { var saleTaxLine = new coreModel.TaxLine { Id = lineItem.Id + "&sale", Code = lineItem.Sku, Name = lineItem.Name, TaxType = lineItem.TaxType, Amount = (double)lineItem.SalePrice.Amount }; retVal.Lines.Add(saleTaxLine); } } foreach (var shipment in cart.Shipments) { var totalTaxLine = new coreModel.TaxLine { Id = shipment.Id + "&total", Code = shipment.ShipmentMethodCode, Name = shipment.ShipmentMethodCode, TaxType = shipment.TaxType, Amount = (double)shipment.Total.Amount }; retVal.Lines.Add(totalTaxLine); var priceTaxLine = new coreModel.TaxLine { Id = shipment.Id + "&price", Code = shipment.ShipmentMethodCode, Name = shipment.ShipmentMethodCode, TaxType = shipment.TaxType, Amount = (double)shipment.ShippingPrice.Amount }; retVal.Lines.Add(priceTaxLine); if (shipment.DeliveryAddress != null) { //*** alex fix shipping address & customerId to the taxevalcontext retVal.Address = shipment.DeliveryAddress.ToCoreServiceModel(); retVal.Address.AddressType = ((int)shipment.DeliveryAddress.Type).ToString(); } retVal.Customer = new coreModel.Contact { Id = cart.CustomerId, Name = cart.CustomerName }; //*** end alex fix shipping address & customerId to the taxevalcontext } return(retVal); }