Problem/Motivation

If you change the attribute field on a product variation to use an Entity Reference View to filter to options there is a fatal error in commerce_product_field_views_data_alter() because $handler_settings['target_bundles'] is not set.

Proposed resolution

Check that the reference field is using the default handler before altering

if ($field->getSetting('handler') == 'default:commerce_product_attribute_value')

Original report by @orangeicebear

i got this Warning

Warning: array_values() expects parameter 1 to be array, null given in commerce_product_field_views_data_alter() (line 33 of modules/contrib/commerce/modules/product/commerce_product.views.inc).
Warning: reset() expects parameter 1 to be array, null given in commerce_product_field_views_data_alter() (line 34 of modules/contrib/commerce/modules/product/commerce_product.views.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

orangeicebear created an issue. See original summary.

cobenash’s picture

Confirmed error.

cobenash’s picture

I think the problem was caused because I deleted the default product type.

But I think this is a proper move that the user may do, so I create a patch to fix the warning.

narendra.rajwar27’s picture

Assigned: Unassigned » narendra.rajwar27
narendra.rajwar27’s picture

Fix for the failed test cases.

narendra.rajwar27’s picture

narendra.rajwar27’s picture

Patch issue in #6, adding updated patch after correction.

narendra.rajwar27’s picture

Assigned: narendra.rajwar27 » Unassigned
Status: Needs work » Needs review
dwkitchen’s picture

Title: commerce_product.views.inc » commerce_product_field_views_data_alter() assumes the default handler is being used
Version: 8.x-2.17 » 8.x-2.x-dev
Issue summary: View changes
FileSize
1.71 KB

Updated the cause of the issue and provided patch

jsacksick’s picture

FileSize
689 bytes

I think checking if the "target_bundles" setting isn't empty is a better option.

That still leaves the opportunity to define another entity reference selection handler, that isn't the default one and that still uses the same setting.

@dwkitchen: let me know if this approach still works for your usecase.

dwkitchen’s picture

Status: Needs review » Reviewed & tested by the community

Yep good idea, resolves issue

  • jsacksick committed 5a792d6 on 8.x-2.x
    Issue #3133003 by narendra.rajwar27, cobenash, dwkitchen, jsacksick,...

  • jsacksick committed 36dea32 on 3.0.x
    Issue #3133003 by narendra.rajwar27, cobenash, dwkitchen, jsacksick,...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed! @dwkitchen: Thanks for confirming that the fix works as expected!

Status: Fixed » Closed (fixed)

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