[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 ot_coupon.php

Zen Cart 源代码 ot_coupon.php




下载文件

文件名: ot_coupon.php
文件类型: PHP文件
文件大小: 25.01 KiB
MD5: e36fb227f9004478ce0f4bf87d33a017

ot_coupon.php - 关闭高亮
  1. <?php
  2. /**
  3.  * ot_coupon order-total module
  4.  *
  5.  * @package orderTotal
  6.  * @copyright Copyright 2003-2010 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version $Id: ot_coupon.php 16819 2010-06-30 22:39:54Z wilt $
  10.  */
  11. /**
  12.  * Order Total class  to handle discount coupons
  13.  *
  14.  */
  15. class ot_coupon {
  16.   /**
  17.    * coupon title
  18.    *
  19.    * @var unknown_type
  20.    */
  21.   var $title;
  22.   /**
  23.    * Output used on checkout pages
  24.    *
  25.    * @var unknown_type
  26.    */
  27.   var $output;
  28.   /**
  29.    * Enter description here...
  30.    *
  31.    * @return ot_coupon
  32.    */
  33.   function ot_coupon() {
  34.     $this->code = 'ot_coupon';
  35.     $this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;
  36.     $this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;
  37.     $this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;
  38.     $this->user_prompt = '';
  39.     $this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;
  40.     $this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;
  41.     $this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;
  42.     $this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;
  43.     $this->tax_class  = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;
  44.     $this->credit_class = true;
  45.     $this->output = array();
  46.     if (IS_ADMIN_FLAG === true) {
  47.       if ($this->include_tax == 'true' && $this->calculate_tax != "None") {
  48.         $this->title .= '<span class="alert">' . MODULE_ORDER_TOTAL_COUPON_INCLUDE_ERROR . '</span>';
  49.       }
  50.     }
  51.   }
  52.   /**
  53.    * Method used to produce final figures for deductions. This information is used to produce the output<br>
  54.    * shown on the checkout pages
  55.    *
  56.    */
  57.   function process() {
  58.     global $order, $currencies;
  59.     $order_total = $this->get_order_total();
  60.     $od_amount = $this->calculate_deductions($order_total['total']);
  61.     $this->deduction = $od_amount['total'];
  62.     if ($od_amount['total'] > 0) {
  63.       reset($order->info['tax_groups']);
  64.       $tax = 0;
  65.       while (list($key, $value) = each($order->info['tax_groups'])) {
  66.         if ($od_amount['tax_groups'][$key]) {
  67.           $order->info['tax_groups'][$key] -= $od_amount['tax_groups'][$key];
  68.           $tax += $od_amount['tax_groups'][$key];
  69.         }
  70.       }
  71.       if ($od_amount['type'] == 'S') $order->info['shipping_cost'] = 0;
  72.       $order->info['total'] = $order->info['total'] - $od_amount['total'];
  73.       if (DISPLAY_PRICE_WITH_TAX != 'true') {
  74.         $order->info['total'] -= $tax;
  75.       }
  76.       $order->info['tax'] = $order->info['tax'] - $tax;
  77.       //      if ($this->calculate_tax == "Standard") $order->info['total'] -= $tax;
  78.       if ($order->info['total'] < 0) $order->info['total'] = 0;
  79.       $this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ' :',
  80.                               'text' => '-' . $currencies->format($od_amount['total']),
  81.                               'value' => $od_amount['total']);
  82.     }
  83.   }
  84.   /**
  85.    * Enter description here...
  86.    *
  87.    * @return unknown
  88.    */
  89.   function selection_test() {
  90.     return false;
  91.   }
  92.   /**
  93.    * Enter description here...
  94.    *
  95.    */
  96.   function clear_posts() {
  97.     unset($_POST['dc_redeem_code']);
  98.     unset($_SESSION['cc_id']);
  99.   }
  100.   /**
  101.    * Enter description here...
  102.    *
  103.    * @param unknown_type $order_total
  104.    * @return unknown
  105.    */
  106.   function pre_confirmation_check($order_total) {
  107.     global $order;
  108.     $od_amount = $this->calculate_deductions($order_total);
  109. //    print_r($od_amount);
  110.     $order->info['total'] = $order->info['total'] - $od_amount['total'];
  111.     if (DISPLAY_PRICE_WITH_TAX != 'true') {
  112.       $order->info['total'] -= $tax;
  113.     }
  114.     return $od_amount['total'] + (DISPLAY_PRICE_WITH_TAX == 'true' ? 0 : $od_amount['tax']);
  115.   }
  116.   /**
  117.    * Enter description here...
  118.    *
  119.    * @return unknown
  120.    */
  121.   function use_credit_amount() {
  122.     return false;
  123.   }
  124.   /**
  125.    * Enter description here...
  126.    *
  127.    * @return unknown
  128.    */
  129.   function credit_selection() {
  130.     global $discount_coupon;
  131.     // note the placement of the redeem code can be moved within the array on the instructions or the title
  132.     $selection = array('id' => $this->code,
  133.                        'module' => $this->title,
  134.                        'redeem_instructions' => MODULE_ORDER_TOTAL_COUPON_REDEEM_INSTRUCTIONS . ($discount_coupon->fields['coupon_code'] != '' ? MODULE_ORDER_TOTAL_COUPON_REMOVE_INSTRUCTIONS : ''),
  135.                        '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,
  136.                                                'field' => zen_draw_input_field('dc_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
  137.                                                'tag' => 'disc-'.$this->code
  138.                        )));
  139.     return $selection;
  140.   }
  141.   /**
  142.    * Enter description here...
  143.    *
  144.    */
  145.   function collect_posts() {
  146.     global $db, $currencies, $messageStack, $order;
  147.     global $discount_coupon;
  148.     // remove discount coupon by request
  149.     if (isset($_POST['dc_redeem_code']) && strtoupper($_POST['dc_redeem_code']) == 'REMOVE') {
  150.       unset($_POST['dc_redeem_code']);
  151.       unset($_SESSION['cc_id']);
  152.       $messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON, 'caution');
  153.     }
  154. //    print_r($_SESSION);
  155.     // bof: Discount Coupon zoned always validate coupon for payment address changes
  156.     // eof: Discount Coupon zoned always validate coupon for payment address changes
  157.     if ((isset($_POST['dc_redeem_code']) && $_POST['dc_redeem_code'] != '') || (isset($discount_coupon->fields['coupon_code']) && $discount_coupon->fields['coupon_code'] != '')) {
  158.       // set current Discount Coupon based on current or existing
  159.       if (isset($_POST['dc_redeem_code']) && $discount_coupon->fields['coupon_code'] == '') {
  160.         $dc_check = $_POST['dc_redeem_code'];
  161.       } else {
  162.         $dc_check = $discount_coupon->fields['coupon_code'];
  163.       }
  164.       $sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
  165.              restrict_to_products, restrict_to_categories, coupon_zone_restriction
  166.              from " . TABLE_COUPONS . "
  167.              where coupon_code= :couponCodeEntered
  168.              and coupon_active='Y'";
  169.       $sql = $db->bindVars($sql, ':couponCodeEntered', $dc_check, 'string');
  170.  
  171.       $coupon_result=$db->Execute($sql);
  172.  
  173.       if ($coupon_result->fields['coupon_type'] != 'G') {
  174.  
  175.         if ($coupon_result->RecordCount() < 1 ) {
  176.           $messageStack->add_session('redemptions', TEXT_INVALID_REDEEM_COUPON,'caution');
  177.           $this->clear_posts();
  178.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
  179.         }
  180.         $order_total = $this->get_order_total();
  181.  
  182. // left for total order amount vs qualified order amount just switch the commented lines
  183. //        if ($order_total['totalFull'] < $coupon_result->fields['coupon_minimum_order']) {
  184.         if (strval($order_total['total']) < $coupon_result->fields['coupon_minimum_order']) {
  185.  
  186.           $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon_result->fields['coupon_minimum_order'])),'caution');
  187.           $this->clear_posts();
  188.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
  189.         }
  190.  
  191.         // JTD - added missing code here to handle coupon product restrictions
  192.         // look through the items in the cart to see if this coupon is valid for any item in the cart
  193.         $products = $_SESSION['cart']->get_products();
  194.         $foundvalid = true;
  195.  
  196.         if ($foundvalid == true) {
  197.           $foundvalid = false;
  198.           for ($i=0; $i<sizeof($products); $i++) {
  199.             if (is_product_valid($products[$i]['id'], $coupon_result->fields['coupon_id'])) {
  200.               $foundvalid = true;
  201.               continue;
  202.             }
  203.           }
  204.         }
  205.  
  206.         if (!$foundvalid) {
  207.           $this->clear_posts();
  208.         }
  209.  
  210.         if (!$foundvalid) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'credit_class_error_code=' . $this->code . '&credit_class_error=' . urlencode(TEXT_INVALID_COUPON_PRODUCT . ' ' . $dc_check), 'SSL',true, false));
  211.         // JTD - end of additions of missing code to handle coupon product restrictions
  212.  
  213.         $date_query=$db->Execute("select coupon_start_date from " . TABLE_COUPONS . "
  214.                                  where coupon_start_date <= now() and
  215.                                  coupon_code='" . zen_db_prepare_input($dc_check) . "'");
  216.  
  217.         if ($date_query->RecordCount() < 1 ) {
  218.           $messageStack->add_session('redemptions', TEXT_INVALID_STARTDATE_COUPON,'caution');
  219.           $this->clear_posts();
  220.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
  221.         }
  222.  
  223.         $date_query=$db->Execute("select coupon_expire_date from " . TABLE_COUPONS . "
  224.                                  where coupon_expire_date >= now() and
  225.                                  coupon_code='" . zen_db_prepare_input($dc_check) . "'");
  226.  
  227.         if ($date_query->RecordCount() < 1 ) {
  228.           $messageStack->add_session('redemptions', TEXT_INVALID_FINISHDATE_COUPON,'caution');
  229.           $this->clear_posts();
  230.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
  231.         }
  232.  
  233.         $coupon_count = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "
  234.                                      where coupon_id = '" . (int)$coupon_result->fields['coupon_id']."'");
  235.  
  236.         $coupon_count_customer = $db->Execute("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . "
  237.                                               where coupon_id = '" . $coupon_result->fields['coupon_id']."' and
  238.                                               customer_id = '" . (int)$_SESSION['customer_id'] . "'");
  239.  
  240.         if ($coupon_count->RecordCount() >= $coupon_result->fields['uses_per_coupon'] && $coupon_result->fields['uses_per_coupon'] > 0) {
  241.           $messageStack->add_session('redemptions', TEXT_INVALID_USES_COUPON . $coupon_result->fields['uses_per_coupon'] . TIMES ,'caution');
  242.           $this->clear_posts();
  243.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
  244.         }
  245.  
  246.         if ($coupon_count_customer->RecordCount() >= $coupon_result->fields['uses_per_user'] && $coupon_result->fields['uses_per_user'] > 0) {
  247.           $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_USES_USER_COUPON, $dc_check) . $coupon_result->fields['uses_per_user'] . ($coupon_result->fields['uses_per_user'] == 1 ? TIME : TIMES) ,'caution');
  248.           $this->clear_posts();
  249.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
  250.         }
  251.  
  252.         $_SESSION['cc_id'] = $coupon_result->fields['coupon_id'];
  253.         if ($_SESSION['cc_id'] > 0) {
  254.           $sql = "select coupon_id, coupon_amount, coupon_type, coupon_minimum_order, uses_per_coupon, uses_per_user,
  255.                  restrict_to_products, restrict_to_categories, coupon_zone_restriction, coupon_code
  256.                  from " . TABLE_COUPONS . "
  257.                  where coupon_id= :couponIDEntered
  258.                  and coupon_active='Y'";
  259.           $sql = $db->bindVars($sql, ':couponIDEntered', $_SESSION['cc_id'], 'string');
  260.  
  261.           $coupon_result=$db->Execute($sql);
  262.  
  263.           $foundvalid = true;
  264.  
  265.           $check_flag = false;
  266.  
  267.           // base restrictions zone restrictions for Delivery or Billing address
  268.           switch($coupon_result->fields['coupon_type']) {
  269.             case 'S': // shipping
  270.               // use delivery address
  271.               $check_zone_country_id = $order->delivery['country']['id'];
  272.               break;
  273.             case 'F': // amount
  274.               // use billing address
  275.               $check_zone_country_id = $order->billing['country']['id'];
  276.               break;
  277.             case 'P': // percentage
  278.               // use billing address
  279.               $check_zone_country_id = $order->billing['country']['id'];
  280.               break;
  281.             default:
  282.               // use billing address
  283.               $check_zone_country_id = $order->billing['country']['id'];
  284.               break;
  285.           }
  286.  
  287. //          $sql = "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";
  288.           $sql = "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 = '" . $check_zone_country_id . "' order by zone_id";
  289.           $check = $db->Execute($sql);
  290.  
  291.           // base restrictions zone restrictions for Delivery or Billing address
  292.           switch($coupon_result->fields['coupon_type']) {
  293.             case 'S': // shipping
  294.               // use delivery address
  295.               $check_zone_id = $order->delivery['zone_id'];
  296.               break;
  297.             case 'F': // amount
  298.               // use billing address
  299.               $check_zone_id = $order->billing['zone_id'];
  300.               break;
  301.             case 'P': // percentage
  302.               // use billing address
  303.               $check_zone_id = $order->billing['zone_id'];
  304.               break;
  305.             default:
  306.               // use billing address
  307.               $check_zone_id = $order->billing['zone_id'];
  308.               break;
  309.           }
  310.  
  311.           if ($coupon_result->fields['coupon_zone_restriction'] > 0) {
  312.             while (!$check->EOF) {
  313.               if ($check->fields['zone_id'] < 1) {
  314.                 $check_flag = true;
  315.                 break;
  316. //              } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
  317.               } elseif ($check->fields['zone_id'] == $check_zone_id) {
  318.                 $check_flag = true;
  319.                 break;
  320.               }
  321.               $check->MoveNext();
  322.             }
  323.             $foundvalid = $check_flag;
  324.           }
  325.           // remove if fails address validation
  326.           if (!$foundvalid) {
  327.             $messageStack->add_session('checkout_payment', TEXT_REMOVE_REDEEM_COUPON_ZONE, 'caution');
  328.             $this->clear_posts();
  329.             if (!$foundvalid) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
  330.           }
  331.         }
  332.       }
  333.       //      if ($_POST['submit_redeem_coupon_x'] && !$_POST['gv_redeem_code']) zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, 'credit_class_error_code=' . $this->code . '&credit_class_error=' . urlencode(TEST_NO_REDEEM_CODE), 'SSL', true, false));
  334.       $messageStack->add('checkout', TEXT_VALID_COUPON,'success');
  335.     }
  336.   }
  337.   /**
  338.    * Enter description here...
  339.    *
  340.    * @param unknown_type $i
  341.    * @return unknown
  342.    */
  343.   function update_credit_account($i) {
  344.     return false;
  345.   }
  346.   /**
  347.    * Enter description here...
  348.    *
  349.    */
  350.   function apply_credit() {
  351.     global $db, $insert_id;
  352.     $cc_id = $_SESSION['cc_id'];
  353.     if ($this->deduction !=0) {
  354.       $db->Execute("insert into " . TABLE_COUPON_REDEEM_TRACK . "
  355.                    (coupon_id, redeem_date, redeem_ip, customer_id, order_id)
  356.                    values ('" . (int)$cc_id . "', now(), '" . $_SERVER['REMOTE_ADDR'] . "', '" . (int)$_SESSION['customer_id'] . "', '" . (int)$insert_id . "')");
  357.     }
  358.     $_SESSION['cc_id'] = "";
  359.   }
  360.   /**
  361.    * Enter description here...
  362.    *
  363.    * @param unknown_type $order_total
  364.    * @return unknown
  365.    */
  366.   function calculate_deductions($order_total) {
  367.     global $db, $order, $messageStack, $currencies;
  368.     $tax_address = zen_get_tax_locations();
  369.     $od_amount = array();
  370.     $orderTotalDetails = $this->get_order_total();
  371.     $orderTotalTax = $orderTotalDetails['tax'];
  372.     $orderTotal = $orderTotalDetails['total'];
  373.     if ($_SESSION['cc_id']) {
  374.       $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . (int)$_SESSION['cc_id'] . "'");
  375.       $this->coupon_code = $coupon->fields['coupon_code'];
  376.       if (($coupon->RecordCount() > 0 && $orderTotal !=0) || ($coupon->RecordCount() > 0 && $coupon->fields['coupon_type']=='S') ) {
  377. // left for total order amount vs qualified order amount just switch the commented lines
  378. //        if ($orderTotalDetails['totalFull'] >= $coupon->fields['coupon_minimum_order']) {
  379.         if (strval($orderTotalDetails['total']) >= $coupon->fields['coupon_minimum_order']) {
  380.  
  381.           if ($coupon->fields['coupon_type']=='S') {
  382.             $od_amount['total'] = $_SESSION['shipping']['cost'];
  383.             $od_amount['type'] = 'S';
  384.             $od_amount['tax'] = ($this->calculate_tax == 'Standard') ? $_SESSION['shipping_tax_amount'] : 0;
  385.             if (DISPLAY_PRICE_WITH_TAX == 'true')
  386.             {
  387.               $od_amount['total'] += $od_amount['tax'];
  388.             }
  389.             if (isset($_SESSION['shipping_tax_description']) && $_SESSION['shipping_tax_description'] != '') {
  390.               $od_amount['tax_groups'][$_SESSION['shipping_tax_description']] = $od_amount['tax'];
  391.             }
  392.             return $od_amount;
  393.           }
  394.           if ($coupon->fields['coupon_type'] == 'P') {
  395.             $od_amount['total'] = round($orderTotal*($coupon->fields['coupon_amount']/100), 2);
  396.             $od_amount['type'] = 'P';
  397.             $ratio = $od_amount['total']/$orderTotal;
  398.           } elseif ($coupon->fields['coupon_type'] == 'F') {
  399.             $od_amount['total'] = round($coupon->fields['coupon_amount'] * ($orderTotal>0), 2);
  400.             $od_amount['type'] = 'F';
  401.             $ratio = $od_amount['total']/$orderTotal;
  402.           }
  403.           if ($od_amount['total'] > $orderTotal) $od_amount['total'] = $orderTotal;
  404.           switch ($this->calculate_tax) {
  405.             case 'None':
  406.               if ($this->include_tax == 'true') {
  407.                 reset($order->info['tax_groups']);
  408.                 foreach ($order->info['tax_groups'] as $key=>$value) {
  409.                   $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratio;
  410.                 }
  411.               }
  412.             break;
  413.             case 'Standard':
  414.             if ($od_amount['total'] >= $orderTotal) {
  415.               $ratio = 1;
  416.             }
  417.             $adjustedTax = $orderTotalTax * $ratio;
  418. //            echo "order total tax = $orderTotalTax";
  419.             $ratioTax = (isset($order->info['tax']) && $order->info['tax'] != 0) ? $adjustedTax/$order->info['tax'] : 0;
  420.             reset($order->info['tax_groups']);
  421.             $tax_deduct = 0;
  422.             foreach ($order->info['tax_groups'] as $key=>$value) {
  423.               $od_amount['tax_groups'][$key] = $order->info['tax_groups'][$key] * $ratioTax;
  424.               $tax_deduct += $od_amount['tax_groups'][$key];
  425.             }
  426.             $od_amount['tax'] = $tax_deduct;
  427.             break;
  428.             case 'Credit Note':
  429.               $tax_rate = zen_get_tax_rate($this->tax_class);
  430.               $od_amount['tax'] = zen_calculate_tax($od_amount['total'], $tax_rate);
  431.               $tax_description = zen_get_tax_description($this->tax_class);
  432.               $od_amount['tax_groups'][$tax_description] = $od_amount['tax'];
  433.             break;
  434.             default:
  435.           }
  436.         } else {
  437.           $messageStack->add_session('redemptions', sprintf(TEXT_INVALID_REDEEM_COUPON_MINIMUM, $currencies->format($coupon->fields['coupon_minimum_order'])),'caution');
  438.           $this->clear_posts();
  439.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL',true, false));
  440.         }
  441.       }
  442.     }
  443.     return $od_amount;
  444.   }
  445.   /**
  446.    * Enter description here...
  447.    *
  448.    * @return unknown
  449.    */
  450.   function get_order_total() {
  451.     global  $order;
  452.     $order_total_tax = $order->info['tax'];
  453.     $order_total = $order->info['total'];
  454. //    echo "order total = $order_total<br>";
  455. //    echo "order total shipping = {$order->info['shipping_cost']}<br>";
  456. //    echo "order total tax = {$order->info['tax']}<br>";
  457.     if ($this->include_shipping != 'true') $order_total -= $order->info['shipping_cost'];
  458.     if ($this->include_shipping != 'true') $order_total_tax -= $order->info['shipping_tax'];
  459.     if ($this->include_tax != 'true') $order_total -= $order->info['tax'];
  460.  //   if ($this->include_tax != "true" && $this->include_shipping != 'true') $order_total -= $order->info['shipping_tax'];
  461. //    echo "order total = $order_total<br>";
  462.     $orderTotalFull = $order_total;
  463.     $products = $_SESSION['cart']->get_products();
  464.     for ($i=0; $i<sizeof($products); $i++) {
  465.       if (!is_product_valid($products[$i]['id'], $_SESSION['cc_id'])) {
  466.         $order_total -= $products[$i]['final_price'] * $products[$i]['quantity'];
  467.         if ($this->include_tax == 'true') {
  468.           $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
  469.          $order_total -= (zen_calculate_tax($products[$i]['final_price'], $products_tax))   * $products[$i]['quantity'];
  470.         }
  471.         $order_total_tax -= (zen_calculate_tax($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id'])))   * $products[$i]['quantity'];
  472.       }
  473.     }
  474.     $orderTotalInclusive = $order_total + $order_total_tax;
  475.     if (DISPLAY_PRICE_WITH_TAX == 'true') $order_total += $order_total_tax;
  476.     $order_total = array('totalFull'=>$orderTotalFull, 'total'=>$order_total, 'tax'=>$order_total_tax, 'totalInclusive'=>$orderTotalInclusive);
  477.     return $order_total;
  478.   }
  479.   /**
  480.    * Enter description here...
  481.    *
  482.    * @return unknown
  483.    */
  484.   function check() {
  485.     global $db;
  486.     if (!isset($this->check)) {
  487.       $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
  488.       $this->check = $check_query->RecordCount();
  489.     }
  490.  
  491.     return $this->check;
  492.   }
  493.   /**
  494.    * Enter description here...
  495.    *
  496.    * @return unknown
  497.    */
  498.   function keys() {
  499.     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');
  500.   }
  501.   /**
  502.    * Enter description here...
  503.    *
  504.    */
  505.   function install() {
  506.     global $db;
  507.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('该模块已安装', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
  508.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('排序顺序', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '280', '显示的排序顺序。', '6', '2', now())");
  509.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('含运费', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', '计算时含运费', '6', '5', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
  510.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('含税', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'false', '计算时含税。', '6', '6','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
  511.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('重新计算税', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'Standard', '重新计算税', '6', '7','zen_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
  512.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('税率种类', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', '收取优惠券时,使用以下的税率种类。', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
  513.   }
  514.   /**
  515.    * Enter description here...
  516.    *
  517.    */
  518.   function remove() {
  519.     global $db;
  520.     $keys = '';
  521.     $keys_array = $this->keys();
  522.     for ($i=0; $i<sizeof($keys_array); $i++) {
  523.       $keys .= "'" . $keys_array[$i] . "',";
  524.     }
  525.     $keys = substr($keys, 0, -1);
  526.  
  527.     $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
  528.   }
  529. }
  530.  


cron