diff --git a/payment/uc_google_checkout/uc_google_checkout.module b/payment/uc_google_checkout/uc_google_checkout.module index a246254..928c366 100644 --- a/payment/uc_google_checkout/uc_google_checkout.module +++ b/payment/uc_google_checkout/uc_google_checkout.module @@ -108,7 +108,7 @@ function uc_google_checkout_init() { global $user; $users = variable_get('uc_google_checkout_order_users', array()); if (isset($users[$user->uid])) { - unset($_SESSION['cart_order'], $_SESSION['do_complete'], $_SESSION['new_user'], $users[$user->uid]); + unset($_SESSION['cart_order'], $_SESSION['do_complete'], $users[$user->uid]); variable_set('uc_google_checkout_order_users', $users); } diff --git a/payment/uc_payment/uc_payment.ca.inc b/payment/uc_payment/uc_payment.ca.inc index a69160f..fdc82cf 100644 --- a/payment/uc_payment/uc_payment.ca.inc +++ b/payment/uc_payment/uc_payment.ca.inc @@ -40,14 +40,28 @@ function uc_payment_ca_predicate() { ), ), 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', + '#operator' => 'OR', + '#conditions' => array( + array( + '#name' => 'uc_order_state_condition', + '#title' => t('If the order state is in checkout.'), + '#argument_map' => array( + 'order' => 'order', + ), + '#settings' => array( + 'order_state' => 'in_checkout', + ), + ), + array( + '#name' => 'uc_order_state_condition', + '#title' => t('If the order state is post checkout.'), + '#argument_map' => array( + 'order' => 'order', + ), + '#settings' => array( + 'order_state' => 'post_checkout', + ), + ), ), ), ), @@ -66,11 +80,11 @@ function uc_payment_ca_predicate() { ), ); - // 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. + // Set the order status to "Completed" when payment has been received + // and none of the products are shippable. $predicates['uc_checkout_complete_paid'] = array( - '#title' => t('Update order status upon checkout completion with full payment'), - '#trigger' => 'uc_checkout_complete', + '#title' => t('Complete non-shippable order after payment received'), + '#trigger' => 'uc_order_status_update', '#class' => 'payment', '#status' => 1, '#weight' => 1, @@ -78,21 +92,20 @@ function uc_payment_ca_predicate() { '#operator' => 'AND', '#conditions' => array( array( - '#name' => 'uc_payment_condition_order_balance', - '#title' => t('If the balance is less than or equal to $0.00.'), + '#name' => 'uc_order_status_condition', + '#title' => t('If the order status is Payment received.'), '#argument_map' => array( - 'order' => 'order', + 'order' => 'updated_order', ), '#settings' => array( - 'negate' => FALSE, - 'balance_comparison' => 'less_equal', + 'order_status' => 'payment_received', ), ), array( '#name' => 'uc_order_condition_is_shippable', '#title' => t('If the order is not shippable.'), '#argument_map' => array( - 'order' => 'order', + 'order' => 'updated_order', ), '#settings' => array( 'negate' => TRUE, @@ -105,12 +118,12 @@ function uc_payment_ca_predicate() { '#name' => 'uc_order_update_status', '#title' => t('Update the order status to Completed.'), '#argument_map' => array( - 'order' => 'order', + 'order' => 'updated_order', ), '#settings' => array( 'order_status' => 'completed', ), - ) + ), ), ); diff --git a/payment/uc_payment/uc_payment.module b/payment/uc_payment/uc_payment.module index 8c471c5..eb2abf0 100644 --- a/payment/uc_payment/uc_payment.module +++ b/payment/uc_payment/uc_payment.module @@ -641,6 +641,9 @@ function uc_payment_enter($order_id, $method, $amount, $uid = 0, $data = NULL, $ $order = uc_order_load($order_id); $account = user_load($uid); + // Ensure user has an account before payment is made. + uc_cart_complete_sale($order); + module_invoke_all('uc_payment_entered', $order, $method, $amount, $account, $data, $comment); ca_pull_trigger('uc_payment_entered', $order, $account); } diff --git a/uc_cart/uc_cart.admin.inc b/uc_cart/uc_cart.admin.inc index 7fc865c..1796726 100644 --- a/uc_cart/uc_cart.admin.inc +++ b/uc_cart/uc_cart.admin.inc @@ -537,6 +537,19 @@ function uc_cart_checkout_messages_form() { ); $form['checkout_messages']['uc_msg_order_new_user_format'] = filter_form(variable_get('uc_msg_order_new_user_format', FILTER_FORMAT_DEFAULT), NULL, array('uc_msg_order_new_user_format')); + $form['checkout_messages']['uc_msg_order_new_user_logged_in'] = array( + '#type' => 'textarea', + '#title' => t('Checkout completion for new logged in users'), + '#description' => t('Message displayed upon checkout for a new user whose account was just created and also "Login users when new customer accounts are created at checkout." is set on the checkout settings. Uses order and global tokens.', array('!url' => url('admin/store/help/tokens'), '!user_login_setting_ur' => 'admin/store/settings/checkout/edit/basic')), + '#summary' => variable_get('uc_msg_order_new_user_logged_in', uc_get_message('completion_new_user_logged_in')) + ? t('Completion text for new logged in users is set.') + : t('Completion text for new logged in users is not set.'), + '#default_value' => variable_get('uc_msg_order_new_user_logged_in', uc_get_message('completion_new_user_logged_in')), + '#rows' => 3, + ); + $form['checkout_messages']['uc_msg_order_new_user_logged_in_format'] = filter_form(variable_get('uc_msg_order_new_user_logged_in_format', FILTER_FORMAT_DEFAULT), NULL, array('uc_msg_order_new_user_logged_in_format')); + + $form['uc_msg_continue_shopping'] = array( '#type' => 'textarea', '#title' => t('Continue shopping message'), diff --git a/uc_cart/uc_cart.module b/uc_cart/uc_cart.module index 8b76c13..c41d5b3 100644 --- a/uc_cart/uc_cart.module +++ b/uc_cart/uc_cart.module @@ -266,6 +266,7 @@ function uc_cart_init() { $conf['i18n_variables'][] = 'uc_msg_order_existing_user'; $conf['i18n_variables'][] = 'uc_msg_order_logged_in'; $conf['i18n_variables'][] = 'uc_msg_order_new_user'; + $conf['i18n_variables'][] = 'uc_msg_order_new_user_logged_in'; $conf['i18n_variables'][] = 'uc_msg_order_submit'; } @@ -756,7 +757,8 @@ function uc_cart_uc_message() { $messages['completion_message'] = t('Your order is complete! Your order number is [order-id].'); $messages['completion_logged_in'] = t('Thank you for shopping at [store-name]. While logged in, you may continue shopping or view your current order status and order history.'); $messages['completion_existing_user'] = t("Thank you for shopping at [store-name]. Your current order has been attached to the account we found matching your e-mail address.\n\nLogin to view your current order status and order history. Remember to login when you make your next purchase for a faster checkout experience!", array('!user_url' => url('user'))); - $messages['completion_new_user'] = t("Thank you for shopping at [store-name]. A new account has been created for you here that you may use to view your current order status.\n\nLogin to your new account using the following information:\n\nUsername: !new_username\nPassword: !new_password", array('!user_url' => url('user'))); + $messages['completion_new_user'] = t("Thank you for shopping at [store-name]. A new account has been created for you here that you may use to view your current order status.\n\nYour password and further instructions have been sent to your e-mail address."); + $messages['completion_new_user_logged_in'] = t("Thank you for shopping at [store-name]. A new account has been created for you here that you may use to view your current order status.\n\nYour password and further instructions have been sent to your e-mail address.\n\nFor your convenience, you are already logged in with your newly created account."); $messages['continue_shopping'] = t('Return to the front page.'); return $messages; @@ -1186,116 +1188,105 @@ function uc_cart_continue_shopping_url($unset = TRUE) { function uc_cart_complete_sale($order, $login = FALSE) { global $user; - // Logic to create new user if necessary: - if ($order->uid == 0) { - // Check for an existing user account with the e-mail address from checkout. - $result = db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $order->primary_email); - - // If it was found, update the order. - if ($account = db_fetch_object($result)) { - $order->uid = $account->uid; - $account = user_load($account->uid); - db_query("UPDATE {uc_orders} SET uid = %d WHERE order_id = %d", $order->uid, $order->order_id); - $message_type = 'existing_user'; - } - else { - // Get a valid new username. - if (empty($order->data['new_user']['name'])) { - $name = uc_store_email_to_username($order->primary_email); - } - else { - $name = $order->data['new_user']['name']; - } + // Ensure we have the latest order data. + $order->data = unserialize(db_result(db_query("SELECT data FROM {uc_orders} WHERE order_id = %d", $order->order_id))); - // Setup the account fields array and save it as a new user. - $fields = array( - 'name' => $name, - 'mail' => $order->primary_email, - 'init' => $order->primary_email, - 'pass' => empty($order->data['new_user']['pass']) ? user_password(variable_get('uc_pwd_length', 6)) : $order->data['new_user']['pass'], - 'roles' => array(), - 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0, - ); - $account = user_save('', $fields); + // Ensure that user creation and triggers are only run once. + if (empty($order->data['complete_sale'])) { + uc_cart_complete_sale_account($order); - // Send the customer their account details if enabled. - if (variable_get('uc_new_customer_email', TRUE)) { - // Manually set the password so it appears in the e-mail. - $account->password = $fields['pass']; + // Store account data. + db_query("UPDATE {uc_orders} SET uid = %d, data = '%s' WHERE order_id = %d", $order->uid, serialize($order->data), $order->order_id); - // Send the e-mail through the user module. - drupal_mail('user', 'register_no_approval_required', $order->primary_email, NULL, array('account' => $account), uc_store_email_from()); + // Move an order's status from "In Checkout" to "Pending" + $status = db_result(db_query("SELECT order_status FROM {uc_orders} WHERE order_id = %d", $order->order_id)); + if (uc_order_status_data($status, 'state') == 'in_checkout') { + $status = uc_order_state_default('post_checkout'); + if (uc_order_update_status($order->order_id, $status)) { + $order->order_status = $status; } - - // Store the login details in the session for use on the page display. - $_SESSION['new_user'] = array('name' => $fields['name'], 'pass' => $fields['pass']); - - // Update the order's uid in this request and in the database. - $order->uid = $account->uid; - unset($order->data['new_user']['pass']); - db_query("UPDATE {uc_orders} SET uid = %d, data = '%s' WHERE order_id = %d", $order->uid, serialize($order->data), $order->order_id); - - // Login the user if specified. - if ($login) { - $form_state = array('values' => $fields); - drupal_execute('user_login', $form_state); - } - - $message_type = 'new_user'; } - } - else { - if ($order->uid == $user->uid) { - $message_type = 'logged_in'; - $account = clone $user; - } - else { - $message_type = 'existing_user'; - $account = user_load($order->uid); - } - } - $messages = array(); - $messages['uc_msg_order_submit_format'] = variable_get('uc_msg_order_submit', uc_get_message('completion_message')); - if ($message = variable_get('uc_msg_order_'. $message_type, uc_get_message('completion_'.$message_type))) { - if (isset($_SESSION['new_user'])) { - $variables['!new_username'] = check_plain($_SESSION['new_user']['name']); - $variables['!new_password'] = check_plain($_SESSION['new_user']['pass']); - $messages['uc_msg_order_'. $message_type .'_format'] = strtr($message, $variables); - } - else { - $messages['uc_msg_order_'. $message_type .'_format'] = $message; - } + // Invoke the checkout complete trigger and hook. + $account = user_load($order->uid); + module_invoke_all('uc_checkout_complete', $order, $account); + ca_pull_trigger('uc_checkout_complete', $order, $account); } - $messages['uc_msg_continue_shopping_format'] = variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')); - $output_message = ''; - foreach ($messages as $format => $message) { - $message = token_replace_multiple($message, array('global' => NULL, 'order' => $order)); - $message = check_markup($message, variable_get($format, FILTER_FORMAT_DEFAULT), FALSE); - $output_message .= $message; + $type = $order->data['complete_sale']; + + // Log in new users, if requested. + if ($type == 'new_user' && $login && !$user->uid) { + $type = 'new_user_logged_in'; + $user = user_load($order->uid); } - $themed_output = theme('uc_cart_complete_sale', $output_message, $order); - // Move an order's status from "In Checkout" to "Pending" - $status = db_result(db_query("SELECT order_status FROM {uc_orders} WHERE order_id = %d", $order->order_id)); - if (uc_order_status_data($status, 'state') == 'in_checkout') { - $status = uc_order_state_default('post_checkout'); - if (uc_order_update_status($order->order_id, $status)) { - $order->order_status = $status; - } + $messages = array( + 'uc_msg_order_submit' => uc_get_message('completion_message'), + 'uc_msg_order_' . $type => uc_get_message('completion_' . $type), + 'uc_msg_continue_shopping' => uc_get_message('continue_shopping'), + ); + foreach ($messages as $id => &$message) { + $message = variable_get($id, $message); + $message = token_replace_multiple($message, array('global' => NULL, 'order' => $order)); + $message = check_markup($message, variable_get($id . '_format', FILTER_FORMAT_DEFAULT), FALSE); } + $output = implode('', $messages); // Empty that cart... uc_cart_empty(uc_cart_get_id(FALSE), 'checkout'); - module_invoke_all('uc_checkout_complete', $order, $account); - ca_pull_trigger('uc_checkout_complete', $order, $account); + // Clear out the session variables used to force the cart workflow. + unset($_SESSION['cart_order'], $_SESSION['do_complete']); + + return theme('uc_cart_complete_sale', $output, $order); +} - // Clear our the session variables used to force the cart workflow. - unset($_SESSION['cart_order'], $_SESSION['do_complete'], $_SESSION['new_user']); +/** + * Link a completed sale to a user. + * + * @param $order + * The order object that has just been completed. + */ +function uc_cart_complete_sale_account($order) { + // Order already has a user ID, so the user was logged in during checkout. + if ($order->uid) { + $order->data['complete_sale'] = 'logged_in'; + return; + } + + $result = db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s')", $order->primary_email); + + // Email address matches an existing account. + if ($account = db_fetch_object($result)) { + $order->uid = $account->uid; + $order->data['complete_sale'] = 'existing_user'; + return; + } + + // Create a new user. + $fields = isset($order->data['new_user']) ? $order->data['new_user'] : array(); + $fields += array( + 'name' => uc_store_email_to_username($order->primary_email), + 'mail' => $order->primary_email, + 'init' => $order->primary_email, + 'pass' => user_password(), + 'roles' => array(), + 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0, + ); + $account = user_save('', $fields); + + // Send the customer their account details if enabled. + if (variable_get('uc_new_customer_email', TRUE)) { + // Manually set the password so it appears in the e-mail. + $account->password = $fields['pass']; + drupal_mail('user', 'register_no_approval_required', $order->primary_email, NULL, array('account' => $account), uc_store_email_from()); + } - return $themed_output; + // Store username only; don't store password in plaintext. + $order->uid = $account->uid; + $order->data['new_user'] = array('name' => $fields['name']); + $order->data['complete_sale'] = 'new_user'; } /** diff --git a/uc_cart/uc_cart.test b/uc_cart/uc_cart.test index 584a841..26659dd 100644 --- a/uc_cart/uc_cart.test +++ b/uc_cart/uc_cart.test @@ -21,6 +21,40 @@ class UbercartCartCheckoutTest extends UbercartTestHelper { ); } + function setUp() { + $modules = array('uc_payment', 'uc_payment_pack', 'uc_roles'); + $permissions = array('administer permissions', 'administer product features'); + parent::setUp($modules, $permissions); + } + + /** + * Creates a new order. + */ + function createOrder($fields = array()) { + $order = uc_order_new(); + foreach ($fields as $key => $value) { + $order->$key = $value; + } + + if (empty($order->primary_email)) { + $order->primary_email = $this->randomString() .'@example.org'; + } + + if (!isset($fields['products'])) { + $item = clone $this->product; + $item->qty = 1; + $item->price = $item->sell_price; + $item->data = array(); + $order->products = array($item); + } + + $order->order_total = uc_order_get_total($order, TRUE); + $order->line_items = uc_order_load_line_items($order, TRUE); + uc_order_save($order); + + return $order; + } + function testCart() { // Test the empty cart text. $this->drupalGet('cart'); @@ -50,17 +84,113 @@ class UbercartCartCheckoutTest extends UbercartTestHelper { } function testCheckout() { + // Log in new users after checkout. + $this->drupalLogin($this->adminUser); + $this->drupalPost('admin/store/settings/checkout/edit', array('uc_new_customer_login' => TRUE), t('Save configuration')); + $this->drupalLogout(); + // Test as anonymous user. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart')); $this->checkout(); $this->assertRaw('Your order is complete!'); + $this->assertRaw('you are already logged in'); - // Test as authenticated user. - $this->drupalLogin($this->customer); + // Confirm login. + $this->drupalGet(''); + $this->assertText('My account', 'User is logged in.'); + + // Check that cart is now empty. + $this->drupalGet('cart'); + $this->assertText('There are no products in your shopping cart.'); + + // Test again as authenticated user. $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart')); $this->checkout(); $this->assertRaw('Your order is complete!'); + $this->assertRaw('While logged in'); $this->drupalLogout(); + + // Test again with an existing email address + $this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart')); + $this->checkout(array('panes[customer][primary_email]' => $this->customer->mail)); + $this->assertRaw('Your order is complete!'); + $this->assertRaw('order has been attached to the account we found'); + } + + function testCheckoutComplete() { + $order_data = array('primary_email' => 'simpletest@ubercart.org'); + + // Payment notification is received first. + $order = $this->createOrder($order_data); + uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total); + $output = uc_cart_complete_sale($order); + $this->verbose($output); + + // Check that a new account was created. + $this->assertTrue(strpos($output, 'new account has been created') !== FALSE, 'Checkout message mentions new account.'); + + // 3 e-mails: new account, customer invoice, admin invoice + $mails = $this->drupalGetMails(); + $this->assertEqual(count($mails), 3, '3 e-mails were sent.'); + variable_del('drupal_test_email_collector'); + + // Same user, new order, sees the checkout page first. + $order = $this->createOrder($order_data); + $output = uc_cart_complete_sale($order, TRUE); + uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total); + $this->verbose($output); + + // 2 e-mails: customer invoice, admin invoice + $mails = $this->drupalGetMails(); + $this->assertEqual(count($mails), 2, '2 e-mails were sent.'); + variable_del('drupal_test_email_collector'); + } + + function testCheckoutRoleAssignment() { + // Add role assignment to the test product. + $rid = $this->drupalCreateRole(array('access content')); + $this->drupalLogin($this->adminUser); + $this->drupalPost('node/'. $this->product->nid .'/edit/features', array('feature' => 'role'), t('Add')); + $this->drupalPost(NULL, array('uc_roles_role' => $rid), t('Save feature')); + + // Process an anonymous, shippable order. + $item = clone $this->product; + $item->qty = 1; + $item->price = $item->sell_price; + $item->data = array('shippable' => TRUE); + $order = $this->createOrder(array( + 'products' => array($item), + )); + uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total); + + // Find the order uid. + $uid = db_result(db_query("SELECT uid FROM {uc_orders} ORDER BY order_id DESC")); + $account = user_load($uid); + $this->assertTrue(isset($account->roles[$rid]), 'New user was granted role.'); + $order = uc_order_load($order->order_id); + $this->assertEqual($order->order_status, 'payment_received', 'Shippable order was set to payment received.'); + + // 4 e-mails: new account, customer invoice, admin invoice, role assignment + $mails = $this->drupalGetMails(); + $this->assertEqual(count($mails), 4, '4 e-mails were sent.'); + variable_del('drupal_test_email_collector'); + + // Test again with an existing email address and a non-shippable order. + $item->data = array('shippable' => FALSE); + $order = $this->createOrder(array( + 'primary_email' => $this->customer->mail, + 'products' => array($item), + )); + uc_payment_enter($order->order_id, 'SimpleTest', $order->order_total); + $account = user_load($this->customer->uid); + $this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.'); + $order = uc_order_load($order->order_id); + $this->assertEqual($order->order_status, 'completed', 'Non-shippable order was set to completed.'); + + // 3 e-mails: customer invoice, admin invoice, role assignment + $mails = $this->drupalGetMails(); + $this->assertEqual(count($mails), 3, '3 e-mails were sent.'); + variable_del('drupal_test_email_collector'); } } diff --git a/uc_file/uc_file.ca.inc b/uc_file/uc_file.ca.inc index 43d567f..809331b 100644 --- a/uc_file/uc_file.ca.inc +++ b/uc_file/uc_file.ca.inc @@ -44,12 +44,12 @@ function uc_file_ca_predicate() { '#conditions' => array( array( '#name' => 'uc_order_status_condition', - '#title' => t('If the order status is completed.'), + '#title' => t('If the updated order status is payment received.'), '#argument_map' => array( 'order' => 'updated_order', ), '#settings' => array( - 'order_status' => 'completed', + 'order_status' => 'payment_received', ), ), ), diff --git a/uc_order/templates/uc_order-customer.tpl.php b/uc_order/templates/uc_order-customer.tpl.php index c052642..8ec90b4 100644 --- a/uc_order/templates/uc_order-customer.tpl.php +++ b/uc_order/templates/uc_order-customer.tpl.php @@ -39,10 +39,8 @@

$order_first_name)); ?>

- -

-


-

+ data['new_user'])) { ?> +


diff --git a/uc_order/uc_order.ca.inc b/uc_order/uc_order.ca.inc index 5d7f4a0..1afd16c 100644 --- a/uc_order/uc_order.ca.inc +++ b/uc_order/uc_order.ca.inc @@ -128,6 +128,16 @@ function uc_order_ca_condition() { ), ); + $conditions['uc_order_state_condition'] = array( + '#title' => t('Check the order state'), + '#description' => t('Returns TRUE if the current order status belong to the order state specified below.'), + '#category' => t('Order'), + '#callback' => 'uc_order_condition_check_order_state', + '#arguments' => array( + 'order' => $order_arg, + ), + ); + $conditions['uc_order_condition_total'] = array( '#title' => t('Check the order total'), '#description' => t('Returns TRUE if the current order total is within the parameters below.'), @@ -368,6 +378,36 @@ function uc_order_condition_check_order_status_form($form_state, $settings = arr } /** + * Check the current order state. + * + * @see uc_order_condition_check_order_state_form() + */ +function uc_order_condition_check_order_state($order, $settings) { + // Return TRUE if the order status matches. + return uc_order_status_data($order->order_status, 'state') == $settings['order_state']; +} + +/** + * @see uc_order_condition_check_order_state() + */ +function uc_order_condition_check_order_state_form($form_state, $settings = array()) { + foreach (uc_order_state_list('general') as $state) { + $options[$state['id']] = $state['title']; + } + foreach (uc_order_state_list('specific') as $state) { + $options[$state['id']] = $state['title']; + } + $form['order_state'] = array( + '#type' => 'select', + '#title' => t('Order state'), + '#options' => $options, + '#default_value' => $settings['order_state'], + ); + + return $form; +} + +/** * Check the current order balance. * * @see uc_order_condition_total_form() diff --git a/uc_order/uc_order.module b/uc_order/uc_order.module index 3fdf9b0..2836bf6 100644 --- a/uc_order/uc_order.module +++ b/uc_order/uc_order.module @@ -414,13 +414,11 @@ function uc_order_token_values($type, $object = NULL) { case 'order': $order = $object; - if (isset($_SESSION['new_user']) && is_array($_SESSION['new_user'])) { - $values['new-username'] = check_plain($_SESSION['new_user']['name']); - $values['new-password'] = check_plain($_SESSION['new_user']['pass']); + if (isset($order->data['new_user']['name'])) { + $values['new-username'] = $order->data['new_user']['name']; } else { $values['new-username'] = ''; - $values['new-password'] = ''; } $values['order-id'] = $order->order_id; $values['order-uid'] = $order->uid; @@ -492,7 +490,6 @@ function uc_order_token_list($type = 'all') { if ($type == 'order' || $type == 'ubercart' || $type == 'all') { $tokens['order']['new-username'] = t('New username associated with an order if applicable.'); - $tokens['order']['new-password'] = t('New password associated with an order if applicable.'); $tokens['order']['order-id'] = t('The order ID.'); $tokens['order']['order-uid'] = t('The user ID of the order.'); $tokens['order']['order-url'] = t('The URL to the order'); @@ -1347,7 +1344,12 @@ function uc_order_update_status($order_id, $status) { // Attempt the update if the order exists. if ($order !== FALSE) { - // Return false if any module says the update is not good to go. + // Return TRUE if the order status is already set. + if ($order->order_status == $status) { + return TRUE; + } + + // Return FALSE if any module says the update is not good to go. foreach (module_list() as $module) { $function = $module .'_order'; // $order must be passed by reference. diff --git a/uc_roles/uc_roles.ca.inc b/uc_roles/uc_roles.ca.inc index 749703f..653f4d3 100644 --- a/uc_roles/uc_roles.ca.inc +++ b/uc_roles/uc_roles.ca.inc @@ -44,23 +44,12 @@ function uc_roles_ca_predicate() { '#conditions' => array( array( '#name' => 'uc_order_status_condition', - '#title' => t('If the original order status was not Completed.'), - '#argument_map' => array( - 'order' => 'order', - ), - '#settings' => array( - 'negate' => TRUE, - 'order_status' => 'completed', - ), - ), - array( - '#name' => 'uc_order_status_condition', - '#title' => t('If the updated order status is Completed.'), + '#title' => t('If the updated order status is payment received.'), '#argument_map' => array( 'order' => 'updated_order', ), '#settings' => array( - 'order_status' => 'completed', + 'order_status' => 'payment_received', ), ), ),