I'm not sure if this should go in commerce or profile, but it's related to profile's entity form using the logged in user as the default profile owner.

A route like `user/{user}/address-book/add/customer` that invokes the profile's entity form isn't able to set the profile's user id. Saving a new address profile creates the profile associated with the currently logged in user instead of the user identified in the route.

If there's no way to resolve this in profile, I guess commerce could extend the form and set the correct value (may be best approach).

Comments

andyg5000 created an issue. See original summary.

andyg5000’s picture

Project: Profile » Commerce
Version: 8.x-1.x-dev » 7.x-2.0
andyg5000’s picture

Project: Commerce » Commerce Core
Version: 7.x-2.0 » 8.x-2.x-dev
Component: Code » Documentation

Moving to commerce. It looks like we need to update the functional js tests to have a user create a profile for a different user than the one that's logged in.

The following code fixes the issue until we get this resolved.


/**
 * Implements hook_ENTITY_TYPE_prepare_form().
 */
function MY_MODULE_profile_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) {
  $route = \Drupal::routeMatch();
  if (!empty($route) && $route->getRouteName() == 'commerce_order.address_book.add_form') {
    $user = $route->getParameter('user');
    if ($user->id() > 0) {
      $entity->set('uid', $user->id());
    }
  }
}

andyg5000’s picture

Component: Documentation » Order
bojanz’s picture

Status: Active » Closed (duplicate)

Marking as a duplicate of #3086299: Admins can't add profiles to another user's address book since it's slightly older.

Commerce and Profile have distinct user UI code, so this bug is Commerce specific.