Commerce tax is not calculated on programmatically added custom line-items. Is there a reason commerce_tax listens and calculates only product line-items ???

Environment:

We have 3 product variation types (A,B,C), but only 2 product maximum line-items at the time can be present: A+C, B+C, A, B, C are the only possibilities (but that's not the point)
and 5 NON product custom line-item types (D,E,F,G,H) (defined via hook_commerce_line_item_type_info).

We have a custom page where we manage the current order in cart, it has views for product displays with filters, so each product display automatically renders the commerce-add-to-cart form (with ajax properties selectors). Thats ok - works as intended.

This custom page also includes different custom forms for adding our custom line-items. Each custom form is simple: field for quantity, field for unit price. We need different line-item types for distinguish them and for possibile future customizations (more fields for each line-item type).
Submits of these forms creates a line item of type with LABEL, commerce_unit_price and commerce_total already set. No product reference within, i just create them via this code snippet:


$order = commerce_cart_order_load($user->uid);
$order_wrap = entity_metadata_wrapper('commerce_order', $order);
$total = $order_wrap->commerce_order_total->value();
$currCode = $total['currency_code'];

// Creating new line-item:
$line_item = commerce_line_item_new('custom_li_type', $order->order_id);
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);

// Setting the line-item core values:
$line_item_wrapper->quantity = intVal($form_state['values']['custom_li_quantity']);
$line_item_wrapper->line_item_label = 'CUSTOM_LI_COST';
$line_item_wrapper->commerce_total->amount = 0;

// Setting the base unit_price:
$price = floatVal($form_state['values']['custom_li_unit_cost']) * 100;
$line_item_wrapper->commerce_unit_price->amount = $price;
$line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
    $line_item_wrapper->commerce_unit_price->value(),
    'base_price', array(
        'amount' => $price,
        'currency_code' => $currCode,
        'data' => array(),
    ), TRUE
);
$line_item_wrapper->save();

// Adding to the order line-items array:
$order_wrap->commerce_line_items[] = $line_item_wrapper->value();
$order_wrap->save();

Situation:

Step 1 (no VAT rate)

-----+------------+----------+-----------+
type | unit price | quantity | subtotal  |
-----+------------+----------+-----------+
  A  |     196,00 |      110 |  21560,00 |
  C  |      14,00 |       44 |    616,00 | 
  D  |       5,00 |      100 |    500,00 |
-----+------------+----------+-----------+
                    subtotal |  22676,00 |

Step 2 (adding 10% VAT rate)

-----+------------+----------+-----------+-----------+-----------+
type | unit price | quantity | subtotal  |  VAT 10%  | taxed     |
-----+------------+----------+-----------+-----------+-----------+
  A  |     196,00 |      110 |  21560,00 |   2156,00 |  23716,00 |
  C  |      14,00 |       44 |    616,00 |     61,60 |    677,60 |
  D  |       5,00 |      100 |    500,00 |  !!! 0,00 |  !!! 0,00 | *
-----+------------+----------+-----------+-----------+-----------+
                          taxed subtotal |   2217,60 |  24893,60 | **

* - no tax|vat_10 component on commerce_total
** - which is wrong

Probably during the Commerce Add-to-cart submit action there're some rule invoke calls that somehow binds the product line-item typ to be hooked on calculation of any TAX component applyed to the order, while my code is missing something to do so.

Anyone is there to help?

Comments

egorlaw created an issue. See original summary.

eglaw’s picture

Issue summary: View changes
eglaw’s picture

Status: Active » Closed (outdated)

Resolved it somehow ... don't remember how... just cleaning the issues mess here. sorry