How to set Drupal Commerce shipping rules by the longest of the shortest dimensions of a product? How can I create shipping rules which will base the shipping charge on the length of the package? Specifically, I need two rules for shipping: 1) if the length is less than X, then charge Y; 2) else/if the length is greater than X charge Z. Finally, I only need longest of the shortest dimensions for the shipping price.

I have a use case where the shipping charge is determined by the length of the packaging, not weight, or number of units. The products are posters, which will be rolled along the shortest side, such that I cannot simply base the shipping on a specific physical dimension (e.g. the length) as the posters are sometimes horizontally oriented and for this reason the dimension which needs to be used for the shipping calculation should be the shortest, but shipping must be calculated on the longest of the short dimensions. I'm only just now diving into the shipping rules and I've looked at Commerce Physical and Physical Fields, but I'm not sure how to take the shortest of two dimensions of the products, and then base the shipping on the longest of these.

As always, any advice would be greatly appreciated.
The best way to do this will be to create a custom rules action that sets this the way you want it. Writing rules actions isn't very scary. It's mostly a wrapper around a PHP function. Then you can get the logic just right. You could:


Write an action that takes the order as a parameter, returns the dimension you want, and then calculate the shipping in Rules, or
write a function that applies a shipping line item directly to the order.


Option 1 is easier to write and would be my initial tack on the problem. Option 2 is a bit more holistic but requires that you look at the shipping modules to see how they properly add a shipping line item to the order.