uc_optional_checkout_review.module in Ubercart Optional Checkout Review 6
Same filename and directory in other branches
Makes the review button on the Ubercart checkout page optional (set by store admin).
Original author: Oliver Coleman, oliver@e-geek.com.au
File
uc_optional_checkout_review.moduleView source
<?php
/**
* @file
* Makes the review button on the Ubercart checkout page optional (set by store admin).
*
* Original author: Oliver Coleman, oliver@e-geek.com.au
*/
/**
* Custom submit handler for uc_cart_checkout_form().
* @see uc_optional_checkout_review_form_alter()
*
* Make sure checkout validated properly before skipping checkout review.
*/
function uc_optional_checkout_review_form_submit($form, &$form_state) {
// If the normal submit handler set do_review then call the review
// form submit function.
if ($_SESSION['do_review'] && $form_state['redirect'] == 'cart/checkout/review') {
// Clear the previous redirect because we're going to override it anyway.
unset($form_state['redirect']);
// Cause the review form to be loaded because some modules may
// do some of their processing here.
uc_cart_checkout_review();
$order = uc_order_load($_SESSION['cart_order']);
if ($order->payment_method == 'paypal_wps') {
$wps_form = drupal_retrieve_form('uc_paypal_wps_form', $form_state, $order);
drupal_prepare_form('uc_paypal_wps_form', $wps_form, $form_state, $order);
$wps_url = $wps_form['#action'] . '?';
foreach (element_children($wps_form) as $key) {
if (isset($wps_form[$key]['#value'])) {
$wps_url .= urlencode($key) . '=' . urlencode($wps_form[$key]['#value']) . '&';
}
}
$wps_url = trim($wps_url, '&');
drupal_goto($wps_url);
}
elseif ($order->payment_method == 'migs') {
$migs_form = drupal_retrieve_form('uc_migs_form', $form_state, $order);
drupal_prepare_form('uc_migs_form', $migs_form, $form_state);
drupal_process_form('uc_migs_form', $migs_form, $form_state);
uc_migs_form_submit($migs_form, $form_state);
}
else {
// Now submit the form. Obviously the $form_state isn't actually
// correct... hopefully nothing will care.
uc_cart_checkout_review_form_submit($form, $form_state);
// And check for an error.
if ($form_state['redirect'] == 'cart/checkout/review') {
// There's an error, so pretend the user clicked back.
uc_cart_checkout_review_form_back($form, $form_state);
}
}
// Ultimately the $form_state changes made by functions above are used.
}
elseif ($form_state['redirect'] != 'cart/checkout') {
// Log any unexpected URLs in 'redirect'.
watchdog('uc_cart', 'Checkout returned unexpected destination url: %url', array(
'%url' => $form_state['redirect'],
), WATCHDOG_DEBUG);
}
}
/**
* Implementation of hook_form_alter().
*
* Changes text on review order button to submit order and adds our custom submit function.
* Adds a "Skip checkout review" option to checkout settings form.
*/
function uc_optional_checkout_review_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'uc_cart_checkout_form':
if (variable_get('uc_checkout_skip_review', FALSE)) {
// Change the submit button label.
$form['continue']['#value'] = variable_get('uc_checkout_submit_button', t('Submit order'));
// Add our submit handler.
$form['#submit'][] = 'uc_optional_checkout_review_form_submit';
// And add our JavaScript file to handle this submit button.
drupal_add_js(drupal_get_path('module', 'uc_optional_checkout_review') . '/uc_optional_checkout_review.js');
// Add the uc_cart css, since it contains the throbber styles that we are using in the JavaScript.
drupal_add_css(drupal_get_path('module', 'uc_cart') . '/uc_cart.css');
}
break;
case 'uc_cart_checkout_settings_form':
// Add a checkbox for enabling this module.
$form['general']['uc_checkout_skip_review'] = array(
'#type' => 'checkbox',
'#title' => t('Skip checkout review.'),
'#default_value' => variable_get('uc_checkout_skip_review', FALSE),
);
break;
}
}
Functions
Name![]() |
Description |
---|---|
uc_optional_checkout_review_form_alter | Implementation of hook_form_alter(). |
uc_optional_checkout_review_form_submit | Custom submit handler for uc_cart_checkout_form(). |