Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andyg5000 created an issue. See original summary.

andyg5000’s picture

Here's one approach to fixing the issue. Will need the Functional JS test to be updated.

mglaman’s picture

Assigned: andyg5000 » mglaman

Going to work on a test for this today.

mglaman’s picture

Confirmed. If you recalculate a shipment it sets the billing address to null.

mglaman’s picture

Status: Needs review » Needs work

This does not account for editing the existing address

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.7 KB

This works for new or edited profiles. We need a test that has a shipping method that restricts a specific address component and modifies the address to prove it becomes valid or invalid.

mglaman’s picture

Assigned: mglaman » Unassigned
FileSize
4.36 KB

And here's the test that verifies a shipping method with a Zone condition becomes available when the address is changed.

Status: Needs review » Needs work

The last submitted patch, 7: 3079228-7.patch, failed testing. View results

mglaman’s picture

End of the day here, not sure why that failed. It passes locally, there must be something in my environment.

jsacksick’s picture

Status: Needs work » Needs review
FileSize
4.36 KB

Just a reroll...

Status: Needs review » Needs work

The last submitted patch, 10: 3079228-10.patch, failed testing. View results

jsacksick’s picture

Assigned: Unassigned » jsacksick

Debugging this...

jsacksick’s picture

Ok... found this error:

AssertionError: assert($selected_profile instanceof ProfileInterface)

The reason for that is that we're trying to load a profile with $selected_profile_id = '_original'.

jsacksick’s picture

Status: Needs work » Needs review
FileSize
4.44 KB

Ok, this time tests should be passing.
Instead of setting the address on the profile, I'm directly setting the profile on the shipment when available... This way, if custom fields other than the address are attached to a profile, and conditions are targeting them, the correct values should be used.

Status: Needs review » Needs work

The last submitted patch, 14: 3079228-14.patch, failed testing. View results

jsacksick’s picture

Status: Needs work » Needs review
FileSize
4.43 KB

Ok, so setting the shipment profile doesn't seem to be a good idea... The ValidReferenceConstraint returns a violation indicating that the profile cannot be referenced for some reason (This normally happens because of the access)...

So setting the address on the profile instead like in the previous patches...

Since $selected_profile_id could also contain "_new" and "_original", I'm now testing that $selected_profile_id is numeric.

Status: Needs review » Needs work

The last submitted patch, 16: 3079228-16.patch, failed testing. View results

jsacksick’s picture

Status: Needs work » Needs review
FileSize
4.57 KB
1.11 KB

Hopefully the last attempt (Tests are passing locally)...

mglaman’s picture

Assigned: jsacksick » mglaman
+++ b/src/Form/ShipmentForm.php
@@ -218,9 +219,19 @@ class ShipmentForm extends ContentEntityForm {
+      $selected_profile_key = array_merge($base_form_key, ['select_address']);
+      $selected_profile_id = $form_state->getValue($selected_profile_key);
+      $address_key = array_merge($base_form_key, ['address', '0', 'address']);
+      $address = $form_state->getValue($address_key);
+      if ($address === NULL && (!empty($selected_profile_id) && is_numeric($selected_profile_id))) {
+        $profile_storage = $this->entityTypeManager->getStorage('profile');
+        $selected_profile = $profile_storage->load($selected_profile_id);
+        assert($selected_profile instanceof ProfileInterface);
+        $address = $selected_profile->get('address')->first()->getValue();
+      }
+      $shipment->getShippingProfile()->get('address')->setValue($address);

Discussed with @jsacksick and the problem was _original for the selected profile ID.

mglaman’s picture

Assigned: mglaman » Unassigned
FileSize
5.48 KB

I cannot reproduce where _original exists, as the CustomerProfile form only lets it exist as a way to go back to an original entity. But this adds some safeguards. I also added a test to assert the first calculation accounts for the current profile. @jsacksick can reproduce, so this is definitely a safe bet to guard against.

mglaman’s picture

Status: Needs review » Needs work

Okay so @jsacksick and I did a call and determined there's something with chromedriver. It's skipping the first press of the recalculate button which sends _original.

mglaman’s picture

Status: Needs work » Needs review
FileSize
6.31 KB

It's due to manually clicking links, which doesn't wait for Drupal JavaScript behaviors to attach. So the first button press does nothing.

  • mglaman committed 58dce58 on 8.x-2.x
    Issue #3079228 by mglaman, jsacksick, andyg5000: Admin shipment form...
mglaman’s picture

Status: Needs review » Fixed

😱 fixed!

Status: Fixed » Closed (fixed)

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