Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Splitting the weight into more boxes


dtchaos

Recommended Posts

I am trying to modify this mod, to split the weight of any order into 20 lb boxes, the shop I run sells rough rock, and people ordering over 20 lbs cant choose flat rate if their order is over 20 lbs as we are willing to ship in boxes up to 70 lbs. So what I'm trying to do is modify this mod so it divides the weight of the order into 20 lb packages. So this mod will show 2 boxes at 20 lbs instead of 1 box at 40 lbs.

 

I realize that this is calculated in classes/shipping.php in the quote(); function. I noticed the quote(); function in uspsflat.php and I'm wondering if it would be possible to recalculate the package weight here so the user is shown the shipping cost if their order was split between 20 lb packages, or if I have to do that in shipping.php?

 

Does anyone know if this would work?

Link to comment
Share on other sites

check the oscommerce admin panel --> configuration --> Shipping/Packaging

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!

8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.

Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.

Any issues with oscommerce, I am here to help you.

Link to comment
Share on other sites

check the oscommerce admin panel --> configuration --> Shipping/Packaging

Oh I realize it can be set in the Admin panel, but we need the over all wieght to be set to 70lbs so we can ship packages up to that weight, but we also need a a mod that shows what the shipping price would be if the order were split into several flat rate boxes. I.e. to find out which is cheaper etc.

 

Note: I intended to post this in http://www.oscommerce.com/forums/index.php?showtopic=294676 sorry.

Edited by dtchaos
Link to comment
Share on other sites

I tried modifying the calculation around line 85 of classes/shipping.php

 

if(substr_count("flat",$method) > 0){
		if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
		  $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
		  $shipping_weight = $shipping_weight/$shipping_num_boxes;
		}
}else{
	  if ($shipping_weight > 18) { // Split into many boxes
		  $shipping_num_boxes = ceil($shipping_weight/18);
		  $shipping_weight = $shipping_weight/$shipping_num_boxes;
	 }
}

 

However this wound up dividing ALL shipping methods into 18 lb boxes as opposed to just the flat rate mod. I'm assume once it found one instance, of "flat" it just divided all the shipping methods into 18 lb boxes.

Link to comment
Share on other sites

I solved this my self by doing the following:

I took the USPS Flat Rate shipping module, then edited my includes/classes/shipping.php quote function to read as follows.

function quote($method = '', $module = '') {
  global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes, $flat_shipping_weight, $flat_shipping_num_boxes;

	 // This was used for debugging and finding out what this function was doing.
 /* $myFile = "/home/thegemsh/thegemshop.com/html/osc/includes/classes/errlog.txt";
  $fh = fopen($myFile, 'w') or die("can't open file");
  $stringData = '$module = ' . $module . '\n';
   fwrite($fh, $stringData);
   fclose($fh);*/

  $quotes_array = array();

  if (is_array($this->modules)) {
	$shipping_quoted = '';
	$shipping_num_boxes = 1;
	$flat_shipping_num_boxes = 1;
	$shipping_weight = $total_weight;
	$flat_shipping_weight = $total_weight;

	if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
	  $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
	  $flat_shipping_weight = $flat_shipping_weight+SHIPPING_BOX_WEIGHT;
	} else {
	  $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
	  $flat_shipping_weight = $flat_shipping_weight + ($flat_shipping_weight*SHIPPING_BOX_PADDING/100);
	}

	  if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
		  $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
		  $shipping_weight = $shipping_weight/$shipping_num_boxes;
	  }
		// This was used for debugging to find out what this function was doing.
		/*$myFile = "/home/thegemsh/thegemshop.com/html/osc/includes/classes/errlog.txt";
		$fh = fopen($myFile, 'w') or die("can't open file");
		$stringData = '$this->modules = ' . $this->modules . '\n';
		fwrite($fh, $stringData);
		fclose($fh);*/

	  if ($flat_shipping_weight > 18) { // Split into many boxes
		  $flat_shipping_num_boxes = ceil($flat_shipping_weight/18);
		  $flat_shipping_weight = $flat_shipping_weight/$flat_shipping_num_boxes;
	  }

 

I then modified every instance of $shipping_weight and $shipping_num_boxes in includes/modules/shippin/uspsflat.php to be $flat_shipping_weight, and $flat_shipping_num_boxes. Thus making it use the variables that divide it into 20 lb packages. The reason why it divides at 18 and not 20 is to allow for the tear weight of the packages to be added without blowing the 20 lb limit.

 

I hope this helps anyone trying to do the same thing.

 

The contribution I modified is http://addons.oscommerce.com/info/5783

http://www.oscommerce.com/forums/index.php?showtopic=294676 is the forum thread for the mod I modified.

Edited by dtchaos
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...