Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

select shipping method based on longest item in cart


Recommended Posts

Can anyone point me in the right direction?


All my products have length, width, depth

I have 3 shipping methods set up who each have a max length they allow.


What I am trying to do is during the checkout shipping process only show the shipping methods where the longest item in the cart does not exceed the max length the courier allows


How do I determine the longest (products_length) item in the cart within (includes/modules/shopping_cart.php)?

Link to comment
Share on other sites




Since your cart is custom coded, I don't think anyone can make code suggestions without seeing what you already have completed.






Link to comment
Share on other sites

Hi Chris yes i understand that, what i need is to somehow just get the length for the items in the cart and then select the largest one from them


I.e similar to how cart weight is calculated and passed to $this->weight in shopping_cart.php (this gets all the individual items weights * qty)

$products_weight = $product['products_weight'];

$this->weight += ($qty * $products_weight);


I was thinking

$products_length = max($product['products_unit_length'], '');

$this->longest = $products_length;


but this seems to get the length of the last item in the cart instead of the largest?

Link to comment
Share on other sites

The shopping cart steps through each product in the cart in turn, so $product['products_weight'] gets reset to the value for each product. It's added to the total in

$this->weight += ($qty * $products_weight);


Of course that's not what you want. You could test for length like this

	  if( $product['products_unit_length'] > $this->longest ) {
	    $this->longest = $product['products_unit_length'];


Don't forget to initialize $longest = 0 up at the top of the class.




See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...