Drupal: 11.2.2
Commerce: 3.1.0
Commerce shipping pickup api: 1.0.2

Problem/Motivation

When I use a pickup shipping method what do not need to enter customer address i get the following error message:

Undefined array key "pickup_profile" in Drupal\commerce_shipping_pickup_api\Plugin\Commerce\CheckoutPane\PickupCapableShippingInformation->submitPaneForm() (line 409 of modules/contrib/commerce_shipping_pickup_api/src/Plugin/Commerce/CheckoutPane/PickupCapableShippingInformation.php).

Proposed resolution

line: $profile_name = $pane_form['pickup_profile'] ? 'pickup_profile' : 'shipping_profile';
change to: $profile_name = isset($pane_form['pickup_profile']) ? 'pickup_profile' : 'shipping_profile';

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mydot created an issue. See original summary.

anweshas’s picture

Assigned: Unassigned » anweshas

Picking this up, I’ll work on a patch/MR to address the undefined array key error.

djg_tram’s picture

The first, quick idea is to change

$profile_name = $pane_form['pickup_profile'] ? 'pickup_profile' : 'shipping_profile';

to

$profile_name = isset($pane_form['pickup_profile']) ? 'pickup_profile' : 'shipping_profile';

Could you quickly try this? In my quick checks, this seems to be enough.

djg_tram’s picture

Oops, I see, you wrote the same. :-)

I fixed this in the dev version, could you maybe test either that or your own fix to see whether this solves the problems? I did have to change quite a few things in the framework to accommodate submodules that need to ask for an address and have their own UI but it would be nice not to have a regression with those that don't.

mydot’s picture

The new dev version is working now.

In the meantime i found an other bug what appeared with the 1.0.2 version. It shows up on the order shipment edit form:

Error: Call to a member function get() on null in Drupal\commerce_shipping_pickup_api\ProfileFieldCopyWithoutPickup->supportsForm() (line 25 of modules/contrib/commerce_shipping_pickup_api/src/ProfileFieldCopyWithoutPickup.php).

I would suggest to place two conditions after line $order = self::getOrder($form_state);

if (!$order) {
return FALSE;
}

if (!$order->hasField('shipments')) {
return FALSE;
}

djg_tram’s picture

Is it really possible to not get a valid order here? It sounds a bit strange... Anyway, I would suggest to leave the parent call even then and use

    $order = self::getOrder($form_state);
    if ($order && $order->hasField('shipments')) {
      foreach ($order->get('shipments') as $shipment_item) {
        /** @var \Drupal\commerce_shipping\Entity\ShipmentInterface $shipment */
        $shipment = $shipment_item->entity;
        $plugin = $shipment->getShippingMethod()->getPlugin();
        if ($plugin && str_contains($plugin->getPluginId(), 'pickup')) {
          return FALSE;
        }
      }
    }
mydot’s picture

I tried it with your pickup store submodule too, with the same result. But Your suggestion is working.

djg_tram’s picture

Pushed it to dev as well.

djg_tram’s picture

mydot’s picture

Thank You for the quick fix

djg_tram’s picture

1.0.3 published.

djg_tram’s picture

Status: Active » Fixed
djg_tram’s picture

Status: Fixed » Closed (fixed)
anweshas’s picture

Assigned: anweshas » Unassigned
anweshas’s picture

Thanks for the quick follow-up and fixes. Confirming this is resolved in 1.0.3.