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

📄 ot_coupon.php

📁 Zen Cart是一款最新的购物车软件
💻 PHP
📖 第 1 页 / 共 2 页
字号:
      $coupon = $db->Execute("select * from " . TABLE_COUPONS . " where coupon_id = '" . $_SESSION['cc_id'] . "'");
      if (($coupon->RecordCount() > 0 && $order_total !=0) || ($coupon->RecordCount() > 0 && $coupon->fields['coupon_type']=='S') ) {
        if ($coupon->fields['coupon_minimum_order'] <= $order_total) {
          if ($coupon->fields['coupon_type']=='S') {
            $od_amount['total'] = $order->info['shipping_cost'];
            $od_amount['type'] = 'S';
          } else {
            if ($coupon->fields['coupon_type'] == 'P') {
              $od_amount['total'] = zen_round($order_total*($coupon->fields['coupon_amount']/100), 2);
            } else {
              $od_amount['total'] = $coupon->fields['coupon_amount'] * ($order_total>0);
            }
            if ($od_amount['total']>$order_total) $od_amount['total'] = $order_total;
            $products = $_SESSION['cart']->get_products();
            for ($i=0; $i<sizeof($products); $i++) {
              // speed up process and store value
              $is_valid_results = is_product_valid($products[$i]['id'], $_SESSION['cc_id']);
              if ($is_valid_results) {
                if ($coupon->fields['coupon_type'] == 'P') {
                  switch ($this->calculate_tax) {
                    case 'Credit Note':
                      $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                      $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                      $od_amount[$tax_desc] = $od_amount['total'] / 100 * $tax_rate;
                      $od_amount['tax'] += $od_amount[$tax_desc];
                    break;
                    case 'Standard':
                      $ratio = $od_amount['total']/$this->get_order_total();
                      $products = $_SESSION['cart']->get_products();
                      for ($j=0; $j<sizeof($products); $j++) {
                        $t_prid = zen_get_prid($products[$j]['id']);
                        $cc_result = $db->Execute("select products_tax_class_id
                                                   from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");

                        if ($is_valid_results) {
                          $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                          $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                          if ($tax_rate > 0) {
//                            $od_amount[$tax_desc] += (($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate)/100 * $ratio;
                            $od_amount[$tax_desc] += round(((($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate) + .5)/100 * $ratio, 2);
                            $od_amount['tax'] += $od_amount[$tax_desc];
                          }
                        }
                      }
                    break;
                    default:
                  }
                }
                if ($coupon->fields['coupon_type'] == 'F') {
                  switch ($this->calculate_tax) {
                    case 'Credit Note':
                      $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                      $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']);
                      $od_amount[$tax_desc] = $od_amount['total'] / 100 * $tax_rate;
                      $od_amount['tax'] += $od_amount[$tax_desc];
                    break;
                    case 'Standard':
                      $ratio = $od_amount['total']/$this->get_order_total();
                      $products = $_SESSION['cart']->get_products();
                      for ($j=0; $j<sizeof($products); $j++) {
                        $t_prid = zen_get_prid($products[$j]['id']);
                        $cc_result = $db->Execute("select products_tax_class_id
                                                   from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");

                        if ($is_valid_results) {
                          $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                          $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']);
                          if ($tax_rate > 0) {
//                            $od_amount[$tax_desc] += (($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate)/100 * $ratio;
                            $od_amount[$tax_desc] += round(((($products[$j]['final_price'] * $products[$j]['quantity']) * $tax_rate) + .5)/100 * $ratio, 2);
                            $od_amount['tax'] += $od_amount[$tax_desc];
                          }
                        }
                      }
                    break;
                    default:
                  }
                }
              }
            }
          }
        }
      }
    }
    return $od_amount;
  }

  function get_order_total() {
    global  $order;
    $products = $_SESSION['cart']->get_products();
    $order_total = 0;
    for ($i=0; $i<sizeof($products); $i++) {
      if (is_product_valid($products[$i]['id'], $_SESSION['cc_id'])) {
        $order_total += $products[$i]['final_price'] * $products[$i]['quantity'];
	      if ($this->include_tax == 'true') {
          $products_tax = zen_get_tax_rate($products[$i]['tax_class_id']);
          $order_total += (zen_calculate_tax($products[$i]['final_price'], $products_tax))   * $products[$i]['quantity'];
	      }
      }
    }
    if ($this->include_shipping == 'true') $order_total += $order->info['shipping_cost'];
    return $order_total;
  }

  function get_product_price($product_id) {
    global $db, $order;
    $products_id = zen_get_prid($product_id);
 // products price
    $qty = $_SESSION['cart']->contents[$product_id]['qty'];
    $product = $db->Execute("select products_id, products_price, products_tax_class_id, products_weight
                             from " . TABLE_PRODUCTS . " where products_id='" . $products_id . "'");

    if ($product->RecordCount() > 0) {
      $prid = $product->fields['products_id'];
      $products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']);
      $products_price = $product->fields['products_price'];
      $specials = $db->Execute("select specials_new_products_price
                                from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");

      if ($specials->RecordCount() > 0 ) {
        $products_price = $specials->fields['specials_new_products_price'];
      }
      if ($this->include_tax == 'true') {
        $total_price += ($products_price + zen_calculate_tax($products_price, $products_tax)) * $qty;
      } 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 = $db->Execute("select options_values_price, price_prefix
                                           from " . TABLE_PRODUCTS_ATTRIBUTES . "
                                           where products_id = '" . $prid . "'
                                           and options_id = '" . $option . "'
                                           and options_values_id = '" . $value . "'");

          if ($attribute_price->fields['price_prefix'] == '-') {
            if ($this->include_tax == 'true') {
              $total_price -= $qty * ($attribute_price->fields['options_values_price'] + zen_calculate_tax($attribute_price->fields['options_values_price'], $products_tax));
            } else {
              $total_price -= $qty * ($attribute_price->fields['options_values_price']);
            }
          } else {
            if ($this->include_tax == 'true') {
              $total_price += $qty * ($attribute_price->fields['options_values_price'] + zen_calculate_tax($attribute_price->fields['options_values_price'], $products_tax));
            } else {
              $total_price += $qty * ($attribute_price->fields['options_values_price']);
            }
          }
        }
      }
    }
    return $total_price;
  }

    function check() {
      global $db;
      if (!isset($this->check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
        $this->check = $check_query->RecordCount();
      }

      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() {
      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 ('This module is installed', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '280', 'Sort order of display.', '6', '2', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '5', 'zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'false', 'Include Tax in calculation.', '6', '6','zen_cfg_select_option(array(\'true\', \'false\'), ', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'Standard', 'Re-Calculate Tax', '6', '7','zen_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
      $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 ('Tax Class', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', 'Use the following tax class when treating Discount Coupon as Credit Note.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
    }

    function remove() {
      global $db;
      $keys = '';
      $keys_array = $this->keys();
      for ($i=0; $i<sizeof($keys_array); $i++) {
        $keys .= "'" . $keys_array[$i] . "',";
      }
      $keys = substr($keys, 0, -1);

      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
    }
  }
?>

⌨️ 快捷键说明

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