Custom Tax Provider

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
jguengerich
Commodore (COMO)
Commodore (COMO)
Posts: 436
Joined: Tue May 07, 2013 1:59 pm

Custom Tax Provider

Post by jguengerich » Thu May 16, 2013 9:36 am

Using AbleCommerce GOLD build 5410.

I am trying create a custom tax provider. I have followed the Wiki article here:http://wiki.ablecommerce.com/index.php/ ... x_Provider

I wanted to start with something simple to prove that I could make it work, so for now, my Calculate method simply sums the NetExtendedPrice for each basket item and returns 7% of that. It also uses CommerceBuilder.Utility.Logger.Debug() to log the return value. However, no tax is showing up on the order and no message is showing up in the log. The ConfigData field in the ac_TaxGateways table has "Enabled=True". I am not getting any erros. So I have a few questions:

1. The Wiki page talks about "adding line items to the basket for each line item". Also, the existing line items already have tax fields. If I only want to calculate the tax on the total, do I need to add line items and/or fill in the tax field on the existing line items, or can I just return the total tax?
2. Do I need to have a Tax Code and/or Tax Rule defined? If so, how do I indicate that it/they should use my tax provider?
3. Am I using CommerceBuilder.Utility.Logger.Debug() correctly - i.e. does it create a message that shows up on the Help > Error Log page?
4. Are there other things I need in the "ConfigData" field of the ac_TaxGateways table?

Any other suggestions / help anyone could provide on creating a custom tax provider would be appreciated. Thanks.
Jay

jguengerich
Commodore (COMO)
Commodore (COMO)
Posts: 436
Joined: Tue May 07, 2013 1:59 pm

Re: Custom Tax Provider

Post by jguengerich » Thu May 16, 2013 12:30 pm

Well, after setting up a tax rule and watching what happened in the database when building a cart and checking out, I managed to figure out some answers to my questions.

1. You do need to add a BasketItem to the Basket, so I did it like this:

Code: Select all

taxItem = new BasketItem(0, basket, null, "Sales Tax:", basketTax, 0m, 1, (short)OrderItemType.Tax, 0, DateTime.UtcNow, DateTime.UtcNow, 0m, 0m);
basket.Items.Add(taxItem);
basketTax is my calculated total tax. Yes, I could have written that as one line, but I figured I might want to do other things with taxItem later :) .

2. I left a Tax Code defined, but no Tax Rules. My tax provider code checks the product info to see the product has the tax code set.

3. CommerceBuilder.Utility.Logger.Debug() didn't seem to be doing anything, but CommerceBuilder.Utility.Logger.WriteProviderLog() does write to a text file in App_Data\Logs:

Code: Select all

Logger.WriteProviderLog("MyTaxProvider", "Calculate", "Total tax was " + basketTax.ToString());
4. I guess nothing else is required, because it is working.
Jay

Post Reply