我们略过常规检查不再说明,首先检查是否已经正确设置发货方式。
if (!$_SESSION['shipping']) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
上述代码检查有无设置发货方式,并且检查免运费方式是否设置正确。
// Stock Check
if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $_SESSION['cart']->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
break;
}
}
}
if ($_SESSION['cc_id']) {
$discount_coupon_query = "SELECT coupon_code
FROM " . TABLE_COUPONS . "
WHERE coupon_id = :couponID";
$discount_coupon_query = $db->bindVars($discount_coupon_query, ':couponID', $_SESSION['cc_id'], 'integer');
$discount_coupon = $db->Execute($discount_coupon_query);
}
// if no billing destination address was selected, use the customers own address as default
if (!$_SESSION['billto']) {
$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
} else {
// verify the selected billing address
$check_address_query = "SELECT count(*) AS total FROM " . TABLE_ADDRESS_BOOK . "
WHERE customers_id = :customersID
AND address_book_id = :addressBookID";
$check_address_query = $db->bindVars($check_address_query, ':customersID', $_SESSION['customer_id'], 'integer');
$check_address_query = $db->bindVars($check_address_query, ':addressBookID', $_SESSION['billto'], 'integer');
$check_address = $db->Execute($check_address_query);
if ($check_address->fields['total'] != '1') {
$_SESSION['billto'] = $_SESSION['customer_default_address_id'];
$_SESSION['payment'] = '';
}
}
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping($_SESSION['shipping']);
require(DIR_WS_CLASSES . 'order_total.php');
$order_total_modules = new order_total;
$order_total_modules->collect_posts(); // 先各自统计模块收集提交信息,判断是否正确,并完成相关设置工作
$order_total_modules->pre_confirmation_check(); // 汇总所有统计模块应增加或扣减的金额
$total_weight = $_SESSION['cart']->show_weight();
$total_count = $_SESSION['cart']->count_contents();
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());
if (isset($_GET['payment_error']) && is_object(${$_GET['payment_error']}) && ($error = ${$_GET['payment_error']}->get_error())) {
$messageStack->add('checkout_payment', $error['error'], 'error');
}
<?php
$selection = $payment_modules->selection();
if (sizeof($selection) > 1) {
?>
<p class="important"><?php echo TEXT_SELECT_PAYMENT_METHOD; ?></p>
<?php
} elseif (sizeof($selection) == 0) {
?>
<p class="important"><?php echo TEXT_NO_PAYMENT_OPTIONS_AVAILABLE; ?></p>
<?php
}
?>
<?php
$radio_buttons = 0;
for ($i=0, $n=sizeof($selection); $i<$n; $i++) {
?>
<?php
if (sizeof($selection) > 1) {
if (empty($selection[$i]['noradio'])) {
?>
<?php echo zen_draw_radio_field('payment', $selection[$i]['id'], ($selection[$i]['id'] == $_SESSION['payment'] ? true : false), 'id="pmt-'.$selection[$i]['id'].'"'); ?>
<?php } ?>
<?php
} else {
?>
<?php echo zen_draw_hidden_field('payment', $selection[$i]['id'], 'id="pmt-'.$selection[$i]['id'].'"'); ?>
<?php
}
?>
<label for="pmt-<?php echo $selection[$i]['id']; ?>" class="radioButtonLabel"><?php echo $selection[$i]['module']; ?></label>
<?php
if (defined('MODULE_ORDER_TOTAL_COD_STATUS') && MODULE_ORDER_TOTAL_COD_STATUS == 'true' and $selection[$i]['id'] == 'cod') {
?>
<div class="alert"><?php echo TEXT_INFO_COD_FEES; ?></div>
<?php
} else {
// echo 'WRONG ' . $selection[$i]['id'];
?>
<?php
}
?>
<br class="clearBoth" />
<?php
if (isset($selection[$i]['error'])) {
?>
<div><?php echo $selection[$i]['error']; ?></div>
<?php
} elseif (isset($selection[$i]['fields']) && is_array($selection[$i]['fields'])) {
?>
<div class="ccinfo">
<?php
for ($j=0, $n2=sizeof($selection[$i]['fields']); $j<$n2; $j++) {
?>
<label <?php echo (isset($selection[$i]['fields'][$j]['tag']) ? 'for="'.$selection[$i]['fields'][$j]['tag'] . '" ' : ''); ?>class="inputLabelPayment"><?php echo $selection[$i]['fields'][$j]['title']; ?></label><?php echo $selection[$i]['fields'][$j]['field']; ?>
<br class="clearBoth" />
<?php
}
?>
</div>
<br class="clearBoth" />
<?php
}
$radio_buttons++;
?>
<br class="clearBoth" />
<?php
}
?>
<?php
if (MODULE_ORDER_TOTAL_INSTALLED) {
$order_totals = $order_total_modules->process();
?>
<?php $order_total_modules->output(); ?>
<?php
}
?>
当$order_total_modules的output方法传入参数$return_html=true是,会使用模板文件tpl_modules_order_totals.php,否则使用直接构造方式输出HTML代码。