function uc_checkout_pane_quotes in Ubercart 5
Same name and namespace in other branches
- 6.2 shipping/uc_quote/uc_quote.module \uc_checkout_pane_quotes()
- 7.3 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.
1 call to uc_checkout_pane_quotes()
- uc_paypal_ec_review_form in payment/
uc_paypal/ uc_paypal.module
1 string reference to 'uc_checkout_pane_quotes'
- uc_quote_checkout_pane in shipping/
uc_quote/ uc_quote.module - Defines the shipping quote checkout pane.
File
- shipping/
uc_quote/ uc_quote.module, line 1070 - The controller module for fulfillment modules that process physical goods.
Code
function uc_checkout_pane_quotes($op, &$arg1, $arg2) {
global $user;
switch ($op) {
case 'view':
$description = check_markup(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.')), variable_get('uc_quote_desc_format', FILTER_FORMAT_DEFAULT));
// Let Javascript know where we are.
$contents['page'] = array(
'#type' => 'hidden',
'#value' => 'checkout',
);
$contents['uid'] = array(
'#type' => 'hidden',
'#value' => $user->uid,
);
$contents['quote_button'] = array(
'#type' => 'button',
'#value' => t('Click to calculate shipping'),
'#weight' => 0,
);
uc_add_js(array(
'uc_quote' => array(
'progress_msg' => t('Receiving quotes:'),
'err_msg' => check_markup(variable_get('uc_quote_err_msg', t("There were problems getting a shipping quote. Please verify the delivery address and product information and try again.\nIf this does not resolve the issue, please call @phone to complete your order.", array(
'@phone' => variable_get('uc_store_phone', null),
))), variable_get('uc_quote_msg_format', FILTER_FORMAT_DEFAULT), false),
),
), 'setting');
uc_add_js('misc/progress.js');
uc_add_js(drupal_get_path('module', 'uc_quote') . '/uc_quote.js');
$default = $arg1->quote['method'] . '---' . ($arg1->quote['accessorials'] ? $arg1->quote['accessorials'] : 0);
$prod_string = '';
foreach (uc_cart_get_contents() as $item) {
$prod_string .= '|' . $item->nid;
$prod_string .= '^' . $item->title;
$prod_string .= '^' . $item->model;
$prod_string .= '^' . $item->manufacturer;
$prod_string .= '^' . $item->qty;
$prod_string .= '^' . $item->cost;
$prod_string .= '^' . $item->price;
$prod_string .= '^' . $item->weight;
$prod_string .= '^' . serialize($item->data);
}
$prod_string = substr($prod_string, 1);
// If a previous quote gets loaded, make sure it gets saved again.
// Also, make sure the previously checked option is checked by default.
uc_add_js('$(function() {
setQuoteCallbacks("' . urlencode($prod_string) . '");
var quoteButton = $("input:radio[@name=quote-option]").click(function() {
var quoteButton = $(this);
var label = quoteButton.parent("label").text().split(":", 2)[0];
quoteButton.end();
var rate = $("input:hidden[@name=\'rate[" + quoteButton.val() + "]\']").val();
set_line_item("shipping", label, rate, 1, 1, false);
if (window.getTax) {
getTax();
}
else if (window.render_line_items) {
render_line_items();
}
}).filter("[@value=' . $default . ']").click();
var quoteDiv = $("#quote");
if (quoteDiv.length && $("#quote input[@name=quote-form]").length == 0) {
quoteDiv.append("<input type=\\"hidden\\" name=\\"quote-form\\" value=\\"" + encodeURIComponent(quoteDiv.html()) + "\\" />");
}
});', 'inline');
return array(
'description' => $description,
'contents' => $contents,
);
case 'process':
if (!isset($_POST['quote-option'])) {
if (variable_get('uc_quote_require_quote', true)) {
drupal_set_message(t('You must select a shipping option before continuing.'), 'error');
return false;
}
else {
return true;
}
}
$details = array();
foreach ($arg1 as $key => $value) {
if (strpos($key, 'delivery_') !== false) {
$details[substr($key, 9)] = $value;
}
}
$products = array();
foreach ($arg1->products as $id => $product) {
$node = (array) node_load($product->nid);
foreach ($node as $key => $value) {
if (!isset($product->{$key})) {
$product->{$key} = $value;
}
}
$arg1->products[$id] = $product;
}
$quote_option = explode('---', $_POST['quote-option']);
$arg1->quote['method'] = $quote_option[0];
$arg1->quote['accessorials'] = $quote_option[1];
$_SESSION['quote']['quote_form'] = rawurldecode($_POST['quote-form']);
$methods = array_filter(module_invoke_all('shipping_method'), '_uc_quote_method_enabled');
$method = $methods[$quote_option[0]];
$quote_data = array();
ob_start();
workflow_ng_invoke_event('get_quote_from_' . $method['id'], $arg1, $method, $user);
$quote_string = ob_get_contents();
ob_end_clean();
$quote_data = unserialize($quote_string);
if (!isset($quote_data[$quote_option[1]])) {
drupal_set_message(t('Invalid option selected. Recalculate shipping quotes to continue.'), 'error');
return false;
}
$label = $method['quote']['accessorials'][$quote_option[1]];
$arg1->quote['rate'] = $quote_data[$quote_option[1]]['rate'];
$result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = %d AND type = 'shipping'", $arg1->order_id);
if ($lid = db_result($result)) {
uc_order_update_line_item($lid, $label, $arg1->quote['rate']);
}
else {
uc_order_line_item_add($arg1->order_id, 'shipping', $label, $arg1->quote['rate']);
}
return true;
case 'review':
$result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = %d AND type = '%s'", $arg1->order_id, 'shipping');
if ($line_item = db_fetch_object($result)) {
$review[] = array(
'title' => $line_item->title,
'data' => uc_currency_format($line_item->amount),
);
}
return $review;
}
}