Importing products into Drupal Commerce and handling Tax Im working on an integration module where I'm trying to import products externally and into Drupal Commerce. I revceive the product object externally like this:
    2692604 (Object) stdClass
      id (Integer) 2692604
      revision (Integer) 2
      currencyCode (String, 3 characters ) NOK
      vatType (Integer) 3
      name (String, 14 characters ) Produktkatalog
      priceCurrency (Integer) 235
      priceIncVatCurrency (Integer) 294
      number (String, 4 characters ) 1003
      cost (Integer) 230

I've found a code snippet from the commerce_example module where you can create a product programmatically like this:

//commerce_price[und][0][amount]
$price = array(LANGUAGE_NONE =&gt; array(0 =&gt; array(
  'amount' =&gt; $price * 100,
  'currency_code' =&gt; commerce_default_currency(),
)));
$form_state['values']['commerce_price'] = $price;

// Notify field widgets to save their field data
field_attach_submit('commerce_product', $new_product, $form, $form_state);

commerce_product_save($new_product);
return $new_product-&gt;product_id;


I have defined a tax type and a set of tax rates - including a mapping from the code found in the importing object.

I'm thinking the correct way of adding the tax part should be by modifying the code to something like this:

//commerce_price[und][0][amount]
$price = array(LANGUAGE_NONE =&gt; array(0 =&gt; array(
  'amount' =&gt; $price * 100,
  'currency_code' =&gt; $product_obj-&gt;vatType,
  'data' =&gt; array('include_tax' =&gt; 'MVA_hoy'),
)));
$form_state['values']['commerce_price'] = $price;

// Notify field widgets to save their field data
field_attach_submit('commerce_product', $new_product, $form, $form_state);

commerce_product_save($new_product);


Problem is that when I import the products, the tax rate is not set as I would expect it to.
Investigating the newly created product (or an old loaded product) does not give me much clue either...
Found the solution it seems.
It is apparently not enough to add a field under the data array, you also need to add the include_tax field on the same level as amount and currency:

//commerce_price[und][0][amount]
$price = array(LANGUAGE_NONE =&gt; array(0 =&gt; array(
  'amount' =&gt; $price * 100,
  'currency_code' =&gt; $product_obj-&gt;vatType,
  'data' =&gt; array('include_tax' =&gt; 'MVA_hoy'),
  'include_tax' =&gt; 'MVA_hoy',
)));
$form_state['values']['commerce_price'] = $price;


Now, when importing products, the tax field is updated.