You are here

function commerce_cart_form_commerce_order_settings_form_alter in Commerce Core 7

Implements hook_form_FORM_ID_alter().

Adds a checkbox to the order settings form to enable the local action on order edit forms to apply pricing rules.

File

modules/cart/commerce_cart.module, line 361
Implements the shopping cart system and add to cart features.

Code

function commerce_cart_form_commerce_order_settings_form_alter(&$form, &$form_state) {
  $form['commerce_order_apply_pricing_rules_link'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable the local action link on order edit forms to apply pricing rules.'),
    '#description' => t('Even if enabled the link will not appear on shopping cart order edit forms.'),
    '#default_value' => variable_get('commerce_order_apply_pricing_rules_link', TRUE),
    '#weight' => 10,
  );
  $cart_providers = array();
  foreach (commerce_cart_get_providers() as $key => $cart_provider) {
    $cart_providers[$key] = $cart_provider['title'];
  }
  $form['commerce_cart_provider'] = array(
    '#title' => t('Cart provider'),
    '#type' => 'select',
    '#options' => $cart_providers,
    '#default_value' => variable_get('commerce_cart_provider', COMMERCE_CART_DEFAULT_PROVIDER),
    '#access' => count($cart_providers) > 1,
  );

  // Add a fieldset for settings pertaining to the shopping cart refresh.
  $form['cart_refresh'] = array(
    '#type' => 'fieldset',
    '#title' => t('Shopping cart refresh'),
    '#description' => t('Shopping cart orders comprise orders in shopping cart and some checkout related order statuses. These settings let you control how the shopping cart orders are refreshed, the process during which product prices are recalculated, to improve site performance in the case of excessive refreshes on sites with less dynamic pricing needs.'),
    '#weight' => 40,
  );
  $form['cart_refresh']['commerce_cart_refresh_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Shopping cart refresh mode'),
    '#options' => array(
      COMMERCE_CART_REFRESH_ALWAYS => t('Refresh a shopping cart when it is loaded regardless of who it belongs to.'),
      COMMERCE_CART_REFRESH_OWNER_ONLY => t('Only refresh a shopping cart when it is loaded if it belongs to the current user.'),
      COMMERCE_CART_REFRESH_ACTIVE_CART_ONLY => t("Only refresh a shopping cart when it is loaded if it is the current user's active shopping cart."),
    ),
    '#default_value' => variable_get('commerce_cart_refresh_mode', COMMERCE_CART_REFRESH_OWNER_ONLY),
  );
  $form['cart_refresh']['commerce_cart_refresh_frequency'] = array(
    '#type' => 'textfield',
    '#title' => t('Shopping cart refresh frequency'),
    '#description' => t('Shopping carts will only be refreshed if more than the specified number of seconds have passed since they were last refreshed.'),
    '#default_value' => variable_get('commerce_cart_refresh_frequency', COMMERCE_CART_REFRESH_DEFAULT_FREQUENCY),
    '#required' => TRUE,
    '#size' => 32,
    '#field_suffix' => t('seconds'),
    '#element_validate' => array(
      'commerce_cart_validate_refresh_frequency',
    ),
  );
  $form['cart_refresh']['commerce_cart_refresh_force'] = array(
    '#type' => 'checkbox',
    '#title' => t('Always refresh shopping cart orders on shopping cart and checkout form pages regardless of other settings.'),
    '#description' => t('Note: this option only applies to the core /cart and /checkout/* paths.'),
    '#default_value' => variable_get('commerce_cart_refresh_force', TRUE),
  );
}