uc_optional_checkout_review.module in Ubercart Optional Checkout Review 7
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
*/
/**
* Implementats hook_form_FORM_ID_alter().
*
* This #submit handler must be *last* so that all others get their chance at
* processing.
* @see uc_optional_checkout_review_enable()
*/
function uc_optional_checkout_review_form_uc_cart_checkout_settings_form_alter(&$form, &$form_state, $form_id) {
$form['checkout']['uc_optional_checkout_review'] = array(
'#type' => 'checkbox',
'#title' => t('Skip checkout review'),
'#default_value' => variable_get('uc_optional_checkout_review', FALSE),
);
}
/**
* Implementats hook_form_FORM_ID_alter().
*/
function uc_optional_checkout_review_form_uc_cart_checkout_form_alter(&$form, &$form_state, $form_id) {
if (variable_get('uc_optional_checkout_review', FALSE)) {
$form['#submit'][] = 'uc_optional_checkout_review_uc_cart_checkout_form_submit';
$form['actions']['continue']['#value'] = t('Submit order');
}
}
/**
* Submit handler
*/
function uc_optional_checkout_review_uc_cart_checkout_form_submit($form, &$form_state) {
// NB: we explicitly check the form_id because of #2314427 (uc_payafter)
if (variable_get('uc_optional_checkout_review', FALSE) && $form['#form_id'] == 'uc_cart_checkout_form') {
$order = $form_state['storage']['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);
}
else {
$form_state['values']['op'] = t('Submit order');
$form_state['uc_order'] = $order;
$uc_credit_enabled = module_exists('uc_credit');
// c.f. http://drupal.org/node/1519042
if ($uc_credit_enabled && isset($_SESSION['sescrd'])) {
$_POST['sescrd'] = base64_encode($_SESSION['sescrd']);
}
drupal_form_submit('uc_cart_checkout_review_form', $form_state);
// Ensure that if the checkout fails we don't get redirected to the
// review page.
if ($uc_credit_enabled && $form_state['redirect'] == $form_state['storage']['base_path'] . '/checkout/review') {
// @see uc_credit_form_uc_cart_checkout_review_form_alter().
// Send them back to the checkout form to put in their details again.
drupal_set_message(t('To protect our customers from identity theft, credit card details are erased when a browser refreshes on the checkout page. Please enter your card details again and re-submit the form.'), 'error');
$_SESSION['clear_cc'] = TRUE;
unset($_SESSION['cc_pay']);
$form_state['redirect'] = $form_state['storage']['base_path'] . '/checkout';
}
$form_state['programmed'] = FALSE;
}
}
}
Functions
Name![]() |
Description |
---|---|
uc_optional_checkout_review_form_uc_cart_checkout_form_alter | Implementats hook_form_FORM_ID_alter(). |
uc_optional_checkout_review_form_uc_cart_checkout_settings_form_alter | Implementats hook_form_FORM_ID_alter(). |
uc_optional_checkout_review_uc_cart_checkout_form_submit | Submit handler |