View Single Post
  #20  
Old 09-24-2005, 10:05 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default

Quote:
Originally Posted by nick1628
I was thinking of extending this even further and having it add them into one box up until 150 pounds and then start a new box, manipulating them to get the best combo so you'd have the least number of boxes. But I'm busy right now with a few projects and my real job so I just don't have time...one of these days though it will happen.
I ran into this same problem with FedEx. I'm posting this here in case it helps someone with UPS and because I didn't find any other posts related to this for FedEx.

A store owner has some products that individually fit into 53 lb packages. If someone orders 2 of them, the total weight is 106 lbs. This exceeds the FedEx Home Deliver limit of 70 lbs. If you haven't set Weight Limit for Home Delivery then the cart will only give you the rate up to 70 lbs (at least it appears that way). If you set the Weight Limit for Home Deliver to 70 lbs (like you probably should) then FedEx Home Deliver no longer appears as a shipping method for the order since the total weight is 106 lbs.

We changed shipping/mod_FEDEX.php to break the shipping into 53 lb (max) chunks then add up the chunks, giving a total shipping amount. Here are the changes that accomplished this.

In function get_rate, find:
PHP Code:
$row func_query_first("SELECT * FROM $sql_tbl[fedex_rates] WHERE r_meth_id = '".$method_id."' AND r_zone = '".$zone."' AND r_weight <= ".$weight." ORDER BY r_rate DESC LIMIT 1"); 
replace with:
PHP Code:
error_log("",0);
    
error_log("FedEx $method ($method_id), zone $zone",0);
    
$maxwt 53;        # max lbs per box
    
$rate 0;          # default rate value
    
$weight_orig $weight# remember original weight
    
$pkgcount 0;      # number of packages
    
while ($weight 0) {
        
$pkgcount++;
        if (
$weight $maxwt) {
            
$weight_rem $weight $maxwt;
            
$weight $maxwt;
            
$row func_query_first("SELECT * FROM $sql_tbl[fedex_rates] WHERE r_meth_id = '".$method_id."' AND r_zone = '".$zone."' AND r_weight <= ".$weight." ORDER BY r_rate DESC LIMIT 1");
            if (
$row) {
                
$this_rate $row[r_rate];
                
error_log("$weight lbs = $this_rate",0);
                
$rate += $this_rate;
            }
            
$weight $weight_rem;
        } else {
            
$row func_query_first("SELECT * FROM $sql_tbl[fedex_rates] WHERE r_meth_id = '".$method_id."' AND r_zone = '".$zone."' AND r_weight <= ".$weight." ORDER BY r_rate DESC LIMIT 1");
            if (
$row) {
                
$this_rate $row[r_rate];
                
error_log("$weight lbs = $this_rate",0);
                
$rate += $this_rate;
            }
            
$weight 0;
        }
     }
    
$weight $weight_orig
find:
PHP Code:
if ($row) {
        
# exact weight match
        
return $row["r_rate"];
    } 
replace with:
PHP Code:
if ($rate 0) {
        
error_log("RATE $rate",0);
        
# exact weight match
        
return array($rate$pkgcount);
    } 
Use the package count ($pkgcount) to multiply the Home Delivery surchage. In function AddMethods find:
PHP Code:
$rate get_rate($weight$method['name'], $zone); 
replace with:
PHP Code:
list($rate,$pkgcount) = get_rate($weight$method['name'], $zone); 
Also, find:
PHP Code:
$rate $rate $fuel_addon $method['addon']; 
replace with:
PHP Code:
$addon $method[addon] * $pkgcount;
$rate $rate $fuel_addon $addon;
error_log("packages $pkgcount, fuel $fuel_addon, method $addon = $rate",0); 
As you can see, I like to log stuff so I can see what the cart is doing. Here is a sample of the log after the above changes:
Code:
[25-Sep-2005 15:43:05] FedEx Ground (43), zone 2 [25-Sep-2005 15:43:05] 53 lbs = 10.08 [25-Sep-2005 15:43:05] 53 lbs = 10.08 [25-Sep-2005 15:43:05] RATE 20.16 [25-Sep-2005 15:43:05] packages 2, fuel 0.6, method 0 = 20.76 [25-Sep-2005 15:43:05] [25-Sep-2005 15:43:05] FedEx Home Delivery (44), zone 2 [25-Sep-2005 15:43:05] 53 lbs = 10.08 [25-Sep-2005 15:43:05] 53 lbs = 10.08 [25-Sep-2005 15:43:05] RATE 20.16 [25-Sep-2005 15:43:05] packages 2, fuel 0.6, method 2.9 = 26.56
The modifications above don't mess with how rates are obtained. It just breaks the total weight into smaller chunks. The store owner doesn't ship 106 lb packages, but 53 lb packages, so this works for them. Your requirements may be different.

Additionally, we found that the rates were not correct in some instances. This was tracked down to function get_zone. It appears that the destination zip code may be in multiple zones. The closer zone is probably the one you should be using so we found:
PHP Code:
$row func_query_first("SELECT * FROM $sql_tbl[fedex_zips] WHERE (zip_first<='$zp3') AND (IF(zip_last='', '$zp3'=zip_last, '$zp3'<=zip_last)) AND zip_meth='$methid'"); 
and changed to:
PHP Code:
$row func_query_first("SELECT * FROM $sql_tbl[fedex_zips] WHERE (zip_first<='$zp3') AND (IF(zip_last='', '$zp3'=zip_last, '$zp3'<=zip_last)) AND zip_meth='$methid' order by zip_zone asc"); 
This change says I want the lowest number zone if there are more than one. This coincided with fedex.com's rate finder. fedex.com was saying the zone was 2, in my test, while the cart was giving me the higher rates in zone 6. The database was returning two rows (zone 2 and zone 6) but zone 6 was coming up first. Only the first one to come back is what the original code uses. This change fixes that.

This was done with 4.0.11 but I could find nothing in the changelog nor code changes to this section that would indicate that it is any different up to 4.0.16.

This should be tested and someone should please post a correction if any of this information is inaccurate. I am not a shipping expert.

update - I found that FedEx Home Delivery surcharge is applied per package. I added a package counter ($pkgcounter) to the get_rate function, get_rate now returns the rate and number of packages, and AddMethods now uses the returned package count to multiply the FedEx Home Delivery.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote