Welcome Guest, Not a member yet? Register   Sign In
Help! UPS Calculator
#1

[eluser]beaudierman[/eluser]
I am using a slightly modified version of the UPS Rate Tool found on the wiki:
http://codeigniter.com/wiki/UPS_Rate_Tool

I am trying to first ping UPS for the ground rate(03) and echo that out, then ping & echo all other UPS rates. This is if somebody buys regular items + free shipping items I can quote them ground sans the weight of the free shipping and then the other rates including free shipping weight.

The problem is that after the first UPS quote is echo'd out, the script dies and doesn't load anything else in my controller. I have error reporting turned on and it shows no PHP errors or notices at all.

My code:

Code:
$ups_rates = $this->ups_rate->get_rate($destination_zip, '03', $number_of_packages, $weight_of_packages, $residential);
  foreach($ups_rates as $value) {
   echo '<option value="' . $value['Rate'] . '">' . $value['ServiceName'] . ' - $' . $value['Rate'] . '</option>';
  }
$ups_rates = $this->ups_rate->get_rate($destination_zip, '', $number_of_packages, $weight_of_packages, $residential);
  foreach($ups_rates as $value) {
   echo '<option value="' . $value['Rate'] . '">' . $value['ServiceName'] . ' - $' . $value['Rate'] . '</option>';
  }

I'm coming from a custom built platform and to accomplish this I simply instantiate the UPS class a 2nd time and it works fine. I tried to load the library twice with different names(http://ellislab.com/codeigniter/user-gui...oader.html) and get the same problem. I can comment out either of them and the entire controller loads fine. Any ideas?
#2

[eluser]beaudierman[/eluser]
SOLVED!

I found that the function the author wrote to determine state based on zip code to be the cause of this issue. I removed the code(found below) and manually input the TO / FROM states and it works perfect.

Code:
function getstatefromzip($zip5)
        {
            $allstates = array('AK9950099929', 'AL3500036999', 'AR7160072999', 'AR7550275505', 'AZ8500086599', 'CA9000096199', 'CO8000081699', 'CT0600006999', 'DC2000020099', 'DC2020020599', 'DE1970019999', 'FL3200033999', 'FL3410034999', 'GA3000031999', 'HI9670096798', 'HI9680096899', 'IA5000052999', 'ID8320083899', 'IL6000062999', 'IN4600047999', 'KS6600067999', 'KY4000042799', 'KY4527545275', 'LA7000071499', 'LA7174971749', 'MA0100002799', 'MD2033120331', 'MD2060021999', 'ME0380103801', 'ME0380403804', 'ME0390004999', 'MI4800049999', 'MN5500056799', 'MO6300065899', 'MS3860039799', 'MT5900059999', 'NC2700028999', 'ND5800058899', 'NE6800069399', 'NH0300003803', 'NH0380903899', 'NJ0700008999', 'NM8700088499', 'NV8900089899', 'NY0040000599', 'NY0639006390', 'NY0900014999', 'OH4300045999', 'OK7300073199', 'OK7340074999', 'OR9700097999', 'PA1500019699', 'RI0280002999', 'RI0637906379', 'SC2900029999', 'SD5700057799', 'TN3700038599', 'TN7239572395', 'TX7330073399', 'TX7394973949', 'TX7500079999', 'TX8850188599', 'UT8400084799', 'VA2010520199', 'VA2030120301', 'VA2037020370', 'VA2200024699', 'VT0500005999', 'WA9800099499', 'WI4993649936', 'WI5300054999', 'WV2470026899', 'WY8200083199');
            
            foreach ($allstates as $ziprange)
            {
                
                if (($zip5 >= substr($ziprange, 2, 5)) && ($zip5 <= substr($ziprange, 7, 5)))
                {
                    return substr($ziprange, 0, 2);
                }
            }
            
            return;
        }
#3

[eluser]skunkbad[/eluser]
Hey, good job. I don't think the author really knew what he was doing. You might check out the UPS shipping rate library as I modified it in Community Cart, which is on bitbucket:

https://bitbucket.org/skunkbad/community-cart
#4

[eluser]beaudierman[/eluser]
Thanks for the suggestion, looks like you have made some definite improvements to the library!




Theme © iAndrew 2016 - Forum software by © MyBB