function commerce_registration_default_rules_configuration in Commerce Registration 7.2
Same name and namespace in other branches
- 7.3 commerce_registration.rules_defaults.inc \commerce_registration_default_rules_configuration()
- 7 commerce_registration.rules_defaults.inc \commerce_registration_default_rules_configuration()
Implements hook_default_rules_configuration().
File
- ./
commerce_registration.rules_defaults.inc, line 10 - Default rules configuration.
Code
function commerce_registration_default_rules_configuration() {
// Add a reaction rule that sets the state to pending for registrations
// associated with an order when the order checkout is completed.
$rule1 = rules_reaction_rule();
$rule1->label = t("Set Registrations to Pending upon Order Completion");
$rule1->tags = array(
'Commerce Registration',
);
$rule1->active = TRUE;
$rule1
->event('commerce_checkout_complete')
->action('commerce_registration_set_state', array(
'commerce_order:select' => "commerce-order",
'registration_state' => array(
'pending' => 'pending',
),
));
// Add a reaction rule that sets the state to complete for registrations
// associated with an order when the order is paid in full.
$rule2 = rules_reaction_rule();
$rule2->label = t("Set Registrations to Complete upon Full Payment");
$rule2->tags = array(
'Commerce Registration',
);
$rule2->active = TRUE;
$rule2
->event('commerce_payment_order_paid_in_full')
->action('commerce_registration_set_state', array(
'commerce_order:select' => "commerce-order",
'registration_state' => array(
'complete' => 'complete',
),
));
// Add a reaction rule that deletes the registrations that are associated
// with line item when that line item is deleted. These rules were introduced
// later in the development cycle and will be disabled by default using a
// variable added during an update. It will be enabled by default for all new
// installs.
// @see commerce_registration_update_7202()
$rule3 = rules_reaction_rule();
$rule3->label = t("Delete line item registrations along with line item");
$rule3->tags = array(
'Commerce Registration',
);
$rule3->active = variable_get('enable_commerce_registration_delete_rules', TRUE);
$rule3
->event('commerce_line_item_delete')
->condition('commerce_registration_order_has_registration', array(
'commerce_order:select' => 'commerce-line-item',
))
->action('commerce_registration_load_product_registrations', array(
'commerce_line_item:select' => 'commerce-line-item',
'line_item_registrations:label' => t('Line item registrations'),
'line_item_registrations:var' => 'line_item_registrations',
));
// Build a loop that deletes the loaded registrations that are associated with
// the line item being deleted.
$loop = rules_loop(array(
'list:select' => 'line-item-registrations',
'item:var' => 'registration',
'item:label' => t('Current registration'),
'item:type' => 'registration',
))
->action('entity_delete', array(
'data:select' => 'registration',
));
// Add the loop to the rule as an action.
$rule3
->action($loop);
return array(
'commerce_registration_pending_upon_order_completion' => $rule1,
'commerce_registration_complete_upon_full_payment' => $rule2,
'commerce_registration_delete_line_item_registrations' => $rule3,
);
}