The checkout pane assumes that there’s only a single shipment for now.

It then embeds the entity form for the shipment, starting with the shipping profile field (allowing the user to provide an address).
If someone attached a custom field such as Special Instructions, it would show up as well.
Then it shows the available rates below the entity form.

A followup would be to make the pane ask for a shipping profile, then show an entity form for each shipment with the shipping profile element hidden. That allows for rates per shipment, while still keeping a common shipping profile.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

swickham’s picture

Assigned: Unassigned » swickham
swickham’s picture

Work is located in this branch, just an initial commit so far - https://github.com/swickham78/commerce_shipping/tree/shipping_info_pane

bmcclure’s picture

I've abstracted the changes from GitHub into a patch here that should be able to apply against the latest dev version from d.o. All credit for the work done so far goes to swickham, I just wanted to be able to apply the patch to my version of the module to see where things stand.

bmcclure’s picture

Corrected filename spelling.

bmcclure’s picture

Actually it seems like perhaps only the checkout pane class itself needs to be added, I believe the changes from the mentioned commit which create commerce_shipping.module aren't needed anymore due to the order fields being modified a different way. Verifying this and will post another patch if that's the case.

bmcclure’s picture

Confirmed. Here's a patch that has only the checkout pane class itself.

jsacksick’s picture

Status: Active » Needs work
  1. +++ b/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php
    @@ -0,0 +1,127 @@
    +    if ($shipping_profile = $this->order->getBillingProfile()) {
    

    This needs to be updated...

  2. +++ b/src/Plugin/Commerce/CheckoutPane/ShippingInformation.php
    @@ -0,0 +1,127 @@
    +    if (empty($this->order->shipment)) {
    

    You need to check if the order type has the 'order_shippable' trait, in order to do that you need to load the order type.

    Furthermore, the shipments field is multiple ('shipments') and should be accessed like this ($this->order->get('shipments').

    And I don't think we should create the shipment ourselves if it doesn't exist...

bojanz’s picture

Assigned: swickham » bojanz

I'll take this over once I push the packers.

bmcclure’s picture

Cool, glad to see it's getting some more attention!

I've been working all evening last night trying to get a basic shipping pane fully working with the latest commerce_shipping (with a few other various patches applied from the queue here), and I'm just about there. I'll have another patch likely in a little while today that at least resolves most of the existing issues and offers a shipping pane that works at a basic level.

Not sure how close that'll be to what you guys are envisioning, but it perhaps could be used as a starting point if it's not too far off.

bojanz’s picture

Okay, I'll wait for your updated patch. Thank you for your efforts.

bmcclure’s picture

@bojanz Are the packers what will create the shipment entities and reference them in the orders, or if not what is (or should be) responsible for that behavior?

I know this probably isn't the best place to discuss that, but if work on that feature is almost done then I probably don't need to spend much more time figuring out how to deal with there being no shipments referenced when the pane is rendered.

Thanks for clarifying!

bmcclure’s picture

Just answered my own question by reading the task in the issue queue for the packers. Sounds like they'll be what handles creating the shipments before the pane's rendered.

bmcclure’s picture

I haven't gotten as far as I planned yet, but since it's taking longer I wanted to post my progress.

Here's a new patch which fixes a few of the issues with the shipping pane. It lets you fill in a shipping profile, and I *think* it properly saves it to the shipment upon submitting the form, and properly shows you the profile in the summary on the Review page (previously it was showing the billing profile in the shipping summary).

Since packers aren't here yet, there are two temporary methods in the pane class currently responsible for loading or creating a shipment on an order. Obviously once packers are working, the pane class should not concern itself with creating shipments and both of the private methods should be able to go away.

There are some obviously outstanding items here, apart from any existing bugs, just want to call them out specifically as I've noticed them:
- Need to offer existing shipping profiles rather than requiring a new one to be created each time.
- Shipping method options need to be offered in the pane, particularly if there's more than one available.
- The shipping method options need to refresh after updating the shipping profile information so that new rates can be displayed (I think).
- The selected shipping method needs to be stored when submitting the pane.
- The selected shipping method needs to be displayed in the pane summary on the Review page.

bmcclure’s picture

@bojanz You finished packers quickly! Feel free to pick this one up if you're ready, you've got a much clearer vision of what needs to happen here so I should get out of your way for now :)

mikelutz’s picture

So, I've been looking into this. Are we attempting to do the entire thing in one pane with Ajax, or are we doing two separate panes, one with shipping information, and a second one on a shipping step with shipping selection, like we do in 7.x.2.x? The second way certainly seems more reliable and easier, but I wasn't sure. There doesn't seem to be a way to add a shipping step to the MultistepDefault checkout flow, so we could create a new flow called MultistepShipping or something that adds an extra step. Then we could gather the shipping information, and on the next page send that and the order to the packer, then to the shippers to get rates and choose one.

Thoughts?

bmcclure’s picture

Personally, I like the approach Commerce 2 seems to be taking with the "Order Information" page being where all information is gathered.

I would rather see a shipping method selection populate underneath once you select or create a shipping profile, rather than have to go to another page after entering my address.

This feels like it's in line with much of how the D8 UI works, populating forms within forms using AJAX. Many core and contrib forms seem to use this pattern without appearing to have a separate page to fall back to if JS is disabled, so it seems safe to assume we have access to AJAX. Or is this assumption faulty?

It also feels more modern to me if it's all on a single page with fewer page loads. A shipping method selection form is a very small amount of HTML compared with an entire page, and keeping them together would keep the other order information easily accessible without having to go back and forth between steps.

Ultimately, I don't know how separate steps would function when you've got multiple shipments. Would you choose a shipping profile for each shipment on one step, then shipping method for each on the next step, or would each shipment be its own 2-step workflow? That in itself might be a reason to keep everything in one pane and use AJAX, so that the information can all be presented in a neat and orderly way regardless of the number of shipments.

mikelutz’s picture

I'm fine with trying to do it on one page, I think it's a cleaner solution. The next question is, how do we determine that there is enough of a shipping profile filled out to attempt to retrieve shipping quotes. Combining that with the possibility of multiple shipments, and it makes for a complex UI.

Looking around the web for inspiration, I think we need to have a button that saves and validates the shipping profile, and renders it uneditable, and loads the shipping options. Clicking a change button to change the profile information would hide the shipping rates again until the profile is finalized. An option for multiple shipments could be worked into the shipping profile form as well, letting you select a shipping profile to use for each item, such that when it is finalized again, we have enough information to create the shipping options for each shipment.

I think this flow would give an opportunity to create a framework that would let us get a patch that supports single shipments to start, but is extensible once that is working as well.

bmcclure’s picture

I'm all for that idea! I haven't had a chance to get back to this issue since my last patch in #14, but the site I'm working on now is very much in need of a functioning shipping information pane, as well as FedEx integration for it (the port I started recently that's underway).

I'm working through some other priority items on my project at the moment, but any day now I'll be able to pick up trying to help wrapping up anything I can with this shipping information pane if there isn't a working version by then, and then trying to wrap up the FedEx port.

bojanz’s picture

I should have the commit up today. It escalated a bit. Stay tuned.

We indeed have a single pane. We show the Shipping profile, then a hidden "Recalculate shipping" button, then the rest (form per shipment).
When the address changes, our JS hits the button, causing the rest of the form to be rebuilt.
You have a setting "Hide shipping costs until an address is entered" that defaults to TRUE.

mikelutz’s picture

Looking forward to it. I'll find something else to work on.

bmcclure’s picture

bojanz: That sounds perfect, thanks!

Once I finish some other QA items on a project, I can focus on wrapping up my initial commerce_fedex port and testing it with the upcoming shipping pane work.

mikelutz’s picture

How's this one coming? Are there any blockers I can help with, or anything else I can to do contribute, or a partially finished patch I can work with? I appreciate all the work everybody is doing. I'm looking forward to seeing this pane.

bojanz’s picture

Status: Needs work » Fixed

Sorry for the wait, everyone. Here's the commit (well, more like 5 squashed into one :P)
Spent quite a bit of time on tests.

The "recalculate shipping" button currently needs to be manually clicked.
I'll commit the code that hides it + clicks it automatically on address change in a followup.

  • bojanz committed d2bdf62 on 8.x-2.x
    Issue #2826307 by bmcclure, bojanz, mikeNCM, swickham, jsacksick:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.