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 => array(0 => array(
'amount' => $price * 100,
'currency_code' => 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->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 => array(0 => array(
'amount' => $price * 100,
'currency_code' => $product_obj->vatType,
'data' => array('include_tax' => '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...