Not working with entity reference field on commerce entities

Created on 19 March 2025, 25 days ago

Problem/Motivation

The module doesn't work with entity reference field on commerce entities.

Steps to reproduce

Add a entity reference field, for example a taxonomy term reference on a Commerce Product type.
Create a view of commerce products.
Try to add a entityreference filter on that field.

Proposed resolution

The reason is that inside entityreference_filter_views_data_alter
the check for commerce entities is nested:

      elseif (mb_strpos($table_name, 'commerce_product') !== FALSE) {
        // Commerce product variations.
        if ($field_name === 'variation_id' || (mb_substr($field_name, -10) === '_target_id' && $field_info['filter']['field_name'] === 'variations')) {
          $target_entity_type = 'commerce_product_variation';
        }
        // Commerce product.
        if ($field_name === 'product_id') {
          $target_entity_type = 'commerce_product';
        }
      }

Therefore, for entity reference field for those entities, the outer condition is met, while the inner not.
The following which consider all other entityreference fields is then skipped.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇮🇹Italy Giuseppe87

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024