Does anyone have any examples of importing Sales Tax data from Ubercart 2 into Drupal Commerce?

The two systems seem to use -very- different schemas (Ubercart uses separate line items and Commerce attaches tax to the product/line item. I looked at the commerce_migrate_ubercart module and it doesn't even try to handle this.

The problem is that we have historical data where rates have changed over time so it's not accurate to simply recalculate based on current rates.

We could live with simply being able to override the tax on the entire order, but I can't find a hook to override that in the commerce_orders table.

Edit: I could use commerce_tax_rate_apply('state_sales_tax', $line_item);

     $tax_price = commerce_tax_rate_apply('state_sales_tax',  $line_item); 
    // <--- Now what? I don't understand how to apply $tax_price back to the original line item before saving.

     // Save the line item to get its ID.

Or: After saving the line item, how do I hook into the standard Rules for tax calculation? (Which work fine for new orders.)

  • What does Commerce Migrate Ubercart do? Is it just not migrating tax data? Typically you'd just want to create your own line item for historical records of tax to match up to Ubercart and then going forward use Commerce as is w/ taxes being calculated / applied on a per-line item basis. Commented Nov 3, 2014 at 16:57
  • I'm not using the Commerce Migrate Ubercart module. (It's broken in the latest Kickstart build). I don't see -any- reference to either 'tax' or 'rules' in that code. Anyhoo, I can definitely create my own line item for tax... if you can give me some guidance on how to do so. I've searched and searched and not seen a nice simple example for how to add a tax line item to a commerce order. 1. Can you provide an example... or a link to such a thing? OR... 2. If there is a way to apply the tax rules to each line item and then re-save the order, I could do -that- if it's simpler. TIA!
    – jchwebdev
    Commented Nov 3, 2014 at 18:11
  • I see commerce_tax_rate_apply() as a callback for Rules. I'm confused as to how to use that with a straight line item. ie. If I call that, how do I then update the line item? Please see above.
    – jchwebdev
    Commented Nov 3, 2014 at 18:21

1 Answer 1


The best solution here is a "dumb" migration, one that simply retains the data model of the prior system without trying to shoe horn it into the data model of the new. The reason I changed the tax data model from Ubercart to Commerce is because taxes are actually necessarily tied to the products and services that are being taxes. When we had all taxes added up and stored in a single line item, it's then impossible to do things like refund the taxes collected for one particular product on an order if it's returned. You also cannot generate a very meaningful tax report, though nowadays I'd look to third party systems to do that anyways.

You're going to need to define your own line item type via hook_commerce_line_item_type_info() and then setup your migration to create the line item on migration. I'd call it "Ubercart tax record" or something similar. New taxes going forward should actually become part of the relevant line items when they're calculated.

When you create these tax line items, make sure that you both set the unit price amount / currency code values and update the unit price's components array to match. Look to commerce_product_line_item_populate() around line 1376 where you see the comment about adding the base price to the components array. In your case, you wouldn't use the 'base_price' price component for taxes - you'd either want to define a generic price component type via hook_commerce_price_component_type_info() or if you know the types of the taxes map to price components for tax rates you've defined on the new site, you can use those.

  • First off, I agree with how Commerce does it... the Ubercart method is simply -insane- from an accounting POV. That said, I think I figured it out. I stumbled upon commerce_tax_rate_apply() and the line items now import with the correct tax. GOOD. I appreciate your help. FWIW: I know it (again) sounds ungrateful, but I just can't believe the poor documentation. Having to reverse-engineer this stuff is -painful-. I know doc writing is a drag, but have pity on those of us who don't have months to get this far into the weeds. Best Regards. ---JC
    – jchwebdev
    Commented Nov 3, 2014 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.