ot_gv.php
来自「Zen Cart是真正的电子商务艺术」· PHP 代码 · 共 381 行 · 第 1/2 页
PHP
381 行
*/
function apply_credit() {
global $db, $order, $messageStack;
// check for valid redemption amount vs available credit for current customer
if ($_SESSION['cot_gv'] != 0) {
$gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
// obtain final "deduction" amount
$gv_payment_amount = $this->deduction;
// determine amount of GV to redeem based on available balance minus qualified/calculated deduction suitable to this order
$gv_amount = $gv_result->fields['amount'] - $gv_payment_amount;
// reduce customer's GV balance by the amount redeemed
$db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
}
// clear GV redemption flag since it's already been claimed and deducted
$_SESSION['cot_gv'] = false;
// send back the amount of GV used for payment on this order
return $gv_payment_amount;
}
/**
* Check to see if redemption code has been entered and redeem if valid
*/
function collect_posts() {
global $db, $currencies, $messageStack;
// if we have no GV amount selected, set it to 0
if (!$_POST['cot_gv']) $_SESSION['cot_gv'] = '0.00';
// if we have a GV redemption code submitted, process it
if ($_POST['gv_redeem_code']) {
// check for validity
$gv_result = $db->Execute("select coupon_id, coupon_type, coupon_amount from " . TABLE_COUPONS . " where coupon_code = '" . zen_db_prepare_input($_POST['gv_redeem_code']) . "'");
if ($gv_result->RecordCount() > 0) {
$redeem_query = $db->Execute("select * from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . (int)$gv_result->fields['coupon_id'] . "'");
// if already redeemed, throw error
if ( ($redeem_query->RecordCount() > 0) && ($gv_result->fields['coupon_type'] == 'G') ) {
$messageStack->add_session('checkout_payment', ERROR_NO_INVALID_REDEEM_GV, error);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
} else {
// if not valid redemption code, throw error
$messageStack->add_session('checkout_payment', ERROR_NO_INVALID_REDEEM_GV, error);
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
// if valid, add redeemed amount to customer's GV balance and mark as redeemed
if ($gv_result->fields['coupon_type'] == 'G') {
$gv_amount = $gv_result->fields['coupon_amount'];
// Things to set
// ip address of claimant
// customer id of claimant
// date
// redemption flag
// now update customer account with gv_amount
$gv_amount_result=$db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
$customer_gv = false;
$total_gv_amount = $gv_amount;;
if ($gv_amount_result->RecordCount() > 0) {
$total_gv_amount = $gv_amount_result->fields['amount'] + $gv_amount;
$customer_gv = true;
}
$db->Execute("update " . TABLE_COUPONS . " set coupon_active = 'N' where coupon_id = '" . $gv_result->fields['coupon_id'] . "'");
$db->Execute("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, customer_id, redeem_date, redeem_ip) values ('" . $gv_result->fields['coupon_id'] . "', '" . (int)$_SESSION['customer_id'] . "', now(),'" . $_SERVER['REMOTE_ADDR'] . "')");
if ($customer_gv) {
// already has gv_amount so update
$db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $total_gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
} else {
// no gv_amount so insert
$db->Execute("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . (int)$_SESSION['customer_id'] . "', '" . $total_gv_amount . "')");
}
// zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_REDEEMED_AMOUNT. $currencies->format($gv_amount)), 'SSL'));
$messageStack->add_session('redemptions',ERROR_REDEEMED_AMOUNT. $currencies->format($gv_amount), 'success' );
}
}
if ($_POST['submit_redeem_x'] && $gv_result->fields['coupon_type'] == 'G') zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));
}
/**
* Calculate GV claim amount (GV amounts are always based on the STORE's default currency value)
*/
function calculate_credit($save_total_cost) {
global $db, $order, $currencies;
// calculate value based on default currency
$gv_payment_amount = $currencies->value($_SESSION['cot_gv'], true, DEFAULT_CURRENCY);
$full_cost = $save_total_cost - $gv_payment_amount;
if ($full_cost < 0) {
$full_cost = 0;
$gv_payment_amount = $save_total_cost;
}
return zen_round($gv_payment_amount,2);
}
function calculate_deductions($order_total) {
global $db, $order, $messageStack;
$od_amount = array();
$deduction = $this->calculate_credit($this->get_order_total());
$od_amount['total'] = $deduction;
switch ($this->calculate_tax) {
case 'None':
$remainder = $order->info['total'] - $od_amount['total'];
$tax_deduct = $order->info['tax'] - $remainder;
// division by 0
if ($order->info['tax'] <= 0) {
$ratio_tax = 0;
} else {
$ratio_tax = $tax_deduct/$order->info['tax'];
}
$tax_deduct = 0;
if ($this->include_tax) {
reset($order->info['tax_groups']);
foreach ($order->info['tax_groups'] as $key=>$value) {
$od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio_tax;
$tax_deduct += $od_amount['tax_groups'][$key];
}
}
$od_amount['tax'] = $tax_deduct;
break;
case 'Standard':
if ($od_amount['total'] >= $order_total) {
$ratio = 1;
} else {
$ratio = ($od_amount['total'] / ($order_total - $order->info['tax']));
}
reset($order->info['tax_groups']);
$tax_deduct = 0;
foreach ($order->info['tax_groups'] as $key=>$value) {
$od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
$tax_deduct += $od_amount['tax_groups'][$key];
}
$od_amount['tax'] = $tax_deduct;
break;
case 'Credit Note':
$od_amount['total'] = $deduction;
$tax_rate = zen_get_tax_rate($this->tax_class);
$od_amount['tax'] = zen_calculate_tax($deduction, $tax_rate);
$tax_description = zen_get_tax_description($this->tax_class);
$od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
break;
default:
}
return $od_amount;
}
/**
* Check to see whether current customer has a GV balance available
* Returns amount of GV balance on account
*/
function user_has_gv_account($c_id) {
global $db;
$gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'");
if ($gv_result->RecordCount() > 0) {
return $gv_result->fields['amount'];
}
return 0; // use 0 because 'false' was preventing checkout_payment from continuing
}
/**
* Recalculates base order-total amount for use in deduction calculations
*/
function get_order_total() {
global $order;
$order_total = $order->info['total'];
// if we are not supposed to include tax in credit calculations, subtract it out
if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
// if we are not supposed to include shipping amount in credit calcs, subtract it out
if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
$order_total = $order->info['total'];
return $order_total;
}
/**
* Enter description here...
*
* @return unknown
*/
function check() {
global $db;
if (!isset($this->check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_GV_STATUS'");
$this->check = $check_query->RecordCount();
}
return $this->check;
}
/**
* Enter description here...
*
* @return unknown
*/
function keys() {
return array('MODULE_ORDER_TOTAL_GV_STATUS', 'MODULE_ORDER_TOTAL_GV_SORT_ORDER', 'MODULE_ORDER_TOTAL_GV_QUEUE', 'MODULE_ORDER_TOTAL_GV_INC_SHIPPING', 'MODULE_ORDER_TOTAL_GV_INC_TAX', 'MODULE_ORDER_TOTAL_GV_CALC_TAX', 'MODULE_ORDER_TOTAL_GV_TAX_CLASS', 'MODULE_ORDER_TOTAL_GV_CREDIT_TAX', 'MODULE_ORDER_TOTAL_GV_ORDER_STATUS_ID');
}
/**
* Enter description here...
*
*/
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('璇ユā鍧楀凡瀹夎
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?