1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Rules integration for the checkout process.
|
6 |
|
|
*
|
7 |
|
|
* @addtogroup rules
|
8 |
|
|
* @{
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
|
|
/**
|
12 |
|
|
* Implements hook_rules_event_info().
|
13 |
|
|
*/
|
14 |
|
|
function commerce_checkout_rules_event_info() {
|
15 |
|
|
$events = array();
|
16 |
|
|
|
17 |
|
|
$events['commerce_checkout_complete'] = array(
|
18 |
|
|
'label' => t('Completing the checkout process'),
|
19 |
|
|
'group' => t('Commerce Checkout'),
|
20 |
|
|
'variables' => array(
|
21 |
|
|
'commerce_order' => array(
|
22 |
|
|
'type' => 'commerce_order',
|
23 |
|
|
'label' => t('Completed order', array(), array('context' => 'a drupal commerce order')),
|
24 |
|
|
),
|
25 |
|
|
),
|
26 |
|
|
'access callback' => 'commerce_order_rules_access',
|
27 |
|
|
);
|
28 |
|
|
|
29 |
|
|
return $events;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
* Implements hook_rules_action_info().
|
34 |
|
|
*/
|
35 |
|
|
function commerce_checkout_rules_action_info() {
|
36 |
|
|
$actions = array();
|
37 |
|
|
|
38 |
|
|
$actions['send_account_email'] = array(
|
39 |
|
|
'label' => t('Send account e-mail'),
|
40 |
|
|
'parameter' => array(
|
41 |
|
|
'account' => array(
|
42 |
|
|
'type' => 'user',
|
43 |
|
|
'label' => t('Account'),
|
44 |
|
|
),
|
45 |
|
|
'email_type' => array(
|
46 |
|
|
'type' => 'text',
|
47 |
|
|
'label' => t('E-mail type'),
|
48 |
|
|
'description' => t("Select the e-mail based on your site's account settings to send to the user."),
|
49 |
|
|
'options list' => 'commerce_checkout_account_email_options_list',
|
50 |
|
|
),
|
51 |
|
|
),
|
52 |
|
|
'group' => t('User'),
|
53 |
|
|
'base' => 'commerce_checkout_action_send_account_email',
|
54 |
|
|
'access callback' => 'rules_system_integration_access',
|
55 |
|
|
);
|
56 |
|
|
$actions['commerce_checkout_complete'] = array(
|
57 |
|
|
'label' => t('Complete checkout for an order'),
|
58 |
|
|
'parameter' => array(
|
59 |
|
|
'commerce_order' => array(
|
60 |
|
|
'type' => 'commerce_order',
|
61 |
|
|
'label' => t('Order in checkout'),
|
62 |
|
|
),
|
63 |
|
|
),
|
64 |
|
|
'group' => t('Commerce Checkout'),
|
65 |
|
|
'callbacks' => array(
|
66 |
|
|
'execute' => 'commerce_checkout_rules_complete_checkout',
|
67 |
|
|
),
|
68 |
|
|
);
|
69 |
|
|
|
70 |
|
|
return $actions;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Returns the account e-mail types from the User module.
|
75 |
|
|
*
|
76 |
|
|
* @see _user_mail_notify()
|
77 |
|
|
*/
|
78 |
|
|
function commerce_checkout_account_email_options_list() {
|
79 |
|
|
return array(
|
80 |
|
|
'register_admin_created' => t('Welcome (new user created by administrator)'),
|
81 |
|
|
'register_no_approval_required' => t('Welcome (no approval required)'),
|
82 |
|
|
'register_pending_approval' => t('Welcome (awaiting approval)'),
|
83 |
|
|
'password_reset' => t('Password recovery'),
|
84 |
|
|
'status_activated' => t('Account activation'),
|
85 |
|
|
'status_blocked' => t('Account blocked'),
|
86 |
|
|
'cancel_confirm' => t('Account cancellation confirmation'),
|
87 |
|
|
'status_canceled' => t('Account canceled'),
|
88 |
|
|
);
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
/**
|
92 |
|
|
* Action callback: sends a selected account e-mail.
|
93 |
|
|
*/
|
94 |
|
|
function commerce_checkout_action_send_account_email($account, $email_type) {
|
95 |
|
|
// If we received an authenticated user account...
|
96 |
|
|
if (!empty($account)) {
|
97 |
|
|
$types = commerce_checkout_account_email_options_list();
|
98 |
|
|
|
99 |
|
|
// Attempt to send the account e-mail.
|
100 |
|
|
$result = _user_mail_notify($email_type, $account);
|
101 |
|
|
|
102 |
|
|
// Log the success or failure.
|
103 |
|
|
if ($result) {
|
104 |
|
|
watchdog('rules', '%type e-mail sent to %recipient.', array('%type' => $types[$email_type], '%recipient' => $account->mail));
|
105 |
|
|
}
|
106 |
|
|
else {
|
107 |
|
|
watchdog('rules', 'Failed to send %type e-mail to %recipient.', array('%type' => $types[$email_type], '%recipient' => $account->mail));
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Action callback: completes checkout for the given order.
|
114 |
|
|
*/
|
115 |
|
|
function commerce_checkout_rules_complete_checkout($order) {
|
116 |
|
|
commerce_checkout_complete($order);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* @}
|
121 |
|
|
*/ |