diff --git a/payment/uc_google_checkout/uc_google_checkout.module b/payment/uc_google_checkout/uc_google_checkout.module index 49f28ef..ef07377 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..c3743dc 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 on full payment'), + '#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_paypal/uc_paypal.pages.inc b/payment/uc_paypal/uc_paypal.pages.inc index 93c452f..c54bd57 100644 --- a/payment/uc_paypal/uc_paypal.pages.inc +++ b/payment/uc_paypal/uc_paypal.pages.inc @@ -116,8 +116,8 @@ function uc_paypal_ipn() { watchdog('uc_paypal', 'Payment @txn_id for order @order_id did not equal the order total.', array('@txn_id' => $txn_id, '@order_id' => $order->order_id), WATCHDOG_WARNING, l(t('view'), 'admin/store/orders/'. $order->order_id)); } $comment = t('PayPal transaction ID: @txn_id', array('@txn_id' => $txn_id)); - uc_payment_enter($order_id, 'paypal_wps', $payment_amount, $order->uid, NULL, $comment); uc_cart_complete_sale($order); + uc_payment_enter($order_id, 'paypal_wps', $payment_amount, $order->uid, NULL, $comment); uc_order_comment_save($order_id, 0, t('Payment of @amount @currency submitted through PayPal.', array('@amount' => uc_price($payment_amount, $context, $options), '@currency' => $payment_currency)), 'order', 'payment_received'); uc_order_comment_save($order_id, 0, t('PayPal IPN reported a payment of @amount @currency.', array('@amount' => uc_price($payment_amount, $context, $options), '@currency' => $payment_currency))); break; diff --git a/uc_cart/uc_cart.admin.inc b/uc_cart/uc_cart.admin.inc index 7fc865c..6723f25 100644 --- a/uc_cart/uc_cart.admin.inc +++ b/uc_cart/uc_cart.admin.inc @@ -512,19 +512,6 @@ function uc_cart_checkout_messages_form() { ); $form['checkout_messages']['uc_msg_order_logged_in_format'] = filter_form(variable_get('uc_msg_order_logged_in_format', FILTER_FORMAT_DEFAULT), NULL, array('uc_msg_order_logged_in_format')); - $form['checkout_messages']['uc_msg_order_existing_user'] = array( - '#type' => 'textarea', - '#title' => t('Checkout completion for existing users'), - '#description' => t("Message displayed upon checkout for a user who has an account but wasn't logged in. Uses order and global tokens.", array('!url' => url('admin/store/help/tokens'))), - '#summary' => variable_get('uc_msg_order_existing_user', uc_get_message('completion_existing_user')) - ? t("Completion text for users who aren't logged in is set.") - : t("Completion text for users who aren't logged in is not set."), - - '#default_value' => variable_get('uc_msg_order_existing_user', uc_get_message('completion_existing_user')), - '#rows' => 3, - ); - $form['checkout_messages']['uc_msg_order_existing_user_format'] = filter_form(variable_get('uc_msg_order_existing_user_format', FILTER_FORMAT_DEFAULT), NULL, array('uc_msg_order_existing_user_format')); - $form['checkout_messages']['uc_msg_order_new_user'] = array( '#type' => 'textarea', '#title' => t('Checkout completion for new users'), @@ -537,6 +524,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 450089a..e2260d7 100644 --- a/uc_cart/uc_cart.module +++ b/uc_cart/uc_cart.module @@ -263,9 +263,9 @@ function uc_cart_init() { $conf['i18n_variables'][] = 'uc_continue_shopping_text'; $conf['i18n_variables'][] = 'uc_minimum_subtotal_text'; $conf['i18n_variables'][] = 'uc_msg_continue_shopping'; - $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'; } @@ -755,8 +755,8 @@ function uc_cart_uc_message() { $messages['review_instructions'] = t("Your order is almost complete. Please review the details below and click 'Submit order' if all the information is correct. You may use the 'Back' button to make changes to your order if necessary."); $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; @@ -1187,33 +1187,27 @@ 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); + // 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))); - // 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'; + // Ensure that user creation and triggers are only run once. + if (empty($order->data['complete_sale'])) { + + // Ensure that the order has a user account attached. + if ($order->uid) { + $order->data['complete_sale'] = 'logged_in'; } 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']; + // Create a new user. + if (!isset($order->data['new_user'])) { + $order->data['new_user'] = array(); } - // Setup the account fields array and save it as a new user. - $fields = array( - 'name' => $name, + $fields = $order->data['new_user'] + array( + 'name' => uc_store_email_to_username($order->primary_email), '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'], + 'pass' => user_password(), 'roles' => array(), 'status' => variable_get('uc_new_customer_status_active', TRUE) ? 1 : 0, ); @@ -1223,80 +1217,61 @@ function uc_cart_complete_sale($order, $login = FALSE) { if (variable_get('uc_new_customer_email', TRUE)) { // Manually set the password so it appears in the e-mail. $account->password = $fields['pass']; - - // 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()); } - // 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. + // Store account details in the order, ensuring the password is + // not stored in plaintext. $order->uid = $account->uid; - unset($order->data['new_user']['pass']); + $order->data['complete_sale'] = 'new_user'; + $order->data['new_user'] = array('name' => $fields['name']); 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); + // 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; } - - $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); } + + // 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 = 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; - } + $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); } - $messages['uc_msg_continue_shopping_format'] = variable_get('uc_msg_continue_shopping', uc_get_message('continue_shopping')); + + $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'), + ); $output_message = ''; - foreach ($messages as $format => $message) { + foreach ($messages as $id => $default) { + $message = variable_get($id, $default); $message = token_replace_multiple($message, array('global' => NULL, 'order' => $order)); - $message = check_markup($message, variable_get($format, FILTER_FORMAT_DEFAULT), FALSE); + $message = check_markup($message, variable_get($id . '_format', FILTER_FORMAT_DEFAULT), FALSE); $output_message .= $message; } - $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; - } - } // 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 our the session variables used to force the cart workflow. - unset($_SESSION['cart_order'], $_SESSION['do_complete'], $_SESSION['new_user']); + // Clear out the session variables used to force the cart workflow. + unset($_SESSION['cart_order'], $_SESSION['do_complete']); - return $themed_output; + return theme('uc_cart_complete_sale', $output_message, $order); } /** 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 7ce5aa0..6843381 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 2c5a71b..cee9c18 100644 --- a/uc_order/uc_order.module +++ b/uc_order/uc_order.module @@ -365,13 +365,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['complete_sale']['new_user'])) { + $values['new-username'] = $order->data['complete_sale']['new_user']; } else { $values['new-username'] = ''; - $values['new-password'] = ''; } $values['order-id'] = $order->order_id; $values['order-uid'] = $order->uid; @@ -443,7 +441,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');