I am working on a system that pulls in available dates and booking references from a third party API - we then need to add these pieces of extra information to a line_item that is added to cart.

I have the custom line item setup by way of


What I would really like to see now is several products (Adult, Child, Concession) - all being available within one form - and a single add to bag button. With the caveat of needing to submit the custom line_item attributes at the same time (these values will be copied over using Javascript after being selected in the UI).

I have made use of commerce_add_to_cart_extras - which provides a view of the products - with a single add to bag - but no notion of being able to add the line_item attributes to the form. Indeed - I'm not even sure that the form processing of this module caters for custom line_item - even if my form_alter code managed to get the syntax of the extra fields correct:

$form_state['rebuild'] = TRUE;
        $form['line_item_fields']['#tree'] = TRUE;
        foreach(element_children($form['add_to_cart_quantity']) as $key) {
          //  echo ("here: ".print_r($form['add_to_cart_quantity'][$key]));                                    
                '#product_id' => $form['add_to_cart_quantity'][$key]['#product_id'],
                '#tree' => TRUE

Has anybody got a solution to how this can be done? We only have one product type - and one custom line item type to consider - and they have a 1:1 mapping.

Hope someone can help here!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.