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

📄 ps_product.inc

📁 php做的网上商店系统。简单易懂
💻 INC
📖 第 1 页 / 共 2 页
字号:
  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function sql($product_id) {    $db = new ps_DB;    $q  = "SELECT * FROM product WHERE product_id='$product_id' ";    $db->query($q);    return $db;  }   /**************************************************************************  ** name: items_sql()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function items_sql($product_id) {    $db = new ps_DB;    $q  = "SELECT * FROM product ";    $q .= "WHERE product_parent_id='$product_id' ";    $q .= "ORDER BY product_name";    $db->query($q);    return $db;  }   /**************************************************************************  ** name: is_product()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function is_product($product_id) {    $db = new ps_DB;     $q  = "SELECT product_parent_id FROM product ";    $q .= "WHERE product_id='$product_id' ";     $db->query($q);    $db->next_record();    if ($db->f("product_parent_id") == 0) {      return true;    }    else {      return false;    }  }  /**************************************************************************  ** name: attribute_sql()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function attribute_sql($item_id="",$product_id="",$attribute_name="") {    $db = new ps_DB;    if ($item_id and $product_id) {      $q  = "SELECT * FROM product_attribute,product_attribute_sku ";      $q .= "WHERE product_attribute.product_id = '$item_id' ";      $q .= "AND product_attribute_sku.product_id ='$product_id' ";      if ($attribute_name) {        $q .= "AND product_attribute.attribute_name = $attribute_name ";      }      $q .= "AND product_attribute.attribute_name = ";      $q .=     "product_attribute_sku.attribute_name ";      $q .= "ORDER BY attribute_list,product_attribute.attribute_name";    } elseif ($item_id) {      $q  = "SELECT * FROM product_attribute ";      $q .= "WHERE product_id = '$item_id' ";      if ($attribute_name) {        $q .= "AND attribute_name = $attribute_name ";      }    } elseif ($product_id) {      $q  = "SELECT * FROM product_attribute_sku ";      $q .= "WHERE product_id ='$product_id' ";      if ($attribute_name) {        $q .= "AND product_attribute.attribute_name = $attribute_name ";      }      $q .= "ORDER BY attribute_list,attribute_name";    } else {      /* Error: no arguments were provided. */      return 0;    }        $db->query($q);    return $db;  }  /**************************************************************************  ** name: get_child_product_ids()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function get_child_product_ids($pid) {    $db = new ps_DB;    $q  = "SELECT product_id FROM product ";    $q .= "WHERE product_parent_id='$pid' ";    $db->query($q);    $i = 0;    while($db->next_record()) {      $list[$i] = $db->f("product_id");      $i++;    }    return $list;  }  /**************************************************************************  ** name: parent_has_children()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function parent_has_children($pid) {    $db = new ps_DB;    $q  = "SELECT * FROM product WHERE product_parent_id='$pid' ";    $db->query($q);    if ($db->next_record()) {      return True;    }    else {      return False;    }  }  /**************************************************************************  ** name: product_has_attributes()  ** created by: jep  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function product_has_attributes($pid) {    $db = new ps_DB;    $q  = "SELECT * FROM product_attribute_sku WHERE product_id='$pid' ";    $db->query($q);    if ($db->next_record()) {      return True;    }    else {      return False;    }  }  /**************************************************************************  ** name: get_field()  ** created by: pablo  ** description:  ** parameters:  ** returns:  ***************************************************************************/  function get_field($product_id, $field_name) {    $db = new ps_DB;    $q = "SELECT $field_name FROM product WHERE product_id='$product_id'";    $db->query($q);    if ($db->next_record()) {       return $db->f($field_name);    }    else {       return False;    }  }  /**************************************************************************  ** name: get_flypage()  ** created by: pablo  ** description:  Determines flypage for given product_id by looking at  **               the product category.  If no flypage is specified for this  ** 		   category, then the default FLYPAGE (in phpshop.cfg) is   **		   returned.  ** parameters:  ** returns:  ***************************************************************************/  function get_flypage($product_id) {    $db = new ps_DB;    $q = "SELECT category.category_flypage FROM category, product_category_xref, product ";    $q .= "WHERE product.product_id='$product_id' ";    $q .= "AND product_category_xref.product_id=product.product_id ";    $q .= "AND product_category_xref.category_id=category.category_id";    $db->query($q);    $db->next_record();    if ($db->f("category_flypage")) {      return $db->f("category_flypage");    }    else {      return FLYPAGE;    }  }  /**************************************************************************  ** name: show_image()  ** created by: pablo  ** description:  Shows the image send in the $image field.  **               $args are appended to the IMG tag.  ** parameters:  ** returns:  ***************************************************************************/  function show_image($image, $args="") {        eval(load_class("vendor","ps_vendor"));    $ps_vendor = new ps_vendor;    global $ps_vendor_id;    global $SERVER_PORT;    if ($SERVER_PORT == "443")	$url = SECUREURL;    else        $url = URL;    $url = $ps_vendor->get_field($ps_vendor_id,"vendor_image_path");    $url .= "product/";    $url .= $image;    echo "<IMG SRC=$url $args>";        return True;  }  /**************************************************************************   ** name: get_price($product_id)   ** created by:   ** description: gets price for a given product Id based on   **              the shopper group a user belongs to and whether   **              and item has a price or it must grab it from the    **              parent.   ** parameters:   ** returns:   ***************************************************************************/  function get_price($product_id) {    global $auth;    $db = new ps_DB;        // Get the vendor id for this product.    $q = "SELECT vendor_id FROM product WHERE product_id='$product_id'";    $db->query($q);    $db->next_record();    $vendor_id = $db->f("vendor_id");        // Get the shopper group id for this product and user    $q = "SELECT shopper_group_id FROM shopper_vendor_xref WHERE ";    $q .= "user_id='";    $q .= $auth["user_id"] . "' AND vendor_id='$vendor_id'";    $db->query($q);    $db->next_record();    $shopper_group_id = $db->f("shopper_group_id");        // Get the default shopper group id for this product and user    $q = "SELECT * FROM shopper_group WHERE ";    $q .= "vendor_id='$vendor_id' AND ";    $q .= "shopper_group_name='市场价'";    $db->query($q);    $db->next_record();    $default_shopper_group_id = $db->f("shopper_group_id");        // Get the product_parent_id for this product/item    $product_parent_id = $this->get_field($product_id, "product_parent_id");            // Getting prices    //    // If the shopper group has a price then show it, otherwise    // show the default price.    $q = "SELECT * from product_price WHERE product_id='$product_id' AND ";    $q .= "shopper_group_id='$shopper_group_id'";    $db->query($q);    if ($db->next_record()) {      $price_info["product_price"]=$db->f("product_price");      $price_info["product_currency"]=$db->f("product_currency");      $price_info["item"]=True;      return $price_info;    }        // Get default price    $q = "SELECT * from product_price WHERE product_id='$product_id' AND ";    $q .= "shopper_group_id='$default_shopper_group_id'";    $db->query($q);    if ($db->next_record()) {      $price_info["product_price"]=$db->f("product_price");      $price_info["product_currency"]=$db->f("product_currency");      $price_info["item"]=True;      return $price_info;    }        // Maybe its an item with no price, check again with product_parent_id    $q = "SELECT * from product_price WHERE product_id='$product_parent_id' AND ";    $q .= "shopper_group_id='$shopper_group_id'";    $db->query($q);    if ($db->next_record()) {      $price_info["product_price"]=$db->f("product_price");      $price_info["product_currency"]=$db->f("product_currency");      return $price_info;    }        $q = "SELECT * from product_price WHERE product_id='$product_parent_id' AND ";    $q .= "shopper_group_id='$default_shopper_group_id'";    $db->query($q);    if ($db->next_record()) {      $price_info["product_price"]=$db->f("product_price");      $price_info["product_currency"]=$db->f("product_currency");      return $price_info;    }        // No price found    return False;  }  /**************************************************************************   ** name: show_snapshot($product_sku)   ** created by:   ** description: display a snapshot of a product based on the product sku.   **              This was written to privde a quick way to display a product on   **              a side navigation bar.   ** parameters:   ** returns:   ***************************************************************************/  function show_snapshot($product_sku) {    global $ps_vendor_id, $sess;    $db = new ps_DB;    $q = "SELECT * from product WHERE product_sku='$product_sku'";    $db->query($q);    if ($db->next_record()) {      $price = $this->get_price($db->f("product_id"));//      $category = $this->get_category($db->f("vendor_id"));       echo "<table width='280' border='0' cellspacing='0' cellpadding='0' height='180'><tr><td colspan='2' height='30'>&nbsp;&nbsp;&nbsp;&nbsp;<B>".$db->f("product_name")."</B>\n";      echo "</td></tr><tr><td width='120' height='140'><div align='center'>\n";      $url = "?page=".$this->get_flypage($db->f("product_id"));      $url .= "&product_id=" . $db->f("product_id");      echo "<A HREF=". $sess->url(URL . $url).">";      $this->show_image($db->f("product_thumb_image"), "border=0");      echo "</A></div></td><td width='120' height='140'>";      echo $db->f("product_s_desc")."<A HREF=?page=".$this->get_flypage($db->f("product_id"))."&product_id=" . $db->f("product_id").">TUV/GS/CE......</a><br>市场价:<font color=red>" . $price["product_price"] . $price["product_currency"]."</font><br>&nbsp;</td></tr>";      echo "<tr><td width='120' align='right'>\n";      $url = "?page=shop/cart&func=cartAdd&product_id=" .  $db->f("product_id");      echo "<A HREF=?page=".$this->get_flypage($db->f("product_id"))."&product_id=" . $db->f("product_id")."><img src='/phpshop/images/g-2.gif' border=0></A></td>\n";      echo "<td width='120' align='right'><A HREF=". $sess->url(URL . $url)."><img src='/phpshop/images/g-1.gif' border=0></A></td></table><br>\n";    }    else {      // Product SKU not found      return False;    }      }  }?>

⌨️ 快捷键说明

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