Jump to content

Bug size for carrier isn't decimal


Recommended Posts

Hi

My product is 2.5cm high,.

I defined a carrier, in step 3, height is limited to 2cm.
During the checking, this carrier is possible, but it shouldn't.

It seems to be a bug. If I set the carrier max height from 2.0cm to 2.9cm, the carrier is visible despite my article is 2.5cm high,.

To set carrier height to 1cm, then it "works" as expected, the carrier isn't available anymore.

Do you have also this problem ?

Thank you

 

Link to comment
Share on other sites

Hello,

1) Carrier's maximum package dimensions (width, height and depth) are all integer values in the database. One can't use decimals with them. This means that accuracy of package maximum dimensions is 1 cm, not 1 mm.

2) Product dimensions and Carrier maximum package dimensions are compared in file .../classes/Carrier.php, method getAvailableCarrierList(), lines 1591-1613 (in PS 1.7.6.5).

Their widths, heights and depths aren't compared directly with each other, ie. product height is not necessarily compared with package maximum height. Instead product's longest dimension is compager with Carrier's longest maximum package dimension, product's second longest dimension is compared with second longest package dimension etc. My guess is this could explain your observation.

3) Even when product's dimensions are saved as decimal numbers in the database, they are cast to integers before comparison with package dimensions. So here too this means that maximum accuracy of a product dimensions is 1 cm, not 1 mm. Also, when PHP casts decimal numbers to integers, they are rounded towards zero - this means that if a product dimension is for example 2.9 cm, it becomes 2 cm in the comparison mentioned above (at least when shop's dimension unit is cm as it is by default).

 

If product dimensions are a critical factor for your shipping (and they often are), you might be interested in one of two of my addon shipping modules.

Ship in 3D: https://addons.prestashop.com/en/shipping-carriers/48685-ship-in-3d.html
Ship as Letter: https://addons.prestashop.com/en/shipping-carriers/47787-ship-as-letter.html

They both use 3D packing algorithm to verify not just that every individual product fits inside maximum package dimensions, but that all products of an order together fit into given number of available package types (carton boxes, envelopes etc.) The required number of packages, their types and total volume can be used to price the shipping (etc.). The accuracy of dimensions in calculations is 1 mm.

Link to comment
Share on other sites

Thank you for the explanation.

Carrier's maximum dimensions are saved as decimal in the database because after saving, when modify the carrier, I got my decimal values. So this is only a problem in PHP with the casting.

The only size I need to check it the thickness. I have 2 shipping options. Letter 2cm or letter 5cm (maxi letter). 

All my articles are either 1.5cm thick (ok for letter 2cm) or 2.5cm thick (ok for letter 5cm). As you said, the PHP cats 2.5cm to 2cm and it makes the option letter 2cm available...

Do you think I can easily remove the casting ?
A workaround would be to define my products' size 2cm and 3cm (instead of 1.5cm and 2.5cm)
 

Link to comment
Share on other sites

Your installation appears to function differently than mine (I used the latest stable 1.7.6.5 to study this). I'm not even able to insert decimal values to carrier's max dimension settings and the values are integers in the database.

Screenshot_20200530_054354.png.932e8c0ef8129fae529a53404d3fa407.png

Screenshot_20200530_054820.png.0636757399f5d7f39cfde56826b1d905.png

 

I don't think it should be too difficult to change the product size and carrier max package size comparison (although we should remember we don't know why our installations appers to function differently). Have a look at the getAvailableCarrierList() method in .../classes/Carrier.php. But you then need to reapply your changes every time you update your installation, because updates overwrite your custom implementation with the standard implementation. A dedicated addon module would avoid this problem.

Here is an example of how a selection of package types can be configured in my 'Ship in Letter' module (available for PS versions 1.7.2-1.7.7).

Screenshot_20200530_062213.png.5467e3fd8c92ed5d4ebe35ec679150d8.png

Link to comment
Share on other sites

I said a mistake. I checked and you are right. In carrier, the values as integer. Only the size of the products are decimal.

classes/Carrier.php

Line 1597:

$product_sizes = array((int) $product->width, (int) $product->height, (int) $product->depth);

remove (int)

$product_sizes = array( $product->width,  $product->height, $product->depth);

 

That's it. And it works well.
Yes I will have to make this change every time I upgrade my website. I will consider buying your module in the future if my website becomes bigger. I'm not a professional, I'm creating a small website to sell stuff I have at home 🙂

Thank you for your help! Problem solved!

  • Like 1
Link to comment
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
×
×
  • Create New...