⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ot_coupon.php

📁 美国cre loaded 6.2 b2b网站系统升级补丁
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                    =================================                    Submitted by Rob Cote, robc@traininghott.com                    original code:                                        $od_amount = round($amount*10)/10*$c_deduct/100;                    $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];                    $pod_amount = round($pr_c*10)/10*$c_deduct/100;                    */                     //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];                                        $pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!                    $pod_amount = round($pr_c*10)/10*$c_deduct/100;                     $od_amount = $od_amount + $pod_amount;                  } else {                    $od_amount = $c_deduct;                  }                }              }            } else {              $cat_ids = split("[,]", $get_result['restrict_to_categories']);              for ($i=0; $i < sizeof($order->products); $i++) {                $my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id']));                $sub_cat_ids = split("[_]", $my_path);                for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {                  for ($ii = 0; $ii < count($cat_ids); $ii++) {                    if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {                      if ($get_result['coupon_type'] == 'P') {                                                                        $pr_c = $this->product_price(tep_get_prid($order->products[$i]['id'])); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!                        $pod_amount = round($pr_c*10)/10*$c_deduct/100;                        $od_amount = $od_amount + $pod_amount;                        continue 3;      // v5.13a Tanaka 2005-4-30: to prevent double counting of a product discount                      } else {                        $od_amount = $c_deduct;                        continue 3;      // Tanaka 2005-4-30: to prevent double counting of a product discount                      }                    }                  }                }              }            } //endif $get_result['restrict_to_products']                } //end for sizeof($order->products)        } else {          if ($get_result['coupon_type'] !='P') {            $od_amount = $c_deduct;          } else {            $od_amount = $amount * $get_result['coupon_amount'] / 100;          }        }       }    }    if ($od_amount>$amount) $od_amount = $amount;  }  return $od_amount;}function calculate_tax_deduction($amount, $od_amount, $method) {global $customer_id, $order, $cc_id, $cart;//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.  $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");  if (tep_db_num_rows($coupon_query) !=0 ) {    $coupon_result = tep_db_fetch_array($coupon_query);    $coupon_get = tep_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 = tep_db_fetch_array($coupon_get);    if ($get_result['coupon_type'] != 'S') {      //RESTRICTION--------------------------------      if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {        // What to do here.        // Loop through all products and build a list of all product_ids, price, tax class        // at the same time create total net amount.        // then        // for percentage discounts. simply reduce tax group per product by discount percentage        // or        // for fixed payment amount        // calculate ratio based on total net        // for each product reduce tax group per product by ratio amount.        $products = $cart->get_products();        $valid_product = false;        for ($i=0; $i < sizeof($products); $i++) {        $valid_product = false;          $t_prid = tep_get_prid($products[$i]['id']);          $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");          $cc_result = tep_db_fetch_array($cc_query);          if ($get_result['restrict_to_products']) {            $pr_ids = split("[,]", $get_result['restrict_to_products']);            for ($p = 0; $p < sizeof($pr_ids); $p++) {              if ($pr_ids[$p] == $t_prid) $valid_product = true;            }          }          if ($get_result['restrict_to_categories']) {                        // Tanaka 2005-4-30:  Original Code                        /*$cat_ids = split("[,]", $get_result['restrict_to_categories']);                        for ($c = 0; $c < sizeof($cat_ids); $c++) {                            // Tanaka 2005-4-30:  changed $products_id to $t_prid and changed $i to $c                            $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $t_prid . "' and categories_id = '" . $cat_ids[$c] . "'");                            if (tep_db_num_rows($cat_query) !=0 ) $valid_product = true;                        }*/                        // v5.13a Tanaka 2005-4-30:  New code, this correctly identifies valid products in subcategories                        $cat_ids = split("[,]", $get_result['restrict_to_categories']);                        $my_path = tep_get_product_path($t_prid);                        $sub_cat_ids = split("[_]", $my_path);                        for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {                            for ($ii = 0; $ii < count($cat_ids); $ii++) {                                if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {                                    $valid_product = true;                                    continue 2;                                }                            }                        }          }          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 = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);            $tax_desc = tep_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 = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);              $tax_desc = tep_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 = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);            $tax_desc = tep_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 = tep_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 = tep_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_amount=0;            $tax_rate = tep_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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -