Eman Posted October 15, 2009 Share Posted October 15, 2009 I am building my own shopping-cart/ecommerce website from the ground up. But I'm really stuck with the problem of calculating postage. It is easy enough to do it if I only have one product to calculate postage for, but what about If I have 10 products of all different shapes and sizes and quantities, and I need to calculate the postage? This is my logic: I'm trying to write a php function that will take the first product's dimensions and set that as the parcel width/height/length. And Then loop to the second product, and php will check if the second product is higher or shorter than the first product and then somehow add the dimensions to the parcel, and also calculate excess dimensions.... and rotate the product dimensions to fit in a parcel size... I think I'm confusing myself . but in reality some php script that, given multiple boxes with varying dimensions, it will pack them into as small a parcel as possible, so that I can then calculate the postage costs. Oh, and if there are lots of products and the parcel is too large, it will need to split the parcel into one or more parcels. I love math, but this one has me stuck!! I've been pulling my hair out over this for a while! Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/ Share on other sites More sharing options...
Daniel0 Posted October 15, 2009 Share Posted October 15, 2009 This is known as the Knapsack problem. It's not impossible, but pretty difficult to solve (probably at least without advanced knowledge in computer science or mathematics). Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/#findComment-937273 Share on other sites More sharing options...
Eman Posted October 15, 2009 Author Share Posted October 15, 2009 Thanks! I'm comforted to know that many others have had this problem! How do other e-commerce sites calculate postage? Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/#findComment-937296 Share on other sites More sharing options...
johnsmith153 Posted October 15, 2009 Share Posted October 15, 2009 How do other e-commerce sites calculate postage? Postage £5 per order. Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/#findComment-937407 Share on other sites More sharing options...
Eman Posted October 15, 2009 Author Share Posted October 15, 2009 Yeah I guess that's the easy way out! Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/#findComment-937608 Share on other sites More sharing options...
nadeemshafi9 Posted October 29, 2009 Share Posted October 29, 2009 add the weight to the total weight, and then its about squaring numbers to add and then de-sqaring them to get the final dimensions - i think Quote Link to comment https://forums.phpfreaks.com/topic/177726-impossible-dimensions-of-multiple-boxes-packed-into-as-tight-a-box-as-possible/#findComment-946916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.