function commerce_shipping_method_instance_load in Commerce Shipping 7
Returns a shipping method instance object which includes the settings specific to the context of the instance.
Parameters
$instance_id: A shipping method instance ID in the form of a pipe delimited string containing the method_id and the enabling Rule's name.
Return value
The shipping method instance object which is identical to the shipping method object with the addition of the settings array.
1 call to commerce_shipping_method_instance_load()
- commerce_shipping_pane_checkout_form in includes/
commerce_shipping.checkout_pane.inc - Checkout pane callback: builds a shipping quote selection form.
File
- ./
commerce_shipping.module, line 280 - Defines the shipping system and checkout integration.
Code
function commerce_shipping_method_instance_load($instance_id) {
// Return FALSE if there is no pipe delimeter in the instance ID.
if (strpos($instance_id, '|') === FALSE) {
return FALSE;
}
// Explode the method key into its component parts.
list($method_id, $rule_name) = explode('|', $instance_id);
// Return FALSE if we didn't receive a proper instance ID.
if (empty($method_id) || empty($rule_name)) {
return FALSE;
}
// First load the shipping method and add the instance ID.
$shipping_method = commerce_shipping_plugin_get_plugin('quotes', $method_id);
$shipping_method['instance_id'] = $instance_id;
// Then load the Rule configuration that enables the method.
$rule = rules_config_load($rule_name);
// Iterate over its actions to find one with the matching element name and
// pull its settings into the shipping method object.
foreach ($rule
->actions() as $action) {
if ($action
->getElementName() == 'commerce_shipping_enable_' . $method_id) {
// Set label if we have any set.
if (is_array($action->settings['shipping_method']) && !empty($action->settings['shipping_method']['shipping_label'])) {
$shipping_method['shipping_label'] = $action->settings['shipping_method']['shipping_label'];
}
if (is_array($action->settings['shipping_method']['settings'])) {
$shipping_method['settings'] = $action->settings['shipping_method']['settings'];
}
}
}
return $shipping_method;
}