You are here

function commerce_product_attributes_form_alter in Commerce Product Attributes 7

Implementation of hook_form_alter()

Here we modify the add to cart form.

File

./commerce_product_attributes.module, line 227
This module adds some improvements to the Drupal Commerce core.

Code

function commerce_product_attributes_form_alter(&$form, &$form_state, $form_id) {
  if (strstr($form_id, 'commerce_cart_add_to_cart_form')) {
    $line_item = $form_state['line_item'];
    if (isset($line_item->line_item_id) && $line_item->line_item_id > 0) {
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Update cart'),
        '#weight' => 10,
      );

      // Replace the default submit handler. We need also an update action.
      foreach ($form['#submit'] as $handler_id => $handler) {
        if ($handler == 'commerce_cart_add_to_cart_form_submit') {
          unset($form['#submit'][$handler_id]);
        }
        elseif ($handler == 'commerce_product_attributes_add_to_cart_form_submit') {
          unset($form['#submit'][$handler_id]);
        }
        $form['#submit'][] = 'commerce_product_attributes_add_to_cart_form_submit';
      }
    }
  }
}