Problem/Motivation

The commerce:user selection handler (added in Commerce 2.38 to resolve #3035268) is supposed to allow autocomplete search by both username and email address. However, due to a query construction error, email‑only searches return no results.

Steps to reproduce

  1. Install Commerce 2.40.
  2. Go to Add order (/admin/commerce/orders/add) or Reassign order.
  3. In the customer search field, type a valid email address belonging to an existing user.
  4. No results appear. Typing a username does show results.

Root cause

The buildEntityQuery() method in UserSearch calls DefaultSelection::buildEntityQuery(), which already forces a condition on the name field. The later orConditionGroup() that adds mail is therefore ignored.

Proposed resolution

Replace the broken query builder with a fresh query that correctly adds an OR condition on both name and mail fields.

Issue fork commerce-3585451

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

knyshuk.vova created an issue. See original summary.

knyshuk.vova’s picture

Status: Active » Needs review
StatusFileSize
new1.41 KB

Attached a patch to mirror MR

jsacksick’s picture

8.x-2.x is no longer maintained, can you open an MR against 3.x?

knyshuk.vova’s picture

Added a branch and an MR against 3.x

anybody’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Issue tags: +Needs tests

I'd vote to add a test to ensure this never happens again? Create an entry and search for the email address (and the name in another test)

ivnish’s picture

Version: 3.0.x-dev » 3.x-dev
jsacksick’s picture

Status: Needs review » Needs work

The problem is with these changes, the following is no longer happening:


    // Add entity-access tag.
    $query->addTag($target_type . '_access');

    // Add the Selection handler for system_query_entity_reference_alter().
    $query->addTag('entity_reference');
    $query->addMetaData('entity_reference_selection_handler', $this);

    // Add the sort option.
    if ($configuration['sort']['field'] !== '_none') {
      $query->sort($configuration['sort']['field'], $configuration['sort']['direction']);
    }

Plus the bundle filtering (but I guess this doesn't matter much for users as in 99% of the installs there is probably only one bundle.