function uc_checkout_pane_quotes in Ubercart 7.3
Same name and namespace in other branches
- 5 shipping/uc_quote/uc_quote.module \uc_checkout_pane_quotes()
- 6.2 shipping/uc_quote/uc_quote.module \uc_checkout_pane_quotes()
Shipping quote checkout pane callback.
Selects a quoting method based on the enabled methods' weight and the types of products in the cart. The "Get Quotes" button fires a callback that returns a form for the customer to select a rate based on their needs and preferences.
Adds a line item to the order that records the chosen shipping quote.
See also
uc_quote_checkout_pane_quotes_submit()
1 call to uc_checkout_pane_quotes()
- uc_paypal_ec_review_form in payment/
uc_paypal/ uc_paypal.pages.inc - Returns the form for the custom Review Payment screen for Express Checkout.
1 string reference to 'uc_checkout_pane_quotes'
- uc_quote_uc_checkout_pane in shipping/
uc_quote/ uc_quote.module - Defines the shipping quote checkout pane.
File
- shipping/
uc_quote/ uc_quote.module, line 521 - The controller module for fulfillment modules that process physical goods.
Code
function uc_checkout_pane_quotes($op, &$order, $form = NULL, &$form_state = NULL) {
global $user;
switch ($op) {
case 'view':
$description = filter_xss_admin(variable_get('uc_quote_pane_description', t('Shipping quotes are generated automatically when you enter your address and may be updated manually with the button below.')));
$contents['#attached']['css'][] = drupal_get_path('module', 'uc_quote') . '/uc_quote.css';
$contents['uid'] = array(
'#type' => 'hidden',
'#value' => $user->uid,
);
$contents['quote_button'] = array(
'#type' => 'submit',
'#value' => t('Click to calculate shipping'),
'#submit' => array(
'uc_quote_checkout_pane_quotes_submit',
),
'#weight' => 0,
'#ajax' => array(
'effect' => 'slide',
'progress' => array(
'type' => 'bar',
'message' => t('Receiving quotes...'),
),
),
// Shipping quotes can be retrieved even if the form doesn't validate.
'#limit_validation_errors' => array(),
);
$contents['quotes'] = array(
'#tree' => TRUE,
'#prefix' => '<div id="quote">',
'#suffix' => '</div>',
'#weight' => 1,
);
// If this was an Ajax request, we reinvoke the 'prepare' op to ensure
// that we catch any changes in panes heavier than this one.
if (isset($form_state['triggering_element'])) {
uc_checkout_pane_quotes('prepare', $order, $form, $form_state);
}
$contents['quotes'] += $order->quote_form;
$form_state['uc_ajax']['uc_quote']['panes][quotes][quote_button'] = array(
'payment-pane' => 'uc_ajax_replace_checkout_pane',
'quotes-pane' => 'uc_ajax_replace_checkout_pane',
);
$form_state['uc_ajax']['uc_quote']['panes][quotes][quotes][quote_option'] = array(
'payment-pane' => 'uc_ajax_replace_checkout_pane',
);
return array(
'description' => $description,
'contents' => $contents,
);
case 'prepare':
case 'process':
// If a quote was explicitly selected, add it to the order.
if (isset($form['panes']['quotes']['quotes']['quote_option']['#value']) && isset($form['panes']['quotes']['quotes']['quote_option']['#default_value']) && $form['panes']['quotes']['quotes']['quote_option']['#value'] !== $form['panes']['quotes']['quotes']['quote_option']['#default_value']) {
$quote_option = explode('---', $form_state['values']['panes']['quotes']['quotes']['quote_option']);
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$order->data['uc_quote_selected'] = TRUE;
}
// If the current quote was never explicitly selected, discard it and
// use the default.
if (empty($order->data['uc_quote_selected'])) {
unset($order->quote);
}
// Ensure that the form builder uses the default value to decide which
// radio button should be selected.
unset($form_state['input']['panes']['quotes']['quotes']['quote_option']);
$order->quote_form = uc_quote_build_quote_form($order, !empty($form_state['quote_requested']));
$default_option = _uc_quote_extract_default_option($order->quote_form);
if ($default_option) {
$order->quote['rate'] = $order->quote_form[$default_option]['rate']['#value'];
$quote_option = explode('---', $default_option);
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$methods = uc_quote_methods();
$method = $methods[$quote_option[0]];
$label = $method['quote']['accessorials'][$quote_option[1]];
$result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(
':id' => $order->order_id,
':type' => 'shipping',
));
if ($lid = $result
->fetchField()) {
uc_order_update_line_item($lid, $label, $order->quote['rate']);
}
else {
uc_order_line_item_add($order->order_id, 'shipping', $label, $order->quote['rate']);
}
}
else {
unset($order->quote);
}
if (!isset($order->quote) && $op == 'process' && variable_get('uc_quote_require_quote', TRUE)) {
form_set_error('panes][quotes][quotes][quote_option', t('You must select a shipping option before continuing.'));
return FALSE;
}
else {
return TRUE;
}
case 'review':
$review = array();
$result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", array(
':id' => $order->order_id,
':type' => 'shipping',
));
if ($line_item = $result
->fetchAssoc()) {
$review[] = array(
'title' => $line_item['title'],
'data' => theme('uc_price', array(
'price' => $line_item['amount'],
)),
);
}
return $review;
}
}