📄 ps_intershipper.inc
字号:
** returns: boolean ***************************************************************************/ function validate() { /* verify that Intershipper module is activated and that * we have authorization to make a request of * the Intershipper server. */ if (!IS_ENABLE) { $this->error = "InterShipper module not activated."; return false; } elseif (!IS_EMAIL) { $this->error = "InterShipper authorization email address missing."; return false; } elseif (!IS_PASSWORD) { $this->error = "Intershipper authorization password missing."; return false; } return true; } /************************************************************************** ** name: fetch_quote() ** created by: Matt Oberpriller ** description: Retrieve shipping quotes from shipper ** parameters: HTTP Post vars - usually $vars ** returns: multidimensional array of rate, ship date, and delivery date ** by ship method ID. ** ** $quote[$ship_method_id]["rate"] = method rate ** $quote[$ship_method_id]["sdate"] = method ship date ** $quote[$ship_method_id]["ddate"] = methods delivery date ***************************************************************************/ function fetch_quote(&$d) { global $ps_vendor_id; global $cart; global $IS_quote; global $IS_check; global $sess; $qvars = array(); eval(load_class("ISshipping", "Intershipper")); $Intershipper = new InterShipper; $db = new ps_DB; /* Check for a ship to address. */ if (!$d["user_info_id"]) { if (!$d["ship_to_info_id"]) { $d["error"] = "Ship to address required."; return False; } else { $shipto_id = $d["ship_to_info_id"]; } } else { $shipto_id = $d["user_info_id"]; } /* If a quote already exists, check to see if cart, quote, or ship to * address has changed since last function call. If not, * return the existing quote. */ $status = serialize($cart) . serialize($IS_quote) . $shipto_id; if (is_array($IS_quote) && (strcmp($IS_check,$status) == 0)) return($IS_quote); /* Set authorization information */ $Intershipper->Request['email'] = IS_EMAIL; $Intershipper->Request['password'] = IS_PASSWORD; /* Get active carriers */ $q = "SELECT DISTINCT(ship_carrier_code) FROM ISshipping "; $q .= "WHERE ship_publish='Y' "; $q .= "AND vendor_id='$ps_vendor_id'"; $db->query($q); while ($db->next_record()) { $carriers .= $db->f("ship_carrier_code") . "|"; } $carriers = substr($carriers,0,(strlen($carriers)-1)); $Intershipper->Request['carriers'] = $carriers; /* Calculate total weight of all products. Since only one * unit of measure can be sent. All product weights must * be converted into a single unit of measure. I chose * ounces because I'm a stubborn American. */ for($i = 0; $i < $cart["idx"]; $i++) { if(!($product_weight_arr = $this->get_weight($cart[$i]["product_id"]))) { $d["error"]=$this->error; return false; } else { $totalweight += $product_weight_arr * $cart[$i]["quantity"]; } } /* weights must be integers * and cannot be 0 */ if (($totalweight / 16) < 1) { $totalweight = ceil($totalweight); $uom = "OZ"; } else { $totalweight = round($totalweight / 16); $uom = "LB"; } $Intershipper->Request['weight'] = $totalweight; $Intershipper->Request['weightunits'] = $uom; /* Get customer destination info */ $q = "SELECT * FROM user_info "; $q .= "WHERE user_info_id='$shipto_id'"; $db->query($q); $db->next_record(); $Intershipper->Request['Daddress'] = $db->f("address_1"); $Intershipper->Request['Dcity'] = $db->f("city"); $Intershipper->Request['Dstate'] = $db->f("state"); $Intershipper->Request['Dpostalcode'] = $db->f("zip"); $Intershipper->Request['Dcountry'] = $db->f("country"); $Intershipper->Request['Dresidential'] = "YES"; /* Get vendor origin info */ $q = "SELECT * from vendor "; $q .= "WHERE vendor_id='$ps_vendor_id'"; $db->query($q); $db->next_record(); $Intershipper->Request['Oaddress'] = $db->f("vendor_address_1"); $Intershipper->Request['Ocity'] = $db->f("vendor_city"); $Intershipper->Request['Ostate'] = $db->f("vendor_state"); $Intershipper->Request['Opostalcode'] = $db->f("vendor_zip"); $Intershipper->Request['Ocountry'] = $db->f("vendor_country"); $Intershipper->Request['Oresidential'] = "NO"; /* Make our request */ if (!$this->validate() || !$Intershipper->Quote(60)) { $qvars = $this->default_method(); } else { $response=$Intershipper->getQuote(); $q = "SELECT * FROM ISshipping "; $q .= "WHERE ship_publish='Y' "; $q .= "AND vendor_id='$ps_vendor_id'"; $db->query($q); while ($db->next_record()) { reset($response); while (list($key,$val)=each($response)) { if (strcmp(trim($db->f("ship_method_code")),trim($response[$key]["methodcode"])) == 0) { $rate = $response[$key]["rate"]; /* calculate our handling charges */ if (($db->f("ship_handling_charge") <> 0) && ($db->f("ship_handling_type") == "P")) $rate = $rate + ($rate * ($db->f("ship_handling_charge") / 100)); elseif (($db->f("ship_handling_charge") <> 0) && ($db->f("ship_handling_type") == "F")) $rate = $rate + $db->f("ship_handling_charge"); $rate = sprintf("%8.2f", $rate); /* calculate our ship date */ $ship = time() + ($db->f("ship_lead_time") * 86400); /* calculate the arrival date */ $date = split("/", $response[$key]["date"]); $time = split(":", $response[$key]["time"]); $month = $date[0]; $day = $date[1]; $year = $date[2]; $hour = $time[0]; $min = $time[1]; $arrive = mktime($hour, $min, 0, $month, $day, $year); $arrive = $arrive + ($db->f("ship_lead_time") * 86400); /* we don't ship or deliver on weekends */ if (strtoupper(date("D", $ship)) == "SAT") { $ship += (2 * 86400); $arrive += (2 * 86400); } elseif (strtoupper(date("D", $ship)) == "SUN") { $ship += 86400; $arrive += 86400; } if (strtoupper(date("D", $arrive)) == "SAT") $arrive += (2 * 86400); elseif (strtoupper(date("D", $arrive)) == "SUN") $arrive += 86400; $id = $db->f("ship_method_id"); $qvars["$id"]["rate"] = $rate; $qvars["$id"]["ddate"] = $arrive; $qvars["$id"]["sdate"] = $ship; } } } } if (!$qvars) { $qvars = $this->default_method(); //return false; } else { /* save the quote */ $IS_quote = $qvars; $sess->register("IS_quote"); /* save cart, quote, and ship to address for verification of changes */ $IS_check = serialize($cart) . serialize($IS_quote) . $shipto_id; $sess->register("IS_check"); return($qvars); } } /************************************************************************** ** name: default_method() ** created by: Matt Oberpriller ** description: Empty function where a default shipping calculation method ** can be defined. ** parameters: ** returns: ** ***************************************************************************/ function default_method() { $qvars =array(); /* This method was left empty intentionaly. It is here for the sole * purpose of allowing developers to insert their own method of * calculating shipping charges in the event that the InterShipper server * does not respond, or has been disabled. */ return $qvars; } function get_rate($d) { global $ps_vendor_id; $db = new ps_DB; $prices = array(); $q = "SELECT * FROM ISshipping "; $q .= "WHERE ship_publish='Y' "; $q .= "AND vendor_id='$ps_vendor_id' "; $q .= "ORDER BY ship_carrier_name ASC"; $db->query($q); $ship_method_id = $d["ship_method_id"]; $prices = $this->fetch_quote($d); while ($db->next_record()) { reset($prices); while (list($key,$val)=each($prices)) { if (strcmp($key,$db->f("ship_method_id")) == 0) { if ($ship_method_id && (strcmp($ship_method_id,$db->f("ship_method_id")) == 0)) { return $prices[$key]["rate"]; } } } } }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -