I needed to quickly code up a shipping module that is just like table rate, but instead of calculating “total weight” it calculates only on the weight of the heaviest product in the cart.
With some fairly simplistic code, I made it happen.
Step 1
Create an array of product weights as part of the shopping cart class. Like so: 1,7
In this case the total weight of the 6 products is 8kgs (1+7). The highest weight is 7kgs.
Step 2
Read the highest value and use that in a new module based on table rate.
It ended up like this:
This is based on the same shipping cost for both “max weight” and “table” which are both (for this example):
7:2.50,50:5.50,10000:0.00
In other words; up to 7kgs: $2.50, to 50kgs: $5.50
If we work on the basis of TOTAL weight, the cost falls into the up to 50kgs slot as the total is 8kgs.
If we work on the basis of “weight of heaviest product only”, it falls into the upto 7kgs slot.
Conclusion
A very quick and simple project completed for a site going live today. Now the shopowner can offer mixed shipping for heavy and light products.