Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 03-18-2017 05:53:40

Graham
Member
Registered: 09-30-2004
Posts: 981
Website

Adding length calculation to Custom Shipping Method

I'm selling some items which are longer than the length that Royal Mail allows for a Small Parcel, so I need to add extra cost if an order will need to go in a Medium parcel.

In the basic supplied code it says:

Code:

// | All custom shipping scripts work in the same way.  A global
// | variable named 'ecom.customship' contains the following PHP
// | array.  Array keys with value info:
// |

// | packages      => An array containing all packages with
// |                  each package defined in it's own array
// |                  with keys: length, width, height, weight.

I've created a variable $ship_length but how do I set it to the package length?

Also if someone orders multiple items, how do I find the longest one?

Offline

 

#2 03-20-2017 07:55:44

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Adding length calculation to Custom Shipping Method

$packages is an array.  Loop through it until you find the key with the largest length.


Nick Hendler

Offline

 

#3 03-21-2017 20:19:53

Graham
Member
Registered: 09-30-2004
Posts: 981
Website

Re: Adding length calculation to Custom Shipping Method

Thanks for the reply, but I'm afraid I don't understand what you mean.

How do I actually find what an item's length is from the $packages array?

Is it just something like $ship_length=$packages(length)?

Offline

 

#4 03-22-2017 09:37:48

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Adding length calculation to Custom Shipping Method

$packages is an array, meaning it's a list of packages.  To see what's in it, do:

Code:

print '<pre>' . print_r($packages,1) . '</pre>';

To loop through it and get the length of the first package:

Code:

$length = 0; foreach ($packages as $packageid => $package) {$length = $package['length']; break 1;}

To loop through it and get the length of the longest package:

Code:

$length = 0; foreach ($packages as $packageid => $package) {if ($package['length'] > $length) {$length = $package['length'];}}

Nick Hendler

Offline

 

#5 03-23-2017 05:59:15

Graham
Member
Registered: 09-30-2004
Posts: 981
Website

Re: Adding length calculation to Custom Shipping Method

Great, thanks for that, I'll give it a try.

Offline

 

Board footer