function uc_checkout_pane_discounts in Ubercart Discounts (Alternative) 6.2
Discounts checkout pane callback
More information at http://www.ubercart.org/docs/developer/245/checkout
1 string reference to 'uc_checkout_pane_discounts'
- uc_discounts_checkout_pane in uc_discounts/
uc_discounts.module - Implementation of hook_checkout_pane().
File
- uc_discounts/
uc_discounts.module, line 548
Code
function uc_checkout_pane_discounts($op, &$arg1, $arg2) {
global $user;
switch ($op) {
case "view":
$description = t("Enter discount codes in the box below (one per line).");
//If viewing an existing order, load order's codes
if (!empty($arg1->order_id)) {
$codes_string = uc_discounts_codes_to_str(uc_discounts_get_codes_for_order($arg1->order_id));
}
$contents["uc-discounts-codes"] = array(
"#type" => "textarea",
"#default_value" => $codes_string,
"#rows" => 5,
"#prefix" => "<div class='discount-codes-wrapper'>",
"#suffix" => "</div>",
);
$contents["uc-discounts-placeholder"] = array(
"#type" => "hidden",
"#prefix" => "<div class='uc-discounts-messages-container'>",
"#suffix" => "</div>",
);
$contents["uc-discounts-button"] = array(
"#type" => "button",
"#value" => t("Click to calculate discounts"),
);
return array(
"description" => $description,
"contents" => $contents,
);
case "process":
// Save form values from checkout pane in order ($arg1).
$arg1->uc_discounts_codes = uc_discounts_codes_to_array($arg2['uc-discounts-codes']);
drupal_alter('uc_discounts_codes', $arg1, 'pane_submit');
$has_code_errors = FALSE;
$errors = array();
$warnings = array();
$discounts = get_discounts_for_order($arg1, $errors, $warnings);
// Make sure the recorded discount codes for the order were only the ones that were actually used
// for a discount.
$applied_codes = array();
foreach ($discounts as $discount) {
$applied_codes[] = $discount->code;
}
$arg1->uc_discounts_codes = $applied_codes;
foreach ($errors as $error) {
drupal_set_message($error, "error");
}
foreach ($warnings as $warning) {
drupal_set_message(t('Warning: @warning', array(
'@warning' => $warning,
)), 'error');
}
//If there were errors, return FALSE
if (!empty($errors)) {
return FALSE;
}
//Add discount line items to order
add_discount_line_items_to_order($arg1, $discounts);
//Mark order as needing discount line items updated
$arg1->uc_discounts_line_items_need_updating = TRUE;
break;
}
}