Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Intershipper and Over Weight Shipments

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 09-27-2007, 05:36 PM
 
kacz kacz is offline
 

Member
  
Join Date: Aug 2007
Posts: 11
 

Default Intershipper and Over Weight Shipments

I had a problem getting a foreeach() error in the intershipper module whenever a cart had items that totaled greater than 150 lbs.

The problem was similar to the one discussed in this thread --> http://forum.x-cart.com/showthread.php?t=11659

But the solution was different because of my use of the intershipper module.

Here are the basics <<new note. I received a patch from X-Cart on this issue, see below for patch and comments>>:

Intershipper will only quote single-box shipments through x-cart.

The code to interact with intershipper is contained in /shipping/intershipper.php.


There is a hard-coded value to set the package count $post[] = "TotalPackages=1";

So, when using intershipper AND having something weigh more than 150 pounds, the user gets an error in line 186 of the intershipper code.

Here's the work around / edits for the shipping/intershipper.php module. It's been tested with UPS and FedEx enabled. (all code is in red)

1. Add these lines before you start building the $post[] array. This sets up a loop that divides the shipment into 150lbs increments (the last run through the loop gets anything left over after all the 150lbs boxes have been checked).


$calcweight = $pounds;

if ($pounds>150) $currentweight=150;
else $currentweight=$pounds;
$i=0;
while ($currentweight > 0)
{

2. Then, modify the line that sets Weight1 as follows:


$post[] = "Weight1=$currentweight";

3. Add these lines to the point just before all of this -> if ($debug=="Y") { print "<table width=800><tr><td width=800>"; <-


This sets a new array to hold the shipping rates from each individual request made to intershipper (because we are requesting more than 1 box, we make multiple requests) it then unsets the rates so they can be gotten again for the next run then it resets the remaining weight and unsets the post that is sent to intershipper so that post can be reset on the next request
$holdingrates[] = $intershipper_rates;
unset($intershipper_rates);
$calcweight=$calcweight-$currentweight;
if ($calcweight>150) $currentweight=150;
else $currentweight = $calcweight;
unset ($post);
} // closes the while loop described above


4. Then add these lines to the bottom of the file. They replace the return $intershipper_rates; Essentially what this does is explodes the array of intershipper_rates you collected above, then totals all of the shipping method rates and then creates a new $i_rates[] array that replaces the original intershipper_rates array. There may be better ways to handle that array, but I didn't think of them...



foreach ($holdingrates as $holdingrate) {
foreach ($holdingrate as $x){
$r[$x['methodid']]=$r[$x['methodid']]+$x['rate'];
}
}
foreach (array_keys($r) as $name){
$i_rates[]= array("methodid"=>$name, "rate"=>$r[$name]);
}

// return $intershipper_rates;
return $i_rates;
}


5. Finally, comment these lines out to get rid of the shipping_cache functionality. That got in the way while I was testing the front-end cart. It seems that if a cart has already calculated shipping, the cache function doesn't do a new calculation if things change. It just reads from teh shipping_cache table. That seemed to be pretty screwy, so I just turned off the cache as bellow:

// if ($debug != "Y") func_save_shipping_result_to_cache($md5_request, $intershipper_rates);


// $md5_request = md5($query);
// if ((func_is_shipping_result_in_cache($md5_request)) && ($debug != "Y")){
// return func_get_shipping_result_from_cache($md5_request);
// }

Ok, X-Cart support sent a patch for the intershipper.php file. The patch was intended to upgrade version
1.54.2.5 of the file. I am running version 1.54.24. That aside, I did apply the patch (here are the salient elements):

- if (empty($pkginfo['#']) || !is_array($pkginfo['#']))
+ if (empty($pkginfo['#']) || !is_array($pkginfo['#']) || empty($pkginfo['#']['QUOTE']))
continue;

As you can see, it adds a check to see whether Intershipper sent any rates back. This certainly removed the foreach() error at line 186 (over weight items), but did not really fix the underlying problem because when X-Cart does not get any rates returned from Intershipper, no rates are displayed and the user is asked to select any rate you may have set up that is not "auto-quoted". In my case, this meant that the user could elect to use their own shipper and request a pickup. Not exactly what I had in mind when I started this saga. Therefore, I reinstalled my modification. I did keep the extra check highlighted in red above as I think this is a good way to gracefully deal with the fact that intershipper may be unavailable or something went wrong with the return strings. It seems to work just fine...
__________________
X-Cart Pro - 4.1.8
X-Cart Pro - 4.1.9
Custom Mods and Skinning
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:05 PM.

   

 
X-Cart forums © 2001-2020