Jump to content
Sign in to follow this  

How to get the weight of the heaviest item in cart?

Recommended Posts



been modifying the "Padoren"-contribution (Norwegian postal contrib), but the problem would be the same in any shipping module I've seen so far.


Namely: I use "volume-weight" for shipping, but I need to add some extra handling cost to the shipment based on the actual (product)weight of the heaviest item in cart. (some people charge extra if they have to carry a 100+ kg stove to the n:th floor :P )


Basically I need to get an array of the products_weight(s) in cart and figure out the heaviest weight. (I figure easiest way to get the heaviest would be to sort the array by weight and pick the first or last depending on sort order)


The problem is I don't seem to be able to create the array :blush:


Among other things I've tried: adding $cart to the (shipping module) globals and added this piece of code to the shipping module:

			$kollit_array = 0;	
		$kollit = $cart->get_products();

  for ($i=0, $n=sizeof($kollit); $i<$n; $i++) {
		$this->kollit[$kollit_array] = array('weight' => $kollit[$i]['weight']);
		echo $kollit_array;

the echo is for testing purposes, it gives me "00" (double zero). If I place it before the "for" I get "array". So apparently I get an empty array :angry:


I'm sure my mistakes are elementary, but I seem to have hit the wall.

Any ideas?




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
Sign in to follow this