shopping_cart.php

来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 377 行 · 第 1/2 页

PHP
377
字号
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $qty = $this->contents[$products_id]['qty'];

        $product_query = $db->query("select products_id, products_price, products_tax_class_id, products_weight,products_type from $table_products where products_id = '" . (int)$products_id . "'");
        if ($product = $db->fetch_array($product_query)) {
          $prid = $product['products_id'];
          $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
          $products_price = $product['products_price'];
          $products_weight = $product['products_weight'];
          
          if($customer_email && $groupdiscount>=1 && $groupdiscount<10 && MARK_OF_CUSTOMER_DISPLAYE=='True'){
              $groupdiscount=$groupdiscount<MARK_OF_CUSTOMER_BIG ? MARK_OF_CUSTOMER_BIG : $groupdiscount; 
							$products_price=$product['products_price']*$groupdiscount/10;
          }elseif((DEFAULT_DISCOUNT>0) && (DEFAULT_DISCOUNT<10) && MARK_OF_CUSTOMER_DISPLAYE=='True'){
              $products_price=$product['products_price']*(float)DEFAULT_DISCOUNT/10;
          }
              
					$specials_query = $db->query("select specials_new_products_price from $table_specials where products_id = '" . (int)$prid . "' and status = '1'");
          if ($db->num_rows ($specials_query)) {
              $specials = $db->fetch_array($specials_query);
              $products_price = $specials['specials_new_products_price'];
          }

          $this->total += tep_add_tax($products_price, $products_tax) * $qty;
          $this->weight += ($qty * $products_weight);
        }

        if (isset($this->contents[$products_id]['attributes'])) {
          reset($this->contents[$products_id]['attributes']);
          while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
            $attribute_price_query = $db->query("select options_values_price, price_prefix from $table_products_attributes where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
            $attribute_price = $db->fetch_array($attribute_price_query);
						if ($attribute_price['price_prefix'] == '+') {
              $this->total = $this->total+($qty * tep_add_tax($attribute_price['options_values_price'], $products_tax));
            } else {
              $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
            }
          }
        }
      }
    }

    function attributes_price($products_id) {
        global $db,$table_products_attributes;
			$attributes_price = 0;

      if (isset($this->contents[$products_id]['attributes'])) {
        reset($this->contents[$products_id]['attributes']);
        while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
          $attribute_price_query = $db->query("select options_values_price, price_prefix from $table_products_attributes where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
          $attribute_price = $db->fetch_array($attribute_price_query);
          if ($attribute_price['price_prefix'] == '+') {
            $attributes_price += $attribute_price['options_values_price'];
          } else {
            $attributes_price -= $attribute_price['options_values_price'];
          }
        }
      }

      return $attributes_price;
    }

    function get_products() {
      global $db,$languages_id,$table_specials,$table_products,$table_products_description, $customer_email, $groupdiscount;

      if (!is_array($this->contents)) return false;

      $products_array = array();
      reset($this->contents);
      while (list($products_id, ) = each($this->contents)) {
        $products_query = $db->query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price,p.products_type, p.products_weight, p.products_tax_class_id from $table_products p, $table_products_description pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
        if ($products = $db->fetch_array($products_query)) {
          $prid = $products['products_id'];
          $products_price = $products['products_price'];
          if($customer_email && $groupdiscount>=1 && $groupdiscount<10 && MARK_OF_CUSTOMER_DISPLAYE=='True'){
              $groupdiscount= $groupdiscount<MARK_OF_CUSTOMER_BIG ? MARK_OF_CUSTOMER_BIG : $groupdiscount; 
							$products_price=$products['products_price']*$groupdiscount/10;
          }elseif((DEFAULT_DISCOUNT>0) && (DEFAULT_DISCOUNT<10) && MARK_OF_CUSTOMER_DISPLAYE=='True'){
             $products_price=$products_price*(float)DEFAULT_DISCOUNT/10;
          }
          
          $specials_query = $db->query("select specials_new_products_price from $table_specials where products_id = '" . (int)$prid . "' and status = '1'");
          if ($db->num_rows($specials_query)) {
            $specials = $db->fetch_array($specials_query);
            $products_price = $specials['specials_new_products_price'];
          }

          $products_array[] = array('id' => $products_id,
                                    'name' => $products['products_name'],
                                    'model' => $products['products_model'],
                                    'image' => $products['products_image'],
                                    'price' => $products_price,
                                    'quantity' => $this->contents[$products_id]['qty'],
                                    'weight' => $products['products_weight'],
                                    'final_price' => $products_price+ $this->attributes_price($products_id),
                                    'tax_class_id' => $products['products_tax_class_id'],
                                    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
        }
      }

      return $products_array;
    }

    function show_total() {
      $this->calculate();

      return $this->total;
    }

    function show_weight() {
      $this->calculate();

      return $this->weight;
    }

    function generate_cart_id($length = 5) {
      return tep_create_random_value($length, 'digits');
    }

    function get_content_type() {
       global $db,$table_products_attributes,$table_products_attributes_download;
			$this->content_type = false;

      if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          if (isset($this->contents[$products_id]['attributes'])) {
            reset($this->contents[$products_id]['attributes']);
            while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
              $virtual_check_query =$db->query("select count(*) as total from $table_products_attributes pa, $table_products_attributes_download pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
              $virtual_check = $db->fetch_array($virtual_check_query);

              if ($virtual_check['total'] > 0) {
                switch ($this->content_type) {
                  case 'physical':
                    $this->content_type = 'mixed';

                    return $this->content_type;
                    break;
                  default:
                    $this->content_type = 'virtual';
                    break;
                }
              } else {
                switch ($this->content_type) {
                  case 'virtual':
                    $this->content_type = 'mixed';

                    return $this->content_type;
                    break;
                  default:
                    $this->content_type = 'physical';
                    break;
                }
              }
            }
          } else {
            switch ($this->content_type) {
              case 'virtual':
                $this->content_type = 'mixed';

                return $this->content_type;
                break;
              default:
                $this->content_type = 'physical';
                break;
            }
          }
        }
      } else {
        $this->content_type = 'physical';
      }

      return $this->content_type;
    }

    function unserialize($broken) {
      for(reset($broken);$kv=each($broken);) {
        $key=$kv['key'];
        if (gettype($this->$key)!="user function")
        $this->$key=$kv['value'];
      }
    }

  }
?>

⌨️ 快捷键说明

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