Recently I have been working on a new e-commerce site for Onyx Group. The site, everfan.com, uses the latest version of Drupal, in addition to using the newest version of Drupal Commerce. Formerly known as Ubercart, Drupal Commerce has been completely revamped to provide a more modular framework for developers. Although there is currently a lot of development happening on Drupal Commerce and some other supporting modules, it isn't quite ready for an out-of-the-box storefront just yet. However, if you are a developer with a bit of knowledge, you can currently take advantage of Drupal Commerce and roll your own solution.
One of the issues that we ran into while developing everfan.com is the fact that Drupal Commerce's tax system isn't yet set up to support an easy way to query tax information from the database. We needed to set up a tax system that supported different tax rates for different municipalities in Georgia. For instance, if we ship to one zip code in Georgia it may have a different tax rate than another. This tutorial shows you how to set up conditional taxes, however it would have been far too much work to manually input a whole table full of taxes based on zip code (There are about 1000 different zip codes).
So rather than input these tax rates into the rules system, I decided to directly hook into Drupal Commerce's tax processing so that we could just query the database based upon the current order's shipping zip code. In order to accomplish this, I needed to install the Drupal Commerce Shipping module first and update all of our Drupal Commerce code to the latest versions. Then I created a database table that included a list of all of the Georgia zip codes and tax rates that I would query from. Next I used hook_commerce_tax_rate_info() to process the tax info by checking the zip code of the current order's shipping address, pulling the correct tax rate from the database, and then applying that tax rate to the order. I was really happy to see how easy it is to hook into commerce's tax system, and I can foresee that developing more complex tax rate calculations shouldn't be too difficult.
Note: All of the code for our module is available on OnyxGroup's GitHub site.
Related Links
Back to my blog
Posted by:
Adrian Mummey
Posted on: August 15, 2011
Glad to hear it worked out for you. I've been itching to get some "real world" feedback on those tax hooks for a while. : )
Post a comment