I'm getting several errors when adding a product field to a product view. After refreshing the view and saving, the view page shows this error "Notice: Undefined index: commerce_product in views_handler_field_field->query() (line 79 of /var/aegir/platforms/dev/sites/all/modules/views/modules/field/views_handler_field_field.inc).". Steps to reproduce:

  • Create a sample product
  • Create a product view
  • Add fields, including 'fields: product'.
  • Preview should throw and/or view page should show an error.

Comments

pcambra’s picture

Issue tags: +dcsprint5

Origin of the problem comes from the views_data_alter from commerce_product_reference module:


/**
 * Implements hook_field_views_data_alter().
 *
 * This is a Views hook implemented to enable adding relationships for
 * referenced products.
 */
function commerce_product_reference_field_views_data_alter(&$data, $field, $module) {
  // If the field is a product reference field...
  if ($field['type'] == 'commerce_product_reference') {
    $keys = array_keys($data);
    $table = array_shift($keys);

    // Add the relationship data to the proper product_id column.
    foreach (array_keys($data[$table]) as $key) {
      if (strpos($key, '_product_id') == strlen($key) - 11) {
        // First indicate this field's table joins to the commerce_product table.
        $data[$table]['table']['join']['commerce_product'] = array(
          'left_field' => 'product_id',
          'field' => $key,
        );

        // Build the bundles this field appears on, noted per entity.
        $bundles = array();

        foreach ($field['bundles'] as $entity => $bundles) {
          $bundles[] = $entity . ' (' . implode(', ', $bundles) . ')';
        }

        // Then add the relationship data to the field itself.
        $data[$table][$key]['relationship'] = array(
          'title' => t('Referenced product'),
          'help' => t('Appears in: @bundles', array('@bundles' => implode(', ', $bundles))),
          'base' => 'commerce_product',
          'base field' => 'product_id',
          'handler' => 'views_handler_relationship',
          'label' => t('Product'),
        );
      }
    }
  }
}

We need to check the base table or the relationship tables to make sure that the Field:product doesn't show up in the commerce_product based views, only in line_items and product display ones.

pcambra’s picture

Status: Active » Needs review

Replaced hook_views_field_data_alter for hook_views_field_data

https://github.com/pcambra/drupalcommerce/commit/ef81e177ea4751a137811b0...

rszrama’s picture

Status: Needs review » Fixed

I can't see any problems with the patch... it appears to be working fine in the capacities it's currently being used. It may be adding stuff to the delta fields of these references, but I don't know how to check that or what the side effects would be if it's incorrect. : ?

The original report has been satisfied, so I'm marking this one fixed.

jlporter’s picture

Did this ever get commited? I tried the -dev release and still no dice.

rszrama’s picture

Yeah, the patch was committed and should be in -dev. You can always search for the function name in your commerce_product_reference.module file.

Status: Fixed » Closed (fixed)
Issue tags: -dcsprint5

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