Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Steps to reproduce:
- Install a latest Commerce Demo 2.x
- Enable Shipments field on Manage form display page for the Physical order type (
admin/commerce/config/order-types/physical/edit/form-display
) and configure it to useinline_entity_form_complex
widget - Make a sample order on a product that can be shipped, for example: Drupal Commerce Hoodie and fill out Shipping, Billing information
- Log in as an administrator and edit the placed order
admin/commerce/orders/%/edit
- Click "Edit" on the Shipment item and press "Update shipment"
- The following error appears in the console:
Error: Call to a member function getEntity() on null in Drupal\commerce_shipping\Plugin\Field\FieldWidget\ShippingProfileWidget->massageFormValues() (line 134 of /commerce/web/modules/contrib/commerce_shipping/src/Plugin/Field/FieldWidget/ShippingProfileWidget.php)."
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#31 | 3106027-31.patch | 11.85 KB | mglaman |
| |||
#31 | interdiff-3106027-31-30.txt | 7.96 KB | mglaman |
#30 | 3106027-30.patch | 13.62 KB | mglaman |
#30 | interdiff-3106027-30-27.txt | 7.26 KB | mglaman |
#27 | interdiff_25-27.txt | 2.71 KB | jsacksick |
Comments
Comment #2
selinav CreditAttribution: selinav commentedComment #3
nginex CreditAttribution: nginex at Drupal Ukraine Community commentedTagging for Drupal Global Contribution Weekend
Comment #4
jsacksick CreditAttribution: jsacksick at Centarro commented@selinav: Could you provide more information (A list of steps that'd help us reproducing the issue)? I just tried editing existing shipments and saving and didn't get any error.
Renaming massageFormValues() will just mean that the parent function is being called instead which explains why the error is gone, but by doing that the shipping profile is probably not going to be saved properly.
Comment #5
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedI am facing the same issue. Updated the issue title and steps to reproduce.
As far as I can see this could be a regression from #3023313: Replace commerce_profile_select usage with the customer_profile inline form due to the following change:
Comment #6
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedA more obvious error appears if you follow the described steps in the issue summary and replace step 5 with: 5. Click "Edit" on the Shipment item and try to save the order.
Edit: Similar error appears if you press "Add new shippment":
Comment #7
selinav CreditAttribution: selinav commentedYou find enclosed the process.
_20.png edit the order but not shipment
_54.png edit the order and shipment with the update shipment button (massageFormValues() was change to messageFormValues())
_18.png after save the shipment modifications. Address changes are not save and return an error on top. I can't save any modifications on order because the top message displays always (save order button)
Comment #8
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedHere is a test-only patch that should fail with an exception.
Comment #9
NicolasGraphI get the error message referenced in the first post on switching the shipping profile during the checkout when the selected shipping method is not available for the shipping profile I switched to.
I can get ride of the error by replacing the line 136 of commerce_shipping/src/Plugin/Field/FieldWidget/ShippingRateWidget.php :
However, I still get a validation error on changing the shipping profile.
'hope it helps
Comment #10
NicolasGraphIn fact, in my case the main error is an illegal choice detected.
I'm not sure how the selected shipping method should be reset if the value is no longer available after switching from a profile to another.
Comment #11
NicolasGraphComment #12
mglamanDebugging this.
Comment #13
mglamanReading #6:
Looks like we have a logic whole when trying to load shipping methods for a new shipment. The IEF doesn't preset the shipment's order.
Comment #14
mglamanHere's a quick test to check #13
Comment #15
mglamanOkay here's the problem.
$value['array_parents']
has:shipments][form][inline_entity_form][entities][0][form][shipping_profile][widget][0
BUT it's actually
shipments][form][inline_entity_form][entities][0][form][shipping_profile][0][widget][0
Comment #16
mglaman#5 caught the edit. IEF sends in the form without needin field_parents to the widget. I still want to investigate #13 for creating a shipment within IEF.
Comment #17
mglamanIEF is a soft dependency because of the Order module and could go away if we make a custom order items widget. This code should go in a specific module that tests IEF integration and marks
@requires module inline_entity_form
Comment #18
mglamanSo we can fix the array parents for IEF edit. But I think we should fix all IEF errors. Using IEF to add a shipment dies because the order isn't set in the profile widget
🧐IEF doesn't call buildEntity before building the form, which I think normal content entity forms do.
Comment #19
mglamanhere's a WIP patch until I have more time.This fixes the array path and starts supporting "Add" in IEF, which probably fixes other bugs along the way. This is basically exposing a lot of specific logic in ShipmentForm.
Comment #20
mglamanThis patch fixes the Add and Edit forms with IEF. There are probably other things needed, but we can do those in follow-ups.
Comment #22
mglamanLet's see after #3116985: CheckoutPaneTest are failing because credit card in tests are using past dates for expiration
Comment #23
mglamanIt isn't pretty, but I think it's the best we can do beyond trying to fetch from route parameters.
Comment #24
jsacksick CreditAttribution: jsacksick at Centarro commented@mglaman: I tested the patch manually myself and found an interesting bug...
Clicking on "Update shipment" no longer "breaks", thanks to the array_parents change but... the shipping profile only gets updated when you submit the main form (But... and that's where it gets interesting, only when the IEF form is opened).
Otherwise, if you switch to a different profile, then click on the IEF submit button, go back to editing the shipment or just save the main form the shipping profile is not updated... Most probably something we can test...
Comment #25
jsacksick CreditAttribution: jsacksick at Centarro commentedTests should be failing, but the following assertion should in theory pass:
from line 615:
Note that as discussed with @mglaman,
assertRenderedAddress
is not designed to work when multiple addresses are shown on the same page. ProfileFieldCopyTest overrides it, but copying the same method doesn't work in our context.For me, during manual testing, I noticed that updating the profile, and then saving using the main "Save" button was working, but the following doesn't:
1) Edit an order to update an existing shipment
2) Update the shipping profile
3) Click on "Update shipment" (First of all, coming back to the shipment edit shows the previously selected profile, instead of the right one) and then saving the main form doesn't correctly update the profile.
Comment #27
jsacksick CreditAttribution: jsacksick at Centarro commentedTesting the actual data doesn't seem to work as expected, but testing what's shown in the UI actually reflects what I noticed during manual testing...
So now I have a failing test that replicates what I experienced during manual testing...
I added
assertRenderedAddressTextOnly()
(which has a terrible name and just for the purpose of testing, but we need to fix the actual parent assertRenderedAddress...).I'm not expecting this to be committed, I did it just for the purpose of demonstrating the failure...
Comment #29
mglamanI've been deep into debugging this issue. It looks like the problem now isn't IEF but the InlineForm plugins when modifying a referenced entity inside of IEF. It's completely OK when the IEF form is open, as the submit process is completely different. However if you submit the IEF and then submit the parent form things fall apart.
Comment #30
mglamanOkay, here is a patch. The IEF widget works fine unless you click "Update shipment", because the CustomerProfile inline form is never submitted. IEF widget works just fine if you never "close" it by saving.
So this patch disables the ief_edit_save button. IEF + Shipping isn't on our strategic roadmap right now. This fixes the issue without diving into a giant rabbit hole, while lettng folks continue to use IEF without much disruption.
Comment #31
mglamanWhoops,
list
got converted thanks to PhpStorm.This fixes linting and also removes data checking to avoid cache invalidations. It solely uses checking the rendered address on the order view page after saving the order.
Comment #32
jsacksick CreditAttribution: jsacksick at Centarro commented@mglaman: I'm actually having second thoughts on this one... While the patch provides basic "IEF" support, there are several things that are missing in order for this to be usable...
Technically, the IEF form for shipment doesn't provide the button to recalculate rates, and no checkboxes for selecting the shipment items...
Basically, we're missing all the logic that's present in the regular ShipmentForm.
Should we mark this as "won't fix"? Or postponed, or are we fine with providing really basic support?
Comment #33
mglamanThose are all valid problems that need to be fixed regardless of IEF or not.
I think we open immediate follow up about hacks in ShipmentForm that need to be addressed and commit this. If people ask "Why doesn't IEF have XYZ" then we can point to that issue, versus more "IEF throws an error"
Comment #34
jsacksick CreditAttribution: jsacksick at Centarro commentedOk, let's proceed with that then, feel free to commit it.
Comment #35
mglamanOkay, I'll commit after I open the general follow ups. Working on this issue showed me ShipmentForm has a lot of clean up to be done.
Comment #37
mglamanCommitted! This makes the form somewhat usable. See #3117476: ShipmentForm hardcodes logic for package types, shipment items, and rate calculation for feature parity improvements. The community is more than welcome to help start that.