Mixing attributes and line item fields in Drupal Commerce Add To Cart form I am currently working on a Drupal Commerce site that offers highly customizable products with multiple attributes.  I am at the stage where i am trying to theme my add to cart form, and am a bit lost.

In my theme, I have created a hook_form_alter, and check for my add to cart form.  The $form variable has 2 groups of form fields:

$form['attributes']        // Contains 'Attr_1', and 'Attr_2'.
$form['line_item_fields']  // Contains 'Attr_1_c1', 'Attr_1_c2', 'Attr_2_c1', 'Attr_2_c2'


So each attribute has 2 customization options specific to that attribute.  I would like to output my form like so:

Attribute 1: (Select Box)
    Customization 1: (input)   // Attr_1_c1
    Customization 2: (input)   // Attr_1_c2

Attribute 2: (Select Box)
    Customization 1: (input)   // Attr_2_c1
    Customization 2: (input)   // Attr_2_c2


Thus grouping the proper customization line_item_fields with the proper attributes.  However, since attributes are already grouped in the $form variable, and are separate from the line_item_fields, I am not sure how to do this.  Any thoughts on the best way to proceed?
You may find it easier to organize the form elements in a form template.

e.g

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_commerce_cart_add_to_cart_form_alter(&amp;$form, &amp;$form_state{
  $form['#theme'] = array('commerce_add_to_cart_form');
}

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path){
  return array(
    'commerce_add_to_cart_form' =&gt; array(
      'render element' =&gt; 'form',
      'template' =&gt; 'form--commerce_add_to_cart',
      'path' =&gt; $path . '/templates',
    ),
  );
}


Then you can use a file in 

MYTHEME/templates/form--commerce_add_to_cart.tpl.php


and in the template file

print drupal_render($form['element_name']);
// or
print drupal_render_children($form['element_name']);


to specify exactly where to render each form element.