📄 ps_intershipper.inc
字号:
<?phpclass ps_intershipper { var $classname = "ps_intershipper"; var $error; /* The correlation between carrier ID and carrier CODE needs to be made * here. Intershipper returns the carrier ID in the return * quote, but we need to send the carrier CODE in the request. As * Intershipper adds more carriers, this list will need to be updated. */ var $carriers = array("918854856" => "RPS", "452235464" => "ANX", "919801409" => "ABX", "918593305" => "USPS", "1044186586" => "FDX", "919202226" => "DHL", "908801501" => "UPS", "966637132" => "EWW", "927757907" => "BAX"); /************************************************************************** ** name: refresh() ** created by: Matt Oberpriller ** description: Refresh database with Intershipper shippers. ** parameters: None ** returns: Boolean ***************************************************************************/ function refresh() { global $ps_vendor_id; /* validate module activation and InterShipper authorization */ if (!$this->validate()) { return false; } /* check InterShipper server status */ if (!$this->ping()) { return false; } eval(load_class("ISshipping", "Intershipper")); $Intershipper = new InterShipper(); $db = new ps_DB; $timestamp = time(); /* retrieve both light and heavy shipping methods */ $weight[] = 200; $weight[] = 1; /* Seed Intershipper API authentication variables and * give dummy zip codes and weight so that intershipper * will return all ship methods */ /* purge the current shipper database */ $q = "DELETE FROM ISshipping "; $q .= "WHERE vendor_id='$ps_vendor_id'"; $db->query($q); reset($weight); while(list($Wkey,$Wval)=each($weight)) { $Intershipper->Request['carriers'] = "ALL"; $Intershipper->Request['email'] = IS_EMAIL; $Intershipper->Request['password'] = IS_PASSWORD; $Intershipper->Request['Opostalcode'] = "30307"; $Intershipper->Request['Dpostalcode'] = "21201"; $Intershipper->Request['weight'] = intval($Wval); $Intershipper->Request['weightuom'] = "PO"; /* Get the quote for all shippers */ if (!$Intershipper->Quote(60)) { $this->error = $Intershipper->Last_Error; return false; } else { $result=$Intershipper->getQuote(); reset($result); while (list($key,$val)=each($result)) { reset($this->carriers); while(list($Ckey,$Cval)=each($this->carriers)) { if (strcmp(trim($result[$key]["carrierid"]),trim($Ckey)) == 0) $result[$key]["carriercode"] = $Cval; } $q = "SELECT * FROM ISshipping "; $q .= "WHERE vendor_id='$ps_vendor_id' "; $q .= "AND ship_method_code='" . $result[$key]["methodcode"] . "'"; $db->query($q); if (($Wval == 200) && ($db->num_rows() == 0)) { $i = "INSERT INTO ISshipping (ship_carrier_code,ship_carrier_id,ship_carrier_name,ship_method_code,"; $i .= "ship_method_name,ship_publish,ship_handling_charge,ship_lead_time,cdate,vendor_id,ship_heavy) "; $i .= "VALUES ('" . $result[$key]["carriercode"] . "','" . $result[$key]["carrierid"] . "','"; $i .= $result[$key]["carriername"] . "','" . $result[$key]["methodcode"] . "','"; $i .= $result[$key]["methodname"] . "','N','0','0','"; $i .= $timestamp . "','" . $ps_vendor_id . "','Y')"; $db->query($i); } elseif ($db->num_rows() == 0) { $i = "INSERT INTO ISshipping (ship_carrier_code,ship_carrier_id,ship_carrier_name,ship_method_code,"; $i .= "ship_method_name,ship_publish,ship_handling_charge,ship_lead_time,cdate,vendor_id) VALUES ('"; $i .= $result[$key]["carriercode"] . "','" . $result[$key]["carrierid"] . "','"; $i .= $result[$key]["carriername"] . "','" . $result[$key]["methodcode"] . "','"; $i .= $result[$key]["methodname"] . "','N','0','0','"; $i .= $timestamp . "','" . $ps_vendor_id . "')"; $db->query($i); } } } } return true; } /************************************************************************** ** name: ping() ** created by: Matt Oberpriller ** description: Ping the Intershipper server and get shipper response time. ** parameters: None ** returns: Array $status[$carrier][$response] ***************************************************************************/ function ping() { /* validate module activation and InterShipper authorization */ if (!$this->validate()) { return false; } eval(load_class("ISshipping", "Intershipper")); $Intershipper = new InterShipper(); /* Seed Intershipper API authentication variables and * give dummy weight */ $Intershipper->Request['carriers'] = "ALL"; $Intershipper->Request['email'] = IS_EMAIL; $Intershipper->Request['password'] = IS_PASSWORD; $Intershipper->Request['weight'] = "1.1"; /* Get carrier response times */ if (!$Intershipper->Quote(60)) { $this->error = $Intershipper->Last_Error; return false; } else { $ping=$Intershipper->RequestData; $pattern = "/<CARRIER .*?<\/CARRIER>/i"; $carriercount = preg_match_all($pattern, $ping, $carriers, PREG_SET_ORDER); for($idx = 0; $idx < $carriercount; $idx ++) { $pattern = "/<CARRIER [^>]*NAME[ ]*=[ ]*\"([^\"]*)/i"; preg_match($pattern, $carriers[$idx][0], $temp); $carrier = $temp[1]; $pattern = "/<CARRIER [^>]*ELAPSEDTIME[ ]*=[ ]*\"([^\"]*)/i"; preg_match($pattern, $carriers[$idx][0], $temp); $response = $temp[1]; $status[$carrier] = $response; } } return($status); } /************************************************************************** ** name: update() ** created by: Matt Oberpriller ** description: Update shipping_method with changes. ** parameters: HTTP Post vars - usually $vars ** returns: Boolean ***************************************************************************/ function update(&$d) { global $ps_vendor_id; $timestamp = time(); $db=new ps_DB; /* We will check for an array of ship methods to be updated * if it's not an array, we'll update just one record. */ if (count($d["ship_method_id"])) { reset($d["ship_method_id"]); while(list($key,$val)=each($d["ship_method_id"])) { $q = "UPDATE ISshipping SET "; $q .= "ship_carrier_id='" . $d["ship_carrier_id"][$key] . "',"; $q .= "ship_carrier_code='" . $d["ship_carrier_code"][$key] . "',"; $q .= "ship_carrier_name='" . $d["ship_carrier_name"][$key] . "',"; $q .= "ship_method_code='" . $d["ship_method_code"][$key] . "',"; $q .= "ship_method_name='" . $d["ship_method_name"][$key] . "',"; $q .= "ship_publish='" . $d["ship_publish"][$key] . "',"; $q .= "ship_handling_charge='" . $d["ship_handling_charge"][$key] . "',"; $q .= "ship_handling_type='" . $d["ship_handling_type"][$key] . "',"; $q .= "ship_lead_time='" . $d["ship_lead_time"][$key] . "',"; $q .= "ship_msg_header='" . $d["ship_msg_header"][$key] . "',"; $q .= "ship_msg_footer='" . $d["ship_msg_footer"][$key] . "',"; $q .= "mdate='$timestamp' "; $q .= "WHERE ship_method_id='" . $d["ship_method_id"][$key] . "' "; $q .= "AND vendor_id='" . $ps_vendor_id . "'"; $db->query($q); } } else { $q = "UPDATE ISshipping SET "; $q .= "ship_carrier_id='" . $d["ship_carrier_id"] . "',"; $q .= "ship_carrier_code='" . $d["ship_carrier_code"] . "',"; $q .= "ship_carrier_name='" . $d["ship_carrier_name"] . "',"; $q .= "ship_method_code='" . $d["ship_method_code"] . "',"; $q .= "ship_method_name='" . $d["ship_method_name"] . "',"; $q .= "ship_publish='" . $d["ship_publish"] . "',"; $q .= "ship_handling_charge='" . $d["ship_handling_charge"] . "',"; $q .= "ship_handling_type='" . $d["ship_handling_type"] . "',"; $q .= "ship_lead_time='" . $d["ship_lead_time"] . "',"; $q .= "ship_msg_header='" . $d["ship_msg_header"] . "',"; $q .= "ship_msg_footer='" . $d["ship_msg_footer"] . "',"; $q .= "mdate='$timestamp' "; $q .= "WHERE ship_method_id='" . $d["ship_method_id"] . "' "; $q .= "AND vendor_id='" . $ps_vendor_id . "'"; $db->query($q); } return true; } /************************************************************************** ** name: get_weight() ** created by: Matt Oberpriller ** description: Calculate product weight in ounces ** parameters: product_id ** returns: weight in ounces ***************************************************************************/ function get_weight($pid) { global $ps_vendor_id; $db = new ps_DB; $q = "SELECT * FROM product "; $q .= "WHERE product_id='$pid' "; $q .= "AND vendor_id='$ps_vendor_id'"; $db->query($q); $db->next_record(); if ($db->f("product_weight") == 0 && $db->f("product_parent_id")) { $q = "SELECT * from product WHERE product_id="; $q .= $db->f("product_parent_id"); $db->query($q); $db->next_record(); } if ($db->f("product_weight") > 0) { if (eregi("LB",$db->f("product_weight_uom")) || eregi("PO",$db->f("product_weight_uom"))) $weight = $db->f("product_weight") * 16; elseif (eregi("KG",$db->f("product_weight_uom")) || eregi("KILO",$db->f("product_weight_uom"))) $weight = $db->f("product_weight") * 35.27396194958041; elseif (eregi("G",$db->f("product_weight_uom"))) $weight = $db->f("product_weight") * 0.035273961949580414; elseif (eregi("OZ",$db->f("product_weight_uom")) || eregi("OU",$db->f("product_weight_uom"))) $weight = $db->f("product_weight"); else $this->error="Unknown weight UOM in product " . $db->f("product_sku"); } else { $this->error="Weight not specified for product " . $db->f("product_sku"); } if ($weight) return($weight); else return false; } /************************************************************************** ** name: validate() ** created by: Matt Oberpriller ** description: Validate quote retreival ** parameters: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -