Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Taxing the shipping charge View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 3/27/2009 10:27:22 AM
   
Taxing the shipping charge
How can I add tax for the shipping charge of an order?
I need to be able to tax it in much the same way as a product.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/31/2009 6:51:28 AM
   
RE:Taxing the shipping charge
Hello,

unfortunately, we do not support taxes of shipping charge by default. However, you could develop a custom provider to make it work. Please see here: http://devnet.kentico.com/docs/ecommerceguide/customshippingoptioninfoprovid.htm for more information.

Best regards,
Helena Grulichova

User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 4/1/2009 5:20:44 AM
   
RE:Taxing the shipping charge
I can't seem to find the provider to customise that calculates the tax for an order. I need to be able to use my own calculation of the items in the cart and then add tax for the shipping charge.

Regards
Nick

User avatar
Kentico Support
Kentico Support
kentico_radekm - 4/1/2009 7:09:45 AM
   
RE:Taxing the shipping charge
Hello Nick.

You can modify CalculateShipping method with your custom code. Please see following link for more details and example: http://devnet.kentico.com/docs/ecommerceguide/overview10.htm

Best Regards,
Radek Macalik

User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 4/1/2009 7:40:54 AM
   
RE:Taxing the shipping charge
I see this would allow me to modify the shipping charge but how can I get the associated tax into the Total Tax column of the order?
Regards
Nick

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/2/2009 10:44:41 AM
   
RE:Taxing the shipping charge
Hi,

do you mean to add it to total tax directly in the Order or during checkout process into the ShoppingCart? Could you please be more specific?

Regards,
Zdenek C.

User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 4/3/2009 5:41:57 AM
   
RE:Taxing the shipping charge
Zdenek

I need to add the tax during checkout.

For example customer adds two products at $10 each both are taxable at 10%. When the user checks out they select a shipping charge at 5$ also taxable at 10%.
I want the calculation to be;

Item A $10 @ 10% = $1 Tax
Item B $10 @ 10% = $1 Tax
Shipping $5 @ 10% = $0.5 Tax

Total Tax = $2.5

I can't find where to modify the checkout process to achieve this?

I hope this is clear.

Nick

User avatar
Member
Member
alexspurzem-me - 4/5/2009 11:35:11 PM
   
RE:Taxing the shipping charge
I have the exact same problem. I have configured 10% GST for Australia and it is correctly applied to products. How do I get it to apply it to shipping as well?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/27/2009 9:47:43 AM
   
RE:Taxing the shipping charge
Hi,

the checkout process could be modified in more ways, usually it involves changing some checkout step's ascx control (E-commerce guide article).

In this case however, we need further integration into system, so that the taxes could appear in order and invoice and also during checkout.

I'm very sorry for the delay with bringing this solution.

Below please find sample code of involved methods and all needed changes.

Important notes:
The code works fine in my setup, however it is not thoroughly tested yet.
It doesn't count with subjects freed from paying taxes (supplied Tax ID), but this can be done quite easily.
It also doesn't count with flat fees (absolute tax value), but I suppose this is never used...
For the future usage, some optimalizations should be done.


here it goes:
1. Calculate tax in CalculateShipping and 2. Store tax in Hashtable steps are in the CalculateShipping method
(the code is in CustomShippingOptionInfoProvider.cs from the custom ecommerce providers project.)

...

public double CalculateShipping(object cartObj, string siteName)
{

CMS.Ecommerce.ShoppingCartInfo cart = cartObj as CMS.Ecommerce.ShoppingCartInfo;

if (cart != null)
{
// Get shipping address details
CMS.Ecommerce.AddressInfo address = CMS.Ecommerce.AddressInfoProvider.GetAddressInfo(cart.ShoppingCartShippingAddressID);
if (address != null)
{
// Get shipping address country and state
CountryInfo country = CountryInfoProvider.GetCountryInfo(address.AddressCountryID);
StateInfo state = StateInfoProvider.GetStateInfo(address.AddressStateID);

// Add tax to standard shipping price for countries/states with specified "ShippingTax"
CMS.Ecommerce.TaxClassInfo shippingTaxClassInfo = TaxClassInfoProvider.GetTaxClassInfo("ShippingTax");

if (shippingTaxClassInfo != null)
{
// tax will be zero if no value found for state/country
double shippingTax = 0;
if (state != null)
{
CMS.Ecommerce.TaxClassStateInfo tcsi = CMS.Ecommerce.TaxClassStateInfoProvider.GetTaxClassStateInfo(shippingTaxClassInfo.TaxClassID, state.StateID);
if (tcsi != null)
{
shippingTax = tcsi.TaxValue;
}
}
else
{
CMS.Ecommerce.TaxClassCountryInfo tcci = CMS.Ecommerce.TaxClassCountryInfoProvider.GetTaxClassCountryInfo(country.CountryID, shippingTaxClassInfo.TaxClassID);
if (tcci != null)
{
shippingTax = tcci.TaxValue;
}
}

// Perform calculation of shipping charge for current shopping cart
double shippingWithoutTax = CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping(cart, siteName);

// Calculate tax amount
double calculatedShippingTax = TaxClassInfoProvider.GetTaxValue(shippingWithoutTax, shippingTax, false);

// Store calculated tax amount into shop.cart custom data
cart.ShoppingCartCustomData["ShippingTax"] = calculatedShippingTax.ToString();
cart.UpdateShoppingCartCustomData();

// Return shipping charge including calculated tax
return shippingWithoutTax + calculatedShippingTax;
}
}
}
// Get standard shipping price in other cases
return CMS.CMSEcommerce.ShippingOptionInfoProvider.CalculateShipping(cart, siteName);
}

...

The next step - 3. Get tax into tax summary in EvaluateShoppingCartContent (in the CustomShoppingCartInfoProvider.cs from the custom ecommerce providers project)
...

public void EvaluateShoppingCartContent(object shoppingCart, bool evaluateForInvoice)
{
//ShoppingCartInfoProvider.EvaluateShoppingCartContent((CMS.Ecommerce.ShoppingCartInfo)shoppingCart, evaluateForInvoice);
CMS.Ecommerce.ShoppingCartInfo cart = shoppingCart as CMS.Ecommerce.ShoppingCartInfo;
if (cart != null)
{
ShoppingCartInfoProvider.EvaluateShoppingCartContent(cart, evaluateForInvoice);

CMS.Ecommerce.TaxClassInfo tci = TaxClassInfoProvider.GetTaxClassInfo("ShippingTax");

if (cart.ShoppingCartCustomData["ShippingTax"] != null)
{
DataRow dr = cart.ShoppingCartTaxTable.NewRow();
dr["TaxClassID"] = tci.TaxClassID;
dr["TaxClassDisplayName"] = tci.TaxClassDisplayName;

// Get the added tax value from cart custom data hashtable
double taxValue = double.Parse(cart.ShoppingCartCustomData["ShippingTax"]);

// Add the shipping tax summary into the tax table
CMS.Ecommerce.ShoppingCartInfo.AddTaxSummary(cart.ShoppingCartTaxTable, dr, taxValue);
}
}
}

...

Additional step: add call of ShoppingCartInfoProvider.EvaluateShoppingCartContent(ShoppingCartInfoObj) method before "return true;" command within "try" statement in ProcessStep() method in ShoppingCartPaymentShipping.ascx.cs file. (line approx. #170). It's located in ~\CMSModules\Ecommerce\Controls\ShoppingCart\ web project folder.

Finally, you will need to add the tax class in CMSDesk / Tools / Ecommerce / Configuration / TaxClasses with codename "ShippingTax" (it must be the same string as in the code) and define values (in %) for the countries (states) where it is to be applied.

I suppose this will be turned to knowledgebase article soon after further verifications. Hopefully in the future this will be implemented into the e-comm module by default.

Thank you in advance for any further comments, suggestions and questions about this solution.

Regards,
Zdenek C.

User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 4/29/2009 6:22:14 AM
   
RE:Taxing the shipping charge
Thanks for getting back. In the end I had a crack and managed to get something similar working. I've included my solution below if it helps anyone.
One thing I had to do was in ShoppingCartPaymentShipping.ascx.cs I had to call both CalculateShipping and EvaluateShoppingCartContent to ensure the tax was calculated as the cart progressed.
Thanks again.
Nick


//ShoppingCartPaymentShipping.ascx.cs
ShippingOptionInfoProvider.CalculateShipping(ShoppingCartInfoObj, CMSContext.CurrentSiteName);
ShoppingCartInfoProvider.EvaluateShoppingCartContent(ShoppingCartInfoObj, true);


public void EvaluateShoppingCartContent(object shoppingCart, bool evaluateForInvoice)
{
CMS.Ecommerce.ShoppingCartInfo cart = shoppingCart as CMS.Ecommerce.ShoppingCartInfo;
if (cart != null)
{
ShoppingCartInfoProvider.EvaluateShoppingCartContent(cart, evaluateForInvoice);

CustomData customCartData;
customCartData = cart.ShoppingCartCustomData;
if (customCartData.GetValue("ShippingTaxValue") != null)
{
// Get Shipping Tax and update cart
double dShippingChargeTax;
dShippingChargeTax = (double)customCartData.GetValue("ShippingTaxValue");
cart.TotalTax += dShippingChargeTax;
cart.TotalItemsPrice = System.Math.Round(cart.TotalItemsPrice + dShippingChargeTax, 2);
cart.Update();

// Add the shipping tax summary into the tax table
Ecommerce.TaxClassInfo taxinfo = TaxClassInfoProvider.GetTaxClassInfo("VAT");
DataRow dr = cart.ShoppingCartTaxTable.NewRow();
dr["TaxClassID"] = taxinfo.TaxClassID;
dr["TaxClassDisplayName"] = taxinfo.TaxClassDisplayName;
CMS.Ecommerce.ShoppingCartInfo.AddTaxSummary(cart.ShoppingCartTaxTable, dr, dShippingChargeTax);

}
}
}


public double CalculateShipping(object cartObj, string siteName)
{
int stateId = 0;
int countryId = 0;
bool isTaxIDSupplied = false;
double dShippingCharge;
double dShippingChargeTax = 0;
dShippingCharge = ShippingOptionInfoProvider.CalculateShipping((CMS.Ecommerce.ShoppingCartInfo)cartObj, siteName);
CMS.Ecommerce.ShoppingCartInfo cart;
cart = (CMS.Ecommerce.ShoppingCartInfo)cartObj;

// Try to get customer billing information from existing shopping cart
if (cart != null)
{
CMS.Ecommerce.AddressInfo address = CMS.Ecommerce.AddressInfoProvider.GetAddressInfo(cart.ShoppingCartShippingAddressID);
if (address != null)
{
// Get shipping address country and state
CountryInfo country = CountryInfoProvider.GetCountryInfo(address.AddressCountryID);
StateInfo state = StateInfoProvider.GetStateInfo(address.AddressStateID);
stateId = state.StateID;
countryId = country.CountryID;
}
isTaxIDSupplied = ((cart.CustomerInfoObj != null) && (cart.CustomerInfoObj.CustomerTaxRegistrationID != ""));
}

// Use default values
if (countryId == 0)
{
stateId = 0;
countryId = 0;
isTaxIDSupplied = false;

// Use site default country
SiteInfo currentSite = CMS.CMSHelper.CMSContext.CurrentSite;
if (currentSite != null)
{
countryId = currentSite.SiteDefaultCountryID;
}
}


string key = "ProductTotalTax_" + 0 + "_" + dShippingCharge + "_" + stateId + "_" + countryId + "_" + isTaxIDSupplied;

// Try to find key total tax in cache
if (CacheHelper.Contains(key))
{
// Get product total tax form cache
dShippingChargeTax = ValidationHelper.GetDouble(CacheHelper.GetItem(key), 0);
}
// Calculate product total tax based on the data from database
else
{


Ecommerce.TaxClassInfo taxinfo = TaxClassInfoProvider.GetTaxClassInfo("VAT");
Ecommerce.TaxClassCountryInfo taxCountryinfo = Ecommerce.TaxClassCountryInfoProvider.GetTaxClassCountryInfo(countryId,taxinfo.TaxClassID);

if (taxCountryinfo != null)
{
dShippingChargeTax = CMS.CMSEcommerce.TaxClassInfoProvider.GetTaxValue(dShippingCharge, taxCountryinfo.TaxValue, taxCountryinfo.IsFlatValue);

}
// Add product total tax to the cache
CacheHelper.Add(key, dShippingChargeTax, null, DateTime.Now.AddMinutes(SettingsKeyProvider.GetIntValue(CMS.CMSHelper.CMSContext.CurrentSiteName + ".CMSCacheMinutes")), System.Web.Caching.Cache.NoSlidingExpiration);
}


CustomData customCartData;
customCartData = cart.ShoppingCartCustomData;
customCartData.SetValue("ShippingTaxValue",dShippingChargeTax);
cart.UpdateShoppingCartCustomData();
return dShippingCharge;

}