<?php
hook_ca_predicate()
?>Predicates tie together triggers, conditions, and actions. They hold the particular settings of each arrangement, so the same condition may be used in several different ways at different times.
An array of predicates. This array is keyed off the predicate ID, and the values are arrays with the following keys:
- #title - The translated title.
- #description - Helpful text explaining the purpose of the predicate.
- #class - Used to group predicates together on the Conditional Actions settings page.
- #trigger - Determines when the predicate will be evaluated.
- #status - A boolean flag that determines whether this predicate will be evaluated.
- #conditions - A nested array that describes the logical relationship of the conditions of the predicate. The array is a tree-like structure with conditions at the leaves and boolean operators (either "AND" or "OR") at the branches.
Each condition is an array with the following keys:
- #name - The condition id returned from some implementation of hook_ca_condition().
- #title - The condition's title. This can be different from the condition's original title to make it more relevant to the predicate. (E.g.: "If the order status is 'pending'.")
- #argument_map - An array that maps trigger argument ids (keys) to condition argument ids (values). In most cases, these ids will be the same value.
- #settings - An optional array of form values. When the predicate's conditions are saved, they may provide form elements to hold the value of these settings. Inspect the callback functions to see what keys and values are expected.
The root of the #conditions array must hold an #operator element (which must be "AND") and another #conditions array. After this first one, each #conditions array may hold another #operator (which may be "AND" or "OR" now) and #conditions pair, or an array of condition arrays which are described above. I think it helps to think of each #conditions array as set of parentheses around a set of statements with the #operator linking them all together.
- #actions - An array of action arrays. (No trees here!
)
Each action array has the following keys:- #name
- #title
- #argument_map
- #settings
The data a predicate needs for actions is thus the same as what it needs for conditions. Actions are performed in the order given unless a #weight parameter is given (default is 0), either in the hook or through the user interface.
<?php
/**
* Implementation of hook_ca_predicate().
*/
function uc_payment_ca_predicate() {
// Set the order status to "Payment Received" when a payment is received
// and the balance is less than or equal to 0.
$configurations['uc_payment_received'] = array(
'#title' => t('Update order status on full payment'),
'#description' => t('Only happens when a payment is entered and the balance is <= $0.00.'),
'#class' => 'payment',
'#trigger' => 'uc_payment_entered',
'#status' => 1,
'#conditions' => array(
'#operator' => 'AND',
'#conditions' => array(
array(
'#name' => 'uc_payment_condition_order_balance',
'#title' => t('If the balance is less than or equal to $0.00.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'negate' => FALSE,
'balance_comparison' => 'less_equal',
),
),
array(
'#name' => 'uc_order_status_condition',
'#title' => t('If the order status is not already Payment Received.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'negate' => TRUE,
'order_status' => 'payment_received',
),
),
),
),
'#actions' => array(
array(
'#name' => 'uc_order_update_status',
'#title' => t('Update the order status to Payment Received.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'order_status' => 'payment_received',
),
),
),
);
// Set the order status to "Completed" when checkout is complete, none
// of the products are shippable, and the balance is less than or equal to 0.
$configurations['uc_checkout_complete_paid'] = array(
'#title' => t('Update order status upon checkout completion with full payment'),
'#trigger' => 'uc_checkout_complete',
'#class' => 'payment',
'#status' => 1,
'#weight' => 1,
'#conditions' => array(
'#operator' => 'AND',
'#conditions' => array(
array(
'#name' => 'uc_payment_condition_order_balance',
'#title' => t('If the balance is less than or equal to $0.00.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'negate' => FALSE,
'balance_comparison' => 'less_equal',
),
),
array(
'#name' => 'uc_order_condition_is_shippable',
'#title' => t('If the order is not shippable.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'negate' => TRUE,
),
),
),
),
'#actions' => array(
array(
'#name' => 'uc_order_update_status',
'#title' => t('Update the order status to Completed.'),
'#argument_map' => array(
'order' => 'order',
),
'#settings' => array(
'order_status' => 'completed',
),
)
),
);
return
$configurations;
}
?>