You are here

function commerce_paypal_ec_enabled in Commerce PayPal 7.2

Returns whether or not Express Checkout is enabled, in general or for a specific order.

@todo Rework this function to support any number of Express Checkout rules.

Parameters

$order: The order that needs to be checked.

1 call to commerce_paypal_ec_enabled()
commerce_paypal_ec_form_alter in modules/ec/commerce_paypal_ec.module
Implements hook_form_alter().

File

modules/ec/commerce_paypal_ec.module, line 1536
Implements PayPal Express Checkout in Drupal Commerce checkout.

Code

function commerce_paypal_ec_enabled($order = NULL) {

  // If an order is passed in, then pass it through Rules to only return TRUE if
  // the Express Checkout rule is available for the order.
  if (!empty($order)) {
    $order->payment_methods = array();
    rules_invoke_all('commerce_payment_methods', $order);

    // Sort the payment methods array by the enabling Rules' weight values.
    uasort($order->payment_methods, 'drupal_sort_weight');
    return in_array('paypal_ec|commerce_payment_paypal_ec', array_keys($order->payment_methods));
  }

  // Otherwise sipmly load the default PayPal EC rule and see if it's enabled.
  $rule = rules_config_load('commerce_payment_paypal_ec');
  $enabled = !empty($rule) && $rule->active;
  if (!empty($order) && $enabled) {
    $enabled = !empty($order->data['payment_method']) && $order->data['payment_method'] == 'paypal_ec|commerce_payment_paypal_ec';
  }
  return $enabled;
}