Note that there are some explanatory texts on larger screens.

plurals
  1. POUPS freight calculator
    primarykey
    data
    text
    <p>I have managed to get a UPS Shipping calculator working in PHP. I now found out that the standard shipping from UPS is capped at 150lbs. For anything over 150lbs, I need to ship via freight.</p> <p>Has anyone ever coded a Freight Calculator with UPS? The calculator I wrote for anything under 150lbs does not require a UPS account. I was hoping to do the same for the freight calculator, however, I am unable to find any information on how to accomplish this.</p> <p>Any help will be greatly appreciated.</p> <p><strong>EDIT</strong></p> <p>As per request by Nicolaesse, I have added some code snippets that I wrote in 2009 to solve my problem. </p> <p>Demo can be seen here: <a href="http://cart.jgallant.com" rel="nofollow noreferrer">http://cart.jgallant.com</a> (Add product to cart, checkout, and enter zipcode for shipping estimate)</p> <p>Core UPS class:</p> <pre><code>&lt;?php class ups { function getMethod() { $method= array( '1DA' =&gt; 'Next Day Air', '2DA' =&gt; '2nd Day Air', '3DS' =&gt; '3 Day Select', 'GND' =&gt; 'Ground', ); return $method; } function get_item_shipping($weight, $zipcode) { unset($_SESSION['zipcode_error']); if($weight &gt; 150) { $_SESSION['zipcode_error'] = "A cart item requires freight."; } if (!isset($_SESSION['zipcode_error'])) { $services = $this-&gt;getMethod(); $ch = curl_init(); foreach ($services as $key =&gt; $service) { $Url = join("&amp;", array("http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes", "10_action=3", "13_product=".$key, "14_origCountry=US", "15_origPostal=90210", "19_destPostal=" . $zipcode, "22_destCountry=US", "23_weight=" . $weight, "47_rate_chart=Regular+Daily+Pickup", "48_container=00", "49_residential=2", "billToUPS=no") ); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $Results[]=curl_exec($ch); } curl_close($ch); $pre = ""; $shipping_list = array(); foreach($Results as $result) { $result = explode("%", $result); if ($services[$result[1]] != ''){ if ((($result[1]=='XPR') &amp;&amp; ($pre == 'XPR')) || (($result[1]=='XDM') &amp;&amp; ($pre == 'XDM')) || (($result[1]=='1DP') &amp;&amp; ($pre == '1DP')) || (($result[1]=='1DM') &amp;&amp; ($pre == '1DM')) || (($result[1]=='1DA') &amp;&amp; ($pre == '1DA')) || (($result[1]=='2DA') &amp;&amp; ($pre == '2DA'))) $shipping_list += array($services[$result[1]."L"] =&gt; $result[8]); else if (($result[1]=='GND') &amp;&amp; ($pre == 'GND')) $shipping_list += array($services[$result[1]."RES"] =&gt; $result[8]); else $shipping_list += array($services[$result[1]] =&gt; $result[8]); $pre = $result[1]; } } } $shipping_list = array_reverse($shipping_list); return $shipping_list; } } ?&gt; </code></pre> <p>WEIGHT Calculator Helper:</p> <pre><code>&lt;?php //UPS calculator - Divides packages into 150lbs max packages, and requests multiple quotes if needed //Returns a sum of all the quotes added together. private function calculate_per_item_shipping() { $currWeight = 0; $packageCount = 0; //Loop thru cart items - adding weights to packages foreach($this-&gt;get_contents() as $item) { for ($i = 0; $i &lt; $item["qty"]; $i++) { $itemWeight = $item["weight"]; if ($itemWeight &gt; 150) { // A single item cannot be more than 150lbs $_SESSION['zipcode_error'] = $item['name'] . " weighs more than 150lbs."; return false; } else { $currWeight += $itemWeight; //Add item weight to active package if ($currWeight &gt; 150) { //Max weight reached for active package $currWeight -= $itemWeight; //Remove item from current package, too heavy $loopPack = 0; $itemUsed = false; //Check if an existing package can take the item while (($loopPack != $packageCount) or ($itemUsed = false)) { if ($packages[$loopPack] + $itemWeight &lt; 150) { $packages[$loopPack] += $itemWeight; $itemUsed = true; } $loopPack++; } //if the item didn't fit in an existing package, create a new package for it if ($itemUsed == false) { $packageCount++; $packages[$packageCount-1] = $currWeight; $currWeight = $item["weight"]; //Put unused item back in active package } } } } } //The remainder becomes a package $packageCount++; $packages[$packageCount-1] = $currWeight; for ($i = 0; $i &lt; $packageCount; $i++) { $temptotal = $this-&gt;calc_package_shipping($packages[$i]); if ($temptotal['Ground'] != 0) { $total['Ground'] += $temptotal['Ground']; } if ($temptotal['3 Day Select'] != 0) { $total['3 Day Select'] += $temptotal['3 Day Select']; } if ($temptotal['2nd Day Air'] != 0) { $total['2nd Day Air'] += $temptotal['2nd Day Air']; } if ($temptotal['Next Day Air Saver'] != 0) { $total['Next Day Air Saver'] += $temptotal['Next Day Air Saver']; } if ($temptotal['Next Day Air Early AM'] != 0) { $total['Next Day Air Early AM'] += $temptotal['Next Day Air Early AM']; } if ($temptotal['Next Day Air'] != 0) { $total['Next Day Air'] += $temptotal['Next Day Air']; } } $this-&gt;selectedQuoteAmount = $total['Ground']; return $total; } private function calc_package_shipping($weight) { $ups = new ups(); $shipping = $ups-&gt;get_item_shipping($weight, $this-&gt;zipcode); return $shipping; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload