ot_coupon.php
来自「Zen Cart是真正的电子商务艺术」· PHP 代码 · 共 440 行 · 第 1/2 页
PHP
440 行
<?php
/**
* ot_coupon order-total module
*
* @package orderTotal
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: ot_coupon.php 7203 2007-10-07 12:29:53Z drbyte $
*/
/**
* Order Total class to handle discount coupons
*
*/
class ot_coupon {
/**
* coupon title
*
* @var unknown_type
*/
var $title;
/**
* Output used on checkout pages
*
* @var unknown_type
*/
var $output;
/**
* Enter description here...
*
* @return ot_coupon
*/
function ot_coupon() {
$this->code = 'ot_coupon';
$this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;
$this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;
$this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;
$this->user_prompt = '';
$this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;
$this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;
$this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;
$this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;
$this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;
$this->credit_class = true;
$this->output = array();
if (IS_ADMIN_FLAG === true) {
if ($this->include_tax == 'true' && $this->calculate_tax != "None") {
$this->title .= '<span class="alert">' . MODULE_ORDER_TOTAL_COUPON_INCLUDE_ERROR . '</span>';
}
}
}
/**
* Method used to produce final figures for dedcutions. This information is used to produce the output<br>
* shown on the checkout pages
*
*/
function process() {
global $order, $currencies, $db;
$order_total = $this->get_order_total();
$od_amount = $this->calculate_deductions($order_total['total']);
$this->deduction = $od_amount['total'];
if ($od_amount['total'] > 0) {
reset($order->info['tax_groups']);
$tax = 0;
while (list($key, $value) = each($order->info['tax_groups'])) {
if ($od_amount['tax_groups'][$key]) {
$order->info['tax_groups'][$key] -= $od_amount['tax_groups'][$key];
$tax += $od_amount['tax_groups'][$key];
}
}
if ($od_amount['type'] == 'S') $order->info['shipping_cost'] = 0;
$order->info['total'] = $order->info['total'] - $od_amount['total'];
if (DISPLAY_PRICE_WITH_TAX == 'true') {
$od_amount['total'] += $tax;
}
if ($this->calculate_tax == "Standard") $order->info['total'] -= $tax;
if ($order->info['total'] < 0) $order->info['total'] = 0;
$order->info['tax'] = $order->info['tax'] - $tax;
$this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ' :',
'text' => '-' . $currencies->format($od_amount['total']),
'value' => $od_amount['total']);
}
}
/**
* Enter description here...
*
* @return unknown
*/
function selection_test() {
return false;
}
/**
* Enter description here...
*
*/
function clear_posts() {
unset($_POST['dc_redeem_code']);
unset($_SESSION['cc_id']);
}
/**
* Enter description here...
*
* @param unknown_type $order_total
* @return unknown
*/
function pre_confirmation_check($order_total) {
global $order;
$od_amount = $this->calculate_deductions($order_total);
return $od_amount['total'] + $od_amount['tax'];
}
/**
* Enter description here...
*
* @return unknown
*/
function use_credit_amount() {
return false;
}
/**
* Enter description here...
*
* @return unknown
*/
function credit_selection() {
global $discount_coupon;
global $db;
// note the placement of the redeem code can be moved within the array on the instructions or the title
$selection = array('id' => $this->code,
'module' => $this->title,
'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : ''),
'fields' => array(array('title' => ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_TEXT_CURRENT_CODE . '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $_SESSION['cc_id']) . '\')">' . $discount_coupon->fields['coupon_code'] . '</a><br />' : '') . MODULE_ORDER_TOTAL_COUPON_TEXT_ENTER_CODE,
'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
'tag' => 'disc-'.$this->code
)));
return $selection;
}
/**
* Enter description here...
*
*/
function collect_posts() {
global $db, $currencies, $messageStack, $order;
global $discount_coupon;
// remove discount coupon by request
if (isset($_POST['dc_redeem_code']) && strtoupper($_POST['dc_redeem_code']) == 'REMOVE') {
unset($_POST['dc_redeem_code']);
unset($_SESSION['cc_id']);
$messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON, 'caution');
}
// bof: Discount Coupon zoned always validate coupon for payment address changes
if ($_SESSION['cc_id'] > 0) {
$sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
restrict_to_products, restrict_to_categories, coupon_zone_restriction, coupon_code
from " . TABLE_COUPONS . "
where coupon_id= :couponIDEntered
and coupon_active='Y'";
$sql = $db->bindVars($sql, ':couponIDEntered', $_SESSION['cc_id'], 'string');
$coupon_result=$db->Execute($sql);
$foundvalid = true;
$check_flag = false;
$check = $db->Execute("select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . $coupon_result->fields['coupon_zone_restriction'] . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
if ($coupon_result->fields['coupon_zone_restriction'] > 0) {
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
$foundvalid = $check_flag;
}
// remove if fails address validation
if (!$foundvalid) {
$messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON_ZONE, 'caution');
$this->clear_posts();
if (!$foundvalid) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
}
}
// eof: Discount Coupon zoned always validate coupon for payment address changes
if ((isset($_POST['dc_redeem_code']) && $_POST['dc_redeem_code'] != '') || (isset($discount_coupon->fields['coupon_code']) && $discount_coupon->fields['coupon_code'] != '')) {
// set current Discount Coupon based on current or existing
if (isset($_POST['dc_redeem_code']) && $discount_coupon->fields['coupon_code'] == '') {
$dc_check = $_POST['dc_redeem_code'];
} else {
$dc_check = $discount_coupon->fields['coupon_code'];
}
$sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
restrict_to_products, restrict_to_categories, coupon_zone_restriction
from " . TABLE_COUPONS . "
where coupon_code= :couponCodeEntered
and coupon_active='Y'";
$sql = $db->bindVars($sql, ':couponCodeEntered', $dc_check, 'string');
$coupon_result=$db->Execute($sql);
if ($coupon_result->fields['coupon_type'] != 'G') {
if ($coupon_result->RecordCount() < 1 ) {
$messageStack->add_session('redemptions', TEXT_INVALID_REDEEM_COUPON,'caution');
$this->clear_posts();
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
}
$order_total = $this->get_order_total();
if ($order_total['totalFull'] < $coupon_result->fields['coupon_minimum_order']) {
$messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon_result->fields['coupon_minimum_order'])),'caution');
$this->clear_posts();
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
}
// JTD - added missing code here to handle coupon product restrictions
// look through the items in the cart to see if this coupon is valid for any item in the cart
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?