You are here

function commerce_shipping_enable_method in Commerce Shipping 7

Generic execution callback for the shipping method.

1 string reference to 'commerce_shipping_enable_method'
commerce_shipping_rules_action_info in ./commerce_shipping.rules.inc
Implements hook_rules_action_info().

File

./commerce_shipping.rules.inc, line 91
Rules integration for shipping.

Code

function commerce_shipping_enable_method($order, $shipping_method, $action_settings, $rule_state, $action, $callback_type) {

  // Find the Rule that contains this action.
  $rule = $action
    ->parentElement();
  while ($rule
    ->getPluginName() != 'reaction rule') {
    $rule = $rule
      ->parentElement();
  }

  // Initialize variables for the shipping method ID and settings.
  if (is_array($shipping_method)) {
    $method_id = $shipping_method['method_id'];
  }
  else {
    $method_id = $shipping_method;
    $shipping_method = commerce_shipping_plugin_get_plugin('quotes', $method_id);
  }

  // Create a unique key for the instance of the shipping method represented by
  // this action.
  $instance_id = commerce_shipping_method_instance_id($method_id, $rule);

  // Set the shipping method to the order along with its settings and context.
  $order->commerce_shipping_methods[$instance_id] = array(
    'method_id' => $method_id,
    'settings' => $shipping_method['settings'],
    'plugin' => $shipping_method,
    'rule_name' => $rule->name,
    'label' => $rule->label,
  );
}