📄 ot_coupon.php
字号:
}
}
if ($valid_product) {
$price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; //Fred - added
$price_incl_vat = $this->product_price($t_prid); //Fred - added
$valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']);
// $total_price += $price_incl_vat; //Fred - changed
$total_price += $price_excl_vat; // changed
}
}
if (sizeof($valid_array) > 0) { // if ($valid_product) {
if ($get_result['coupon_type'] == 'P') {
$ratio = $get_result['coupon_amount']/100;
} else {
$ratio = $od_amount / $total_price;
}
if ($get_result['coupon_type'] == 'S') $ratio = 1;
if ($method=='Credit Note') {
$tax_rate = twe_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
$tax_desc = twe_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
if ($get_result['coupon_type'] == 'P') {
$tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
} else {
$tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
}
$order->info['tax_groups'][$tax_desc] -= $tod_amount;
$order->info['total'] -= $tod_amount; // need to modify total ...OLD
$order->info['tax'] -= $tod_amount; //Fred - added
} else {
for ($p=0; $p<sizeof($valid_array); $p++) {
$tax_rate = twe_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
$tax_desc = twe_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
if ($tax_rate > 0) {
//Fred $tod_amount[$tax_desc] += ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; //OLD
$tod_amount = ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // calc total tax Fred - added
$order->info['tax_groups'][$tax_desc] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio;
$order->info['total'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust total
$order->info['tax'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust tax -- Fred - added
}
}
}
}
//NO RESTRICTION--------------------------------
} else {
if ($get_result['coupon_type'] =='F') {
$tod_amount = 0;
if ($method=='Credit Note') {
$tax_rate = twe_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
$tax_desc = twe_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
$tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
$order->info['tax_groups'][$tax_desc] -= $tod_amount;
} else {
// $ratio1 = $od_amount/$amount; // this produces the wrong ratipo on fixed amounts
reset($order->info['tax_groups']);
while (list($key, $value) = each($order->info['tax_groups'])) {
$ratio1 = $od_amount/($amount-$order->info['tax_groups'][$key]); ////debug
$tax_rate = twe_get_tax_rate_from_desc($key);
$net = $tax_rate * $order->info['tax_groups'][$key];
if ($net>0) {
$god_amount = $order->info['tax_groups'][$key] * $ratio1;
$tod_amount += $god_amount;
$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
}
}
}
$order->info['total'] -= $tod_amount; //OLD
$order->info['tax'] -= $tod_amount; //Fred - added
}
if ($get_result['coupon_type'] =='P') {
$tod_amount=0;
if ($method=='Credit Note') {
$tax_desc = twe_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
$tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
$order->info['tax_groups'][$tax_desc] -= $tod_amount;
} else {
reset($order->info['tax_groups']);
while (list($key, $value) = each($order->info['tax_groups'])) {
$god_amout=0;
$tax_rate = twe_get_tax_rate_from_desc($key);
$net = $tax_rate * $order->info['tax_groups'][$key];
if ($net>0) {
$god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount']/100;
$tod_amount += $god_amount;
$order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
}
}
}
$order->info['total'] -= $tod_amount; // have to modify total also
$order->info['tax'] -= $tod_amount;
}
}
}
}
return $tod_amount;
}
function update_credit_account($i) {
return false;
}
function apply_credit() {
global $insert_id, $REMOTE_ADDR;
if ($this->deduction !=0) {
twe_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id) values ('" . $_SESSION['cc_id'] . "', now(), '" . $REMOTE_ADDR . "', '" . $_SESSION['customer_id'] . "', '" . $insert_id . "')");
}
unset($_SESSION['cc_id']);
}
function get_order_total() {
global $order;
$order_total = $order->info['total'];
// Check if gift voucher is in cart and adjust total
$products = $_SESSION['cart']->get_products();
for ($i=0; $i<sizeof($products); $i++) {
$t_prid = twe_get_prid($products[$i]['id']);
$gv_query = twe_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
$gv_result = twe_db_fetch_array($gv_query);
if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
$qty = $_SESSION['cart']->get_quantity($t_prid);
$products_tax = twe_get_tax_rate($gv_result['products_tax_class_id']);
if ($this->include_tax =='false') {
$gv_amount = $gv_result['products_price'] * $qty;
} else {
$gv_amount = ($gv_result['products_price'] + twe_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
}
$order_total=$order_total - $gv_amount;
}
}
if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
// OK thats fine for global coupons but what about restricted coupons
// where you can only redeem against certain products/categories.
// and I though this was going to be easy !!!
$coupon_query=twe_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id='".$_SESSION['cc_id']."'");
if (twe_db_num_rows($coupon_query) !=0) {
$coupon_result=twe_db_fetch_array($coupon_query);
$coupon_get=twe_db_query("select coupon_amount, coupon_minimum_order,restrict_to_products,restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code='".$coupon_result['coupon_code']."'");
$get_result=twe_db_fetch_array($coupon_get);
$in_cat = true;
if ($get_result['restrict_to_categories']) {
$cat_ids = split("[,]", $get_result['restrict_to_categories']);
$in_cat=false;
for ($i = 0; $i < count($cat_ids); $i++) {
if (is_array($this->contents)) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$cat_query = twe_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");
if (twe_db_num_rows($cat_query) !=0 ) {
$in_cat = true;
$total_price += $this->get_product_price($products_id);
}
}
}
}
}
$in_cart = true;
if ($get_result['restrict_to_products']) {
$pr_ids = split("[,]", $get_result['restrict_to_products']);
$in_cart=false;
$products_array = $_SESSION['cart']->get_products();
for ($i = 0; $i < sizeof($pr_ids); $i++) {
for ($ii = 1; $ii<=sizeof($products_array); $ii++) {
if (twe_get_prid($products_array[$ii-1]['id']) == $pr_ids[$i]) {
$in_cart=true;
$total_price += $this->get_product_price($products_array[$ii-1]['id']);
}
}
}
$order_total = $total_price;
}
}
return $order_total;
}
function get_product_price($product_id) {
global $order;
$products_id = twe_get_prid($product_id);
// products price
$qty = $_SESSION['cart']->contents[$product_id]['qty'];
$product_query = twe_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
if ($product = twe_db_fetch_array($product_query)) {
$prid = $product['products_id'];
$products_tax = twe_get_tax_rate($product['products_tax_class_id']);
$products_price = $product['products_price'];
$specials_query = twe_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
if (twe_db_num_rows ($specials_query)) {
$specials = twe_db_fetch_array($specials_query);
$products_price = $specials['specials_new_products_price'];
}
if ($this->include_tax == 'true') {
$total_price += ($products_price + twe_calculate_tax($products_price, $products_tax)) * $qty;
// echo("total price = " . $total_price . " products_price = " . $products_price . " products_tax = " . $products_tax . "<br>");
} else {
$total_price += $products_price * $qty;
}
// attributes price
if (isset($_SESSION['cart']->contents[$product_id]['attributes'])) {
reset($_SESSION['cart']->contents[$product_id]['attributes']);
while (list($option, $value) = each($_SESSION['cart']->contents[$product_id]['attributes'])) {
$attribute_price_query = twe_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
$attribute_price = twe_db_fetch_array($attribute_price_query);
if ($attribute_price['price_prefix'] == '+') {
if ($this->include_tax == 'true') {
$total_price += $qty * ($attribute_price['options_values_price'] + twe_calculate_tax($attribute_price['options_values_price'], $products_tax));
} else {
$total_price += $qty * ($attribute_price['options_values_price']);
}
} else {
if ($this->include_tax == 'true') {
$total_price -= $qty * ($attribute_price['options_values_price'] + twe_calculate_tax($attribute_price['options_values_price'], $products_tax));
} else {
$total_price -= $qty * ($attribute_price['options_values_price']);
}
}
}
}
}
if ($this->include_shipping == 'true') {
$total_price += $order->info['shipping_cost'];
}
return $total_price;
}
//Added by Fred -- BOF -----------------------------------------------------
//JUST RETURN THE PRODUCT PRICE (INCL ATTRIBUTE PRICES) WITH OR WITHOUT TAX
function product_price($product_id) {
$total_price = $this->get_product_price($product_id);
if ($this->include_shipping == 'true') $total_price -= $order->info['shipping_cost'];
return $total_price;
}
//Added by Fred -- EOF -----------------------------------------------------
function check() {
if (!isset($this->check)) {
$check_query = twe_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
$this->check = twe_db_num_rows($check_query);
}
return $this->check;
}
function keys() {
return array('MODULE_ORDER_TOTAL_COUPON_STATUS', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS');
}
function install() {
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', '6', '1','twe_cfg_select_option(array(\'true\', \'false\'), ', now())");
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '70', '6', '2', now())");
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function ,date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', '6', '5', 'twe_cfg_select_option(array(\'true\', \'false\'), ', now())");
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function ,date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', '6', '6','twe_cfg_select_option(array(\'true\', \'false\'), ', now())");
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function ,date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', '6', '7','twe_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
twe_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', '6', '0', 'twe_get_tax_class_title', 'twe_cfg_pull_down_tax_classes(', now())");
}
function remove() {
$keys = '';
$keys_array = $this->keys();
for ($i=0; $i<sizeof($keys_array); $i++) {
$keys .= "'" . $keys_array[$i] . "',";
}
$keys = substr($keys, 0, -1);
twe_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -