Jump to content
torinwalker

New UPS XML Shipping Module available

Recommended Posts

Jan-

 

right now I've got

 

 // BOF limit choices
			if (!exclude_choices($type)) continue;
			//bof limit results based on ground transit time
			 if ($this->servicesTimeintransit['UPS Ground']['days'] == "1") {
if (exclude_choices('Next Day Air')) continue;
}
//eof ground limit
			// EOF limit choices

 

but this doesn't function in the way that I'm looing for.

 

How do I write this as a command to tell the module to not display a service in a given situation?


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites

Stew,

 

I missed your post, perhaps you already solved it. Otherwise my suggestion would be to use:

 // BOF limit choices
			if (!exclude_choices($type)) continue;
			//bof limit results based on ground transit time
			 if ($this->servicesTimeintransit['UPS Ground']['days'] == "1") {
if (strstr($type, 'Next Day Air')) continue;
if (strstr($type, '2nd Day Air')) continue;
}
//eof ground limit
// EOF limit choices

Share this post


Link to post
Share on other sites
Stew,

 

I missed your post, perhaps you already solved it. Otherwise my suggestion would be to use:

 // BOF limit choices
			if (!exclude_choices($type)) continue;
			//bof limit results based on ground transit time
			 if ($this->servicesTimeintransit['UPS Ground']['days'] == "1") {
if (strstr($type, 'Next Day Air')) continue;
if (strstr($type, '2nd Day Air')) continue;
}
//eof ground limit
// EOF limit choices

 

OH WOW- this is awesome!

 

OK-

 

I've got this for the whole thing:

 

// BOF limit choices
if (!exclude_choices($type, $vendors_id)) continue;
//bof limit results based on ground transit time
if ($this->servicesTimeintransit['UPS Ground']['days'] == "1") {
if (strstr($type, 'Next Day Air')) continue;
if (strstr($type, '2nd Day Air')) continue;
}
elseif ($this->servicesTimeintransit['UPS Ground']['days'] == "2") {
if (strstr($type, '2nd Day Air')) continue;
}
elseif ($this->servicesTimeintransit['UPS Ground']['days'] > "2") {
if (strstr($type, 'Ground')) continue;
}
//eof ground limit
// EOF limit choices

 

and it is testing perfectly! If you can think of any reason why this might not work (for instance, does the XML module sometimes not return Time in Transit data but still return rates? If so then it should be written slightly differently, to default to 2nd Day Air and Next Day Air in those cases), please let me know.

 

In any case, THANK YOU!!!

 

Cheers,

Stew

Permanent member of the JanZ fan club


Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Share this post


Link to post
Share on other sites

I am having trouble setting this up.

 

First I was getting the "TABLE_PACKAGING" error, I did the fix from this thread and got to the cURL error on line 644, did the recommended fix again and now I actually get to the order page!

 

Now there is an even larger problem, first i get the 10002 error on UPS, which the fix for is to change the "define('DIMENSIONS_SUPPORTED', 0);" from 1 to 0. I did that to fix a different problem, and I cant seem to find a fix for the 10002 other than that.

 

Second problem is that my USPS module is now not working either. The USPS error reads

"An error occured with the USPS shipping calculations.

If you prefer to use USPS as your shipping method, please contact the store owner."

Which is of little to no help. If anyone has any suggestions I would be very grateful.

Share this post


Link to post
Share on other sites
Now there is an even larger problem, first i get the 10002 error on UPS, which the fix for is to change the "define('DIMENSIONS_SUPPORTED', 0);" from 1 to 0. I did that to fix a different problem, and I cant seem to find a fix for the 10002 other than that.

 

Second problem is that my USPS module is now not working either. The USPS error reads

"An error occured with the USPS shipping calculations.

If you prefer to use USPS as your shipping method, please contact the store owner."

Which is of little to no help. If anyone has any suggestions I would be very grateful.

True, the "An error occurred.." is not helpful, but better that than to output an error message that scares your customers.

 

Better get the logging of the request to UPS and the answer done. That should give more information (a description of what 10002 is and perhaps even why for example).

Share this post


Link to post
Share on other sites

Logging found the problem, thank you. Now for USPS, but that is a different thread and I think I found the problem, which is that you have to email them to switch your account from test to production.

Share this post


Link to post
Share on other sites

Hey Everyone,

 

I'm going to try and tackle this packaging/packaging dimentions problem but I'm going to need some help with people alittle more familar with this contrib. When I look at the catalog\includes\modules\shipping\upsxml.php file I can see the "simple algorithm" and alot of it makes sense in it's operation. I'm feeling though that the algorithm is missing a key variable that for lack of a better word "order volume". "order volume" would be to me the total volume of the order and I'm not seeing where it reads in the package data individually and I certianly don't see where it adds those packages up to make one big box. So if some one could point me in that direction where the upsxml.php file brings in the order package data that would be a great help.

 

Thanks,

 

Aaron

Share this post


Link to post
Share on other sites

I just installed this contrib and I have everything working for the most part, but I have one quick question.

 

Does this module automatically attempt to figure out how much the box weighs, and if so, how does it do that calculation?

 

When I put several items in my Cart, let's say three items, 2 x .3lbs, and one at .1lbs, that should be a total of .7lbs, however, when I go to the checkout, it calculates the shipping and lists one package @ 3.7 lbs.

 

I'm just curious how it calculates the 3 lbs and if that every changes.

 

Thanks!

Share this post


Link to post
Share on other sites

To Everyone that has been having problems with this contrib putting every item sold in an individual box/package,

 

After reviewing the code late last night I found one area of the code that is very misleading and should be renamed in future verisons of this contrib. It all revolves around the "Ready to Ship" check box in the admin section of the catalog.

 

If most people were like me you thought the "Ready to Ship" check box meant that this item was in stock and ready to ship. After reveiwing the code I found that this was not true. In this contribution "Ready to Ship" means that the item is in its own box and will be shipped as an individual package.

 

So with that being the case if all your items in your catalog section of Admin are checked "Ready to Ship" then the UPS XML will treat those items as individual packages. This will cause your UPS shipping quotes to be higher and potentially lose customers and orders (as I have).

 

So last night I tested out on a few items if I unchecked the "Ready to Ship" checkbox in the catalog admin section to see what it would do. I found that the contrib would treat those items as needing to be packaged AND it would find the smallest box available to pack all those items in. The UPS shipping quote was then ALOT closer.

 

I hope this info helps alot of people out. The strategy I'm going to go with is if the item size is less than half of the maximum UPS box size then I will deselect the "Ready to Ship" check box and make the contrib pack those items in one box. On items over half the maximum UPS box size I will still leave the "Ready to Ship" box checked so the contrib knows to ship this item(s) in their own boxes and hopefully avoid huge box sizes that would be hard to find.

 

If any one has any further questions feel free to post in this fourm (I check it from time to time) or PM me.

 

THanks,

 

Aaron

Share this post


Link to post
Share on other sites

JanZ,

 

Thank you very much - the checkout process works perfectly now. I should have figured out this fix quicker, it was just that basic option, you nailed it.

 

I do have another issue that may be more of a challange for you, if you are game.

 

Since this site is selling remanufactured transmissions the packaging will be bulk "hundredweight" from UPS.

From what I have read so far I think I know the following:

 

a. No one has contributed a module for hundredweight packaging, although a couple people have asked about it

b. The UPS xml contrib basically connects to the UPS SSL server and gets the current shipping rates.

 

 

It seems like we should be able to add a hunderedweight option pretty easily, by duplicating the handshake that takes place with the SSL server with the current packaging options but by changing one of the codes from, for example, "UPS Pak 04" to "Hundredweight 05" (or whatever the code is - the UPS helpdesk hasn't replied back yet =/

 

But I may be wrong, adding a new package type may be way harder than I think. I really just need to see if I am thinking along the right lines. The code below is from upsxml.php...

 

 

// Available package types

$this->package_types = array(

'Unknown' => '00',

'UPS Letter' => '01',

'Customer Package' => '02',

'UPS Tube' => '03',

'UPS Pak' => '04',

'UPS Express Box' => '21',

'UPS 25kg Box' => '24',

'UPS 10kg Box' => '25'

);

 

 

And before I jump into trying to change (break) anything I had a few questions about this process to make sure I start off in the right direction:

 

 

1. Is it possible to add some code to upsxml.php that will interact with UPS secure server that will get the hundredweight info in basically the same way that it gets the info for the other package types? I am not so much a programmer but can grab some help if the hundredweight info would interact in the same manner as the other packaging options..

 

2. I understand there is a packaging contrib but Janz, I know you were saying there were a lot of problems with it, so I didn't install it.. do you know if hundredweight shipping is an option on there? Does the packaging contrib just attempt to offer every type of shipping option possible or is it more about trying to automatically calculate volume and then picking the best package based on that? It doesn't seem like the packaging contrib has much documentation about what it is useful for so i am not sure whether to go that route.

 

3. How many documents would need to be modified to make the changes to add hundredweight shipping? Is it just upsxml.php or are there many documents that would need modified?

 

 

Thanks a lot for all the help so far, and in advance for any help on this step,

 

Thank you,

Dan Linehan.

Share this post


Link to post
Share on other sites

Tony,

Does this module automatically attempt to figure out how much the box weighs, and if so, how does it do that calculation?

 

When I put several items in my Cart, let's say three items, 2 x .3lbs, and one at .1lbs, that should be a total of .7lbs, however, when I go to the checkout, it calculates the shipping and lists one package @ 3.7 lbs.

 

I'm just curious how it calculates the 3 lbs and if that every changes.

This is the same for all shipping modules. It is well explained in the Knowledge Base.

Share this post


Link to post
Share on other sites

Dan,

It seems like we should be able to add a hunderedweight option pretty easily, by duplicating the handshake that takes place with the SSL server with the current packaging options but by changing one of the codes from, for example, "UPS Pak 04" to "Hundredweight 05" (or whatever the code is - the UPS helpdesk hasn't replied back yet
Reading up on what UPS Hundredweight is I get the impression it is more like a separate service so that it would need it's own shipping contribution. I can't get to the info for developers yet, so I'm in the dark on that.

 

And before I jump into trying to change (break) anything I had a few questions about this process to make sure I start off in the right direction:

1. Is it possible to add some code to upsxml.php that will interact with UPS secure server that will get the hundredweight info in basically the same way that it gets the info for the other package types?

No clue yet.

 

do you know if hundredweight shipping is an option on there? Does the packaging contrib just attempt to offer every type of shipping option possible or is it more about trying to automatically calculate volume and then picking the best package based on that? It doesn't seem like the packaging contrib has much documentation about what it is useful for so i am not sure whether to go that route.
What it tries to do is come up with a more accurate quote by trying to calculate with the dimensions and weight of your products, and your boxes how many boxes the shipment will be and of what size. Unfortunately, the algorithm is not working properly (the loops it is supposed to make are not the one the code actually makes) and it is so bad that it will actually lose packages to avoid getting into an indefinite loop.

 

The upsxml I use was modified by me to handle aerosol cans (hazmat shipment) so I had to fix that. Of course it cannot be used without modification for UPSXML, but I haven't had the time to look into it.

 

3. How many documents would need to be modified to make the changes to add hundredweight shipping? Is it just upsxml.php or are there many documents that would need modified?
No idea. Since they have separate software for it, it might need a separate shipping module.

Share this post


Link to post
Share on other sites

I just installed this contrib with dimensional support and think it works great, so thanks for all the work. I am however having a problem with the total shipment weight.

 

It seems that whenever a shipment is more than one package the Total weight of the shipment is less than it should be.

 

Example: I have 12, 18 lb.s items in a shipment... total weight 216 lbs.

 

This shipment is in Three pacakges, each package (box) I put a weight of 1 lb. So total with packaging should be 219 lbs.

 

The rate quoted is for a 165 lb. shipment... it looks like for each package it take the weight of one item off.

 

216 - (18*3) + 3 = 165

 

Any help would be Appreciated.

 

Thanks,

 

Tim

Share this post


Link to post
Share on other sites
Tony,

This is the same for all shipping modules. It is well explained in the Knowledge Base.

 

Thanks for the reply and the info. I can't believe I missed that, I hate asking simple questions with the answer in front of me.

 

I did however, take the overly complex task of looking through all the php code to find it. ;)

 

Thanks again!

Share this post


Link to post
Share on other sites

Hi,

 

This question maybe answered somewhere in the earlier 34 pages, blink:

 

I already have the Canada Post with dimensions contribution installed and working, how much of the UPS UPS XML rates and services contribution do I need to install?

 

According to the Canada Post Contibution notes it just a 10 minute upgrade to add the UPS Rates and Services functionality.

 

Do I need to install everying in the UPS Rates and Services (including the optional dimensions file mods and sql update) if I already have the Canada Post with dimensions contributions installed?

 

Once again, sorry if this has already been answered...

 

Mark

Share this post


Link to post
Share on other sites

Mark,

I already have the Canada Post with dimensions contribution installed and working, how much of the UPS XML rates and services contribution do I need to install?

 

According to the Canada Post Contibution notes it just a 10 minute upgrade to add the UPS Rates and Services functionality.

 

Do I need to install everying in the UPS Rates and Services (including the optional dimensions file mods and sql update) if I already have the Canada Post with dimensions contributions installed?

I'm not really familiar with the Canada Post dimensions contributions but there are references to it in the docs. If the Canada Post mod adds length, width, height, and "ready-to-ship" to the table products than you would be fine. The UPSXML dimensions mod also adds a table for packaging (the boxes you use to ship stuff) and a page in the admin for entering data about the packages but you can use UPS XML without it.

 

Now at the moment the packing algorithm in UPSXML is not OK, it occasionally loses packages to not get into a loop.

 

I have been working on it the past weekend (also on updating the services in the language file, there have been a few changes in the last years) and I believe I tackled that packages problem.

 

There will be more, little, changes to make it more foolproof and also the ability to only use the "ready-to-ship" option (so oversize articles can be quoted properly for) and not having to enter all the size data for all your articles (those will be "boxed" according to the standard osC algorithm).

 

I want to add a few more features (like being able to get the UPS errors mailed to the shop owner, so you can be aware of any problems before a customer takes the trouble to inform you) but it won't be too long for this new release is out.

 

I hope this answers your question.

 

P.S. From the UPS developer info I conclude that UPS XML rates will use the Hundredweight rates when applicable. That was an earlier question from Dan.

Share this post


Link to post
Share on other sites

JanZ,

 

I eagerly await your update to the Packaging algorithm. I have been fighting with it over the last week, trying to improve it, but to no avail. It is just so freaking broken in its current state. >_<

 

How soon do you think you'll have something ready to share with us? ;)

 

Thanks!

Share this post


Link to post
Share on other sites
I eagerly await your update to the Packaging algorithm. I have been fighting with it over the last week, trying to improve it, but to no avail. It is just so freaking broken in its current state. >_<

 

How soon do you think you'll have something ready to share with us? ;)

I still want to add some more sanity checks regarding the input and add more logging and email to be able to get aware of problems, but this is the code part that I changed and does not lose packages anymore.

 

This is one of the new things, dimensions support not as a define in the file, but as a setting in the admin. Also with an intermediate solution: getting oversized products separated from the rest (Ready-to-ship only) and not having to enter all the size data for all your products. This is in the top part:

	if (MODULE_SHIPPING_UPSXML_DIMENSIONS_SUPPORT == 'Ready-to-ship only') {
	$this->dimensions_support = 1;
} elseif (MODULE_SHIPPING_UPSXML_DIMENSIONS_SUPPORT == 'With product dimensions') {
	$this->dimensions_support = 2;
} else {
	$this->dimensions_support = 0;
}

This is the changed part in the function quote:

	// class methods
function quote($method = '') {
	global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes, $total_weight, $boxcount, $cart;
	// UPS purports that if the origin is left out, it defaults to the account's location. Yeah, right.
	$state = $order->delivery['state'];
	$zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_name = '" .  $order->delivery['state'] . "'");
	if (tep_db_num_rows($zone_query)) {
		$zone = tep_db_fetch_array($zone_query);
		$state = $zone['zone_code'];
	}
	$this->_upsOrigin(MODULE_SHIPPING_UPSXML_RATES_CITY, MODULE_SHIPPING_UPSXML_RATES_STATEPROV, MODULE_SHIPPING_UPSXML_RATES_COUNTRY, MODULE_SHIPPING_UPSXML_RATES_POSTALCODE);
	$this->_upsDest($order->delivery['city'], $state, $order->delivery['country']['iso_code_2'], $order->delivery['postcode']);
	$productsArray = $cart->get_products();

	if ($this->dimensions_support == '2') {
		// sort $productsArray according to ready-to-ship (first) and not-ready-to-ship (last)
		usort($productsArray, ready_to_shipCmp);
		// Use packing algoritm to return the number of boxes we'll ship
		$boxesToShip = $this->packProducts($productsArray);
		// Quote for the number of boxes
		for ($i = 0; $i < count($boxesToShip); $i++) {
			$this->_addItem($boxesToShip[$i]['length'], $boxesToShip[$i]['width'], $boxesToShip[$i]['height'], $boxesToShip[$i]['current_weight']);
			$totalWeight += $boxesToShip[$i]['current_weight'];
		}
		} elseif ($this->dimensions_support == '1') {
		$totalWeight = 0;
		$total_non_ready_to_ship_weight = 0;
		// sort $productsArray according to ready-to-ship (first) and not-ready-to-ship (last)
		usort($productsArray, ready_to_shipCmp);
	$non_ready_to_shipArray = array();
	// walk through the productsArray, separate the items ready-to-ship and add them to
	// the items (boxes) list, add the weight to the totalWeight
	// and add the other items to a separate array
		for ($i = 0; $i < count($productsArray); $i++) {
	if ($productsArray[$i]['ready_to_ship'] == '1') {
		for ($z = 0; $z < $productsArray[$i]['quantity']; $z++) {
			$this->_addItem($productsArray[$i]['length'], $productsArray[$i]['width'], $productsArray[$i]['height'], $productsArray[$i]['weight']);
	$totalWeight += $productsArray[$i]['weight'];
		} // end for ($z = 0; $z < $productsArray[$i]['quantity']; $z++)
		} // end if($productsArray['ready_to_ship'] == '1')
	else {
	  $non_ready_to_shipArray[] = $productsArray[$i];
	}
	} // end for ($i = 0; $i < count($productsArray); $i++)
	// Ready_to_ship items out of the way, now assess remaining weight of products

	for ($x = 0; $x < count($non_ready_to_shipArray); $x++) {
	$total_non_ready_to_ship_weight += ($non_ready_to_shipArray[$x]['weight'] * $non_ready_to_shipArray[$x]['quantity']);
	} // end for ($x = 0; count($non_ready_to_shipArray); $x++)

	if (tep_not_null($non_ready_to_shipArray)) {
	// adapted code from includes/classes/shipping.php
		$shipping_non_ready_to_ship_boxes = 1;
	$shipping_non_ready_to_ship_weight = $total_non_ready_to_ship_weight;
		   if (SHIPPING_BOX_WEIGHT >= $total_non_ready_to_ship_weight*SHIPPING_BOX_PADDING/100) {
			 $total_non_ready_to_ship_weight = $total_non_ready_to_ship_weight+SHIPPING_BOX_WEIGHT;
		   } else {
			 $total_non_ready_to_ship_weight += $total_non_ready_to_ship_weight*SHIPPING_BOX_PADDING/100;
		}
	if ($total_non_ready_to_ship_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
	  $shipping_non_ready_to_ship_boxes = ceil($total_non_ready_to_ship_weight/SHIPPING_MAX_WEIGHT);
	  $shipping_non_ready_to_ship_weight = round($total_non_ready_to_ship_weight/$shipping_non_ready_to_ship_boxes,1);
	}
// end adapted code from includes/classes/shipping.php
  // weight and number of boxes of non-read-to-ship is determined, now add them to the items list
	for ($y = 0; $y < $shipping_non_ready_to_ship_boxes; $y++) {
	$this->_addItem(0, 0, 0, $shipping_non_ready_to_ship_weight );
	$totalWeight += $shipping_non_ready_to_ship_weight;
	} // end for ($y = 0; $y < $shipping_non_ready_to_ship_boxes; $y++)
	} // end if (tep_not_null($non_ready_to_shipArray))
	} else {
		// The old method. Let osCommerce tell us how many boxes, plus the weight of each (or total? - might be sw/num boxes)
		$this->items_qty = 0; //reset quantities
		for ($i = 0; $i < $shipping_num_boxes; $i++) {
			$this->_addItem(0, 0, 0, $shipping_weight);
		}
	}

// BOF Time In Transit: comment out this section if you don't want/need to have
// expected delivery dates
// not relevant in this posting:
/*		if ($this->dimensions_support > 0) {
	$this->weight_for_timeintransit = round($totalWeight,1);
} else {
	$this->weight_for_timeintransit = round($shipping_num_boxes * $shipping_weight,1);
} */
// debug only:
/* echo '<pre>Packages and variables:<br />';
print_r($this);
echo '<br />';
exit;  */
	$this->servicesTimeintransit = $this->_upsGetTimeServices();
	if ($this->logfile) {
		error_log("------------------------------------------\n", 3, $this->logfile);
		error_log("Time in Transit: " . $this->timeintransit . "\n", 3, $this->logfile);
	}

// EOF Time In Transit

A new function added (used instead of the getPackages)

	function getPackagesByVol() {
	$packages = array();
	$packages_query = tep_db_query("select *, (package_length * package_width * package_length) as volume from " . TABLE_PACKAGING . " order by volume;");
	while ($package = tep_db_fetch_array($packages_query)) {
		$packages[] = array(
		'id' => $package['package_id'],
		'name' => $package['package_name'],
		'description' => $package['package_description'],
		'length' => $package['package_length'],
		'width' => $package['package_width'],
		'height' => $package['package_height'],
		'empty_weight' => $package['package_empty_weight'],
		'max_weight' => $package['package_max_weight'],
	'volume' => $package['volume'] );
	}
	return $packages;
}

Changes in the packaging part:

	function packProducts($productsArray) {
	// A very simple box packing algorithm. Given a list of packages, returns an array of boxes.
	// etcetera, etcetera, etcetera
	$definedPackages = $this->getPackagesByVol();
	$emptyBoxesArray = array();
	for ($i = 0; $i < count($definedPackages); $i++) {
		$definedBox = $definedPackages[$i];
		$definedBox['remaining_volume'] = $definedBox['volume'];
		$definedBox['current_weight'] = $definedBox['empty_weight'];
		$emptyBoxesArray[] = $definedBox;
	}
	$packedBoxesArray = array();
	$currentBox = NULL;
 $index_of_largest_box = count($emptyBoxesArray)-1;
	// Get the product array and expand multiple qty items.
	$productsRemaining = array();
	for ($i = 0; $i < count($productsArray); $i++) {
		$product = $productsArray[$i];
	if (!$this->fitsInBox($product, $emptyBoxesArray[$index_of_largest_box])) {
		$product['ready_to_ship'] = '1';
	}
		for ($j = 0; $j < $productsArray[$i]['quantity']; $j++) {
			$productsRemaining[] = $product;
		}
	}

// make sure the products that did not fit the largest box and are now set as ready-to-ship
// are out of the way as soon as possible (having a product that does not fit, will cause the program
// to get in a loop
usort($productsRemaining, ready_to_shipCmp);
	// Worst case, you'll need as many boxes as products ordered.
	while (count($productsRemaining)) {
		// Immediately set aside products that are already packed and ready.
		if ($productsRemaining[0]['ready_to_ship'] == '1') {
			$packedBoxesArray[] = array (
			'length' => $productsRemaining[0]['length'],
			'width' => $productsRemaining[0]['width'],
			'height' => $productsRemaining[0]['height'],
			'current_weight' => $productsRemaining[0]['weight']);
			$productsRemaining = array_slice($productsRemaining, 1);
			continue;
		}
		//Cycle through boxes, increasing box size if all doesn't fit.
		if (count($emptyBoxesArray) == 0) {
			print("ERROR: No boxes to ship unpackaged product<br />\n");
			break;
		}
		for ($b = 0; $b < count($emptyBoxesArray) && tep_not_null($productsRemaining); $b++) {
		$result = $this->fitProductsInBox($productsRemaining, $emptyBoxesArray[$b], $packedBoxesArray, $b, count($emptyBoxesArray) -1 );
		$packedBoxesArray = $result['packed_boxes'];
		$productsRemaining = $result['remaining'];
		}
	} // end while

	return $packedBoxesArray;
}

//*****************************
function fitsInBox($product, $box) {
	// in case by accident or by choice length, width or height is not set
	// we will estimate it by using a set density and the product['weight'] variable
	if ($product['length'] == 0 || $product['width'] == 0 || $product['height'] == 0) {
	  $density = 0.7;
	  if ($this->unit_length == 'CM') {
	  $product['length']=$product['width']=$product['height']= round(10*(pow($product['weight']/$density, 1/3)),1);
	  } else {
// non-metric: inches and pounds
		  $product['length']=$product['width']=$product['height']= round(pow($product['weight']*27.67/$density, 1/3),1);
	  }
	} 
	$productVolume = $product['length'] * $product['width'] * $product['height'];

// check if the diagonal of the product is not bigger than the diagonal of the box
if ( ( pow($product['length'],2) + pow($product['width'],2) + pow($product['height'],2) ) > ( pow($box['length'],2) + pow($box['width'],2) + pow($box['height'],2)) ) {
	return false;
} 

	if ($productVolume <= $box['remaining_volume']) {
		if ($box['max_weight'] == 0 || ($box['current_weight'] + $product['weight'] <= $box['max_weight'])) {
			return true;
		}
	}
	return false;
}

//***********************************
function putProductInBox($product, $box) {
	$productVolume = $product['length'] * $product['width'] * $product['height'];
	$box['remaining_volume'] -= $productVolume;
	$box['products'][] = $product;
	$box['current_weight'] += $product['weight'];
	return $box;
} 
//*********************	
 function fitProductsInBox($productsRemaining, $emptyBox, $packedBoxesArray, $box_no, $index_of_largest_box) { 
			$currentBox = $emptyBox;
			//Try to fit each product in box
			for ($p = 0; $p < count($productsRemaining); $p++) {
				if ($this->fitsInBox($productsRemaining[$p], $currentBox)) {
					//It fits. Put it in the box.
					$currentBox = $this->putProductInBox($productsRemaining[$p], $currentBox);
					if ($p == count($productsRemaining) - 1) {
						$packedBoxesArray[] = $currentBox;
						$productsRemaining = array_slice($productsRemaining, $p + 1);
						$result_array = array('remaining' => $productsRemaining, 'box_no' => $box_no, 'packed_boxes' => $packedBoxesArray);
						return ($result_array);
					}
				} else {
					if ($box_no == $index_of_largest_box) {
						//We're at the largest box already, and it's full. Keep what we've packed so far and get another box.
						$packedBoxesArray[] = $currentBox;
						$productsRemaining = array_slice($productsRemaining, $p);
						$result_array = array('remaining' => $productsRemaining, 'box_no' => $box_no, 'packed_boxes' => $packedBoxesArray);

						return ($result_array);
					}
					// Not all of them fit. Stop packing remaining products and try next box.
					$result_array = array('remaining' => $productsRemaining, 'box_no' => $box_no, 'packed_boxes' => $packedBoxesArray);
						return ($result_array);
				} // end else
		} // end for
	 } // end function

And then in the function _upsQuote this part is changed:

			$ratingServiceSelectionRequestPackageContent .=
		"	   <Package>\n".
		"		   <PackagingType>\n".
		"			   <Code>". $this->package_types[$this->package_type] ."</Code>\n".
		"		   </PackagingType>\n";
		if ($this->dimensions_support > 0 && ($this->item_length[$i] > 0 ) && ($this->item_width[$i] > 0 ) && ($this->item_height[$i] > 0)) {

			$ratingServiceSelectionRequestPackageContent .=
			"		   <Dimensions>\n".
			"			   <UnitOfMeasurement>\n".
			"				   <Code>". $this->unit_length ."</Code>\n".
			"			   </UnitOfMeasurement>\n".
			"			   <Length>". $this->item_length[$i] ."</Length>\n".
			"			   <Width>". $this->item_width[$i] ."</Width>\n".
			"			   <Height>". $this->item_height[$i] ."</Height>\n".
			"		   </Dimensions>\n";
		}

		$ratingServiceSelectionRequestPackageContent .=

UPS does not seem to have a problem with some packages being size defined and others not (this is the Ready-to-ship only solution).

Share this post


Link to post
Share on other sites

ok, thanks for the info...I'll try adding the UPS Rates and services without the Dimentions piece (adding dimensions seems to have a separate set of instructions).

 

Hopefully it will work with the Canada Post with dimensions contribution.

 

I'll watch for your UPS updates as well...

 

Thx again,

mark

Share this post


Link to post
Share on other sites

JanZ,

 

WoW, this is working much better for me so far, took me a while to figure out where exactly to put the

 

if (MODULE_SHIPPING_UPSXML_DIMENSIONS_SUPPORT == 'Ready-to-ship only') {
	  $this->dimensions_support = 1;
	} elseif (MODULE_SHIPPING_UPSXML_DIMENSIONS_SUPPORT == 'With product dimensions') {
	  $this->dimensions_support = 2;
	} else {
	  $this->dimensions_support = 0;
	}

part and then I added the appropriate configuration value to the db along with

 

tep_cfg_select_option(array('With product dimensions', 'Ready-to-ship only', 'No Dimensional Support'),

in the set_function field to add it to the admin page, that is working beautifully now.

 

One thing you missed which was keeping it from displaying the total weight was:

 

		// EOF Time In Transit	


	$upsQuote = $this->_upsGetQuote();
	if ((is_array($upsQuote)) && (sizeof($upsQuote) > 0)) {
		if ($this->dimensions_support != 0) {
			$this->quotes = array('id' => $this->code, 'module' => $this->title . ' (' . $this->boxCount . ($this->boxCount > 1 ? ' pkg(s), ' : ' pkg, ') . $totalWeight . ' ' . strtolower($this->unit_weight) . ' total)');
		} else {
			$this->quotes = array('id' => $this->code, 'module' => $this->title . ' (' . $shipping_num_boxes . ($this->boxCount > 1 ? ' pkg(s) x ' : ' pkg x ') . $shipping_weight . ' ' . strtolower($this->unit_weight) . ' total)');
		}
		$methods = array();

had to add " if ($this->dimensions_support != 0) {" to make that part work right.

 

All in all a MAJOR improvement. Thanks so much for working on this. You get a big THUMBS UP :thumbsup:

Share this post


Link to post
Share on other sites

Hi guys,

 

I've installed the module locally, and it errors out because I don't have SSL setup on my local machine. I uploaded it to test it on my hosted site and even though it installs fine via the admin interface, nothing appears when I try to checkout an order. I also don't get anything in the debug log.

 

What's the best way to troubleshoot this? I added an error_log at the top of the quote method in the upsxml.php file and it never appears. This tells me that the method is not being called. Can someone explain the typical process to troubleshoot a module?

 

Thank you!

 

Roy

Share this post


Link to post
Share on other sites
Hi guys,

 

I've installed the module locally, and it errors out because I don't have SSL setup on my local machine. I uploaded it to test it on my hosted site and even though it installs fine via the admin interface, nothing appears when I try to checkout an order. I also don't get anything in the debug log.

 

What's the best way to troubleshoot this? I added an error_log at the top of the quote method in the upsxml.php file and it never appears. This tells me that the method is not being called. Can someone explain the typical process to troubleshoot a module?

 

Thank you!

 

Roy

 

find these lines in upsxml.php:

 

		curl_setopt($ch, CURLOPT_URL, $url);
// uncomment the next line if you get curl error 60: error setting certificate verify locations
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// uncommenting the next line is most likely not necessary in case of error 60
	// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
	curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout);

 

you probably need to uncomment this line:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

 

I had to as I was having a similar problem.

Edited by mucter

Share this post


Link to post
Share on other sites

I did that, although I don't see how that helps. Thanks anyway.

 

I just don't think the module is actually being used even though its been installed via admin. Is there some way for me to verify this? Nothing gets logged and the upsxml stuff doesn't appear in the shipping page.

 

Roy

 

you probably need to uncomment this line:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

Share this post


Link to post
Share on other sites

Okay, if I leave out the access key, it errors out. So the module is being called... however when I put the access key back in, I don't see anything appear on the shipping page dealing with UPS. And no errors get generated. Any suggestions on figuring this out?

 

Roy

 

I just don't think the module is actually being used even though its been installed via admin. Is there some way for me to verify this? Nothing gets logged and the upsxml stuff doesn't appear in the shipping page.

Share this post


Link to post
Share on other sites

did you install it with or without the dimensional/packaging support?

 

and uncommenting that line about CURLOPT_SSL_VERIFYPEER should fix the ssl error you were getting on your local machine, thats why I suggested it.\

 

is CURL working on the servers that you are trying this on... nothing will work if its not enabled.

Edited by mucter

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×