0

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

'hook_commerce_line_item_type_info()'

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;
        //line_item_fields[field_resource_id][0]
        //line_item_fields[field_resource_id][und][0][value]
        foreach(element_children($form['add_to_cart_quantity']) as $key) {
            //hook_form_FORM_ID_alter
          //  echo ("here: ".print_r($form['add_to_cart_quantity'][$key]));                                    
            $form['line_item_fields'][$key]['field_resource_id']['und']['0']['value']=array(
                '#type'=>'textfield',                
                '#product_id' => $form['add_to_cart_quantity'][$key]['#product_id'],
                '#title'=>t('ResourceID'), 
                '#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.