You are here

function commerce_braintree_express_checkout_form_views_form_commerce_cart_form_default_alter in Commerce Braintree 7.3

Implements hook_form_FORM_ID_alter().

File

modules/commerce_braintree_express_checkout/commerce_braintree_express_checkout.module, line 195
Provides integration PayPal Express Checkout for Braintree.

Code

function commerce_braintree_express_checkout_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state, $form_id) {
  if (!empty($form_state['build_info']['args'][0]->result)) {

    // This hook executes before commerce_line_item adds the order
    // object to form state, so we'll load it the same way.
    $view = $form_state['build_info']['args'][0];
    $order = commerce_order_load($view->argument['order_id']->value[0]);

    // Verify that Express Checkout is available for this order.
    if (_commerce_braintree_express_checkout_enabled($order)) {
      $payment_method = commerce_payment_method_instance_load(COMMERCE_BRAINTREE_EXPRESS_CHECKOUT_INSTANCE_ID);

      // Determine if we should show Express Checkout on /cart.
      if (!empty($payment_method['settings']['show_on_cart'])) {

        // Add the Express Checkout to the cart form.
        $form['actions'] += commerce_braintree_express_checkout_button_form($order, $payment_method, array(
          'form_id' => $form_id,
        ));

        // Append our submit handler to form.
        $form['#submit'][] = 'commerce_braintree_express_checkout_submit';
      }
    }
  }
}