FedEx shipping - Multiple package issue

  • Posts: 195
  • Thank you received: 13
  • Hikashop Business
8 years 9 months ago #230636

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.4
-- PHP version -- : 5.5.32

I'm working on some custom coding of the HikaShop FedEx shipping plugin. I'm working on shipping multiple packages in one order, but getting lower than expected shipping costs from FedEx compared to their online rate estimates.

Specifically I've found the code in the addPackageLineItem method in the fedex.php file seems to have an issue. The code in this function is not customized or modified. But it is not handling multiple packages. Please note I'm not familiar with nor do I have a copy of the FedEx shipping rate API documentation. However, that's my next step.

First, it starts by setting $packageLineItem[] = array();
Then a foreach loop breaks the $pkg_values passed parameter into individual $pkg items and sets up the contents of the array that will be added for each line item.
Then it sets $packageLineItem = array(...); This has the effect of redefining that variable rather than adding to it such that $packageLineItem is always the last item in the foreach loop rather than adding each new formatted array to $packageLineItem.

So the addPackage method never returns more than one package line item and always returns only the last item when multiple packages are submitted.

It seems the solution is to add each new formatted array to the $packageLineItem. I've done this as a test, but I'm not getting any response from FedEx. Since I don't know the format FedEx is expecting for multiple packages in one rate request my testing may not be building the correct array of arrays.

Anyone else noticed this and have a solution?


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters
Last edit: 8 years 9 months ago by 3by400.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
8 years 9 months ago #230657

Hello,

You're right, the solution will be to change these lines :

$ct = count($pkg_values);
$x = 1;
foreach($pkg_values as $pkg) {
	if($pkg['PackageWeight']['UnitOfMeasurement']['Code'] == "LBS"){
		$uom = "LB";
	} else {
		$uom = $pkg["PackageWeight"]["UnitOfMeasurement"]['Code'];
	}
	if(is_array($pkg['Dimensions'])){
		$dimensions = array("Dimensions"=>array(
			'Length' => $pkg['Dimensions']['Length'],
			'Width' => $pkg['Dimensions']['Width'],
			'Height' => $pkg['Dimensions']['Height'],
			'Units' => $pkg['Dimensions']['UnitOfMeasurement']['Code'])
		);
	}

	$packageLineItem = array(
		'SequenceNumber'=>$x,
		'GroupPackageCount'=>$ct,
		'Weight' => array(
			'Value' => $pkg['PackageWeight']['Weight'],
			'Units' => $uom
		),
		$dimensions
	);
	$x++;
}
);
By:
$x = 0;
foreach($pkg_values as $pkg) {
	if($pkg['PackageWeight']['UnitOfMeasurement']['Code'] == "LBS"){
		$uom = "LB";
	} else {
		$uom = $pkg["PackageWeight"]["UnitOfMeasurement"]['Code'];
	}
	if(is_array($pkg['Dimensions'])){
		$dimensions = array("Dimensions"=>array(
			'Length' => $pkg['Dimensions']['Length'],
			'Width' => $pkg['Dimensions']['Width'],
			'Height' => $pkg['Dimensions']['Height'],
			'Units' => $pkg['Dimensions']['UnitOfMeasurement']['Code'])
		);
	}

	$packageLineItem[$x] = array(
		'SequenceNumber'=>$x+1,
		'GroupPackageCount'=>1,
		'Weight' => array(
			'Value' => $pkg['PackageWeight']['Weight'],
			'Units' => $uom
		),
		$dimensions
	);
	$x++;
}
);

And change these lines :
}
if(($this->freight==true && $this->classicMethod==false) || ($heavyProduct==true && $this->freight==true))
	$data['XMLpackage'].=$this->_createPackage($data, $product, $rate, $order );
else
	$data['XMLpackage'].=$this->_createPackage($data, $product, $rate, $order, true );
By :
	if(($this->freight==true && $this->classicMethod==false) || ($heavyProduct==true && $this->freight==true))
		$data['XMLpackage'].=$this->_createPackage($data, $product, $rate, $order );
	else
		$data['XMLpackage'].=$this->_createPackage($data, $product, $rate, $order, true );
}
Thanks for your feedback.

Last edit: 8 years 9 months ago by Mohamed Thelji.

Please Log in or Create an account to join the conversation.

  • Posts: 195
  • Thank you received: 13
  • Hikashop Business
8 years 9 months ago #230929

Thanks Mohamed. Your solution is almost identical to mine except that you're setting your 'SequenceNumber' => $x+1 where I set it just to $x. The sequence number starting at 0 instead of 1 seems to work fine with FedEx.

The other issue this doesn't address is the proper use of the 'GroupPackageCount' variable. The FedEx tech support person explained it to me this way. If you have 2 or 3 identical packages (same weight, same dimensions), these would normally be referenced in the same SequenceNumber as GroupPackageCount = 2 or 3 respectively. I haven't seen any other logic in the plugin that would support this. But just saying this is how the GroupPackageCount value is used and with it set to '1' as a constant, the addPackageLineItem method is not able to support proper use of the GroupPackageCount feature.


3by400, Inc.
3by400.com
Websites that Work, Marketing that Matters

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
8 years 9 months ago #231023

Hello,

The sequence number starting at 0 instead of 1 seems to work fine with FedEx.

When I tested it on my end I had an error message regarding the "Sequence number", so that's why I have set it to x+1

The other issue this doesn't address is the proper use of the 'GroupPackageCount' variable. The FedEx tech support person explained it to me this way. If you have 2 or 3 identical packages (same weight, same dimensions), these would normally be referenced in the same SequenceNumber as GroupPackageCount = 2 or 3 respectively

I didn't totally understood it, do you mean that if 2 products have the same dimensions and weight then they'll have to be grouped on the same "PackageLineItem" but with a GroupPackageCount set to the quantity of products ?
If that's the case, note that the FedEx shipping plugin wasn't originally developed by us so we weren't aware of it we just maintained it so that our customers can still use it.
There is actually no option to do that so if you want your FedEx shipping method you'll have to directly do it by customizing the code of the FedEx shipping plugin. My advice will be to :
- Directly check if some product have the same dimensions/weight on the "_getRates" function, just before we add package information (dimensions/weight) in the "$Data" variable.
- Adapt the code of the "addPackageLineItem" function.

Please Log in or Create an account to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum