I will be fleshing this out more in the next few days, but I wanted to get an issue started that we can use to coordinate and add subtasks.

Problem:

Currently Commerce Shipping assumes that each shipment entity represents one physical box. This setup allows the shipment entity to be self contained, have a tracking number, packageType and other data. Each shipment (or package) is assigned a shipping method, and rate for that particular box. While this works for default shipping methods like flat rate (which is a majority portion of the user base), this proves difficult for remote shipping methods, in both calculating rates, and potentially providing fulfillment for these shipments.

If I have a remote shipping method, and a user goes to checkout with an order containing 20 widgets, and I know I can only fit 5 widgets in a box, I need to identify this and request a price for a total of 4 boxes. Currently the FedEx module does this internally during the calculateRates call. The shipping method settings allow the site builder to select from a number of packaging strategies, including shipping each item in it’s own box or estimating the number of needed boxes based on product weight and dimensions.

Solution:

Create a new entity to hold package data and an entity reference field in shipments to hold multiple packages. The existing shipping items array can remain as a master list of items in the shipment. This will allow for backwards compatibility and an easy upgrade path for existing installations.

Steps to implement

Create a new package entity to hold package data
Attach a reference to this entity in shipments
Determine and implement new apis to support this data
This might include something similar to the current packer system, but for packages within a shipment
Create Admin forms and interfaces to manage packages
Deprecate old apis as needed
Implement these apis in contrib shipping methods.

Comments

mikelutz created an issue.

ericchew’s picture

I've done a good bit of work on this issue. There are a lot of moving parts to it, so there needs to be work done on separating everything out to reviewable chunks. The code also needs to be reviewed in general, as I'm not a full time developer, so I'm sure more experienced people may have some better ways of doing things.

I also have a fork of commerce FedEx which uses the changes made in Commerce Shipping. This fork is not complete, it was put together pretty quickly for demo purposes.

Commerce Shipping: https://github.com/ericchew87/commerce_shipping/tree/shipping-packages
Commerce FedEx: https://github.com/ericchew87/drupal-commerce_fedex

Here is a demo video I made to showcase what I have done, the video does not have some more recent changes to the Admin UI for creating shipments: https://youtu.be/9m-MIrTX48Q

I'm hoping i'll get some more time to spend on this soon, feel free to ping me on slack @ericchew with questions.

tonytheferg’s picture

@mikelutz, would this allow for multiple tracking numbers on one shipment?

Also is this something you are still looking to move forward with?

司南’s picture

@ericchew Really good job, but need more, when will you be back to works on this?

司南’s picture

I do a merge from newest 2.x-dev branch to https://github.com/ericchew87/commerce_shipping/tree/shipping-packages at https://github.com/solody/commerce_shipping/tree/shipping-packages, and fix some bugs, and impove code logic.

Welcome somebody else to make it more better together.

ericchew’s picture

I started working on this again recently and have created a contrib module: https://www.drupal.org/project/commerce_packaging

The general idea remains the same as the video I created a few years ago in #2. There are quite a few differences as well. The project is still in very early development stages.