I have an index for commerce product entities. However, to link to the product display properly, I need to add the "Entity referencing products from field" relationship. I can add this relationship on other commerce product views, and it works fine, but it does not exist on this index view as an option.
So, I tried adding it manually with hook_views_data_alter(). This makes it an option for this type of view. But when you add it, there are several functions missing from the SearchApiViewsQuery class, such as "add_relationship()", and it crashes when you actually visit the view. The extra fields are added just fine as options when you are editing the view, however.
I extend views_plugin_query_default instead of views_plugin_query, as it seemed to be more comprehensive and there are no more fatal errors for missing functions. But the node information is blank coming in, so it doesn't really work right.
Can anyone provide any insight on how to pull this relationship in successfully? I would appreciate it. this is important to get a useful search working on the site.
For reference, here is where I added the relationship to the product index view. It is mainly a copy from commerce_product_reference.views.inc:
$data[$name][$field['field_name']]['relationship'] = array(
'handler' => 'views_handler_relationship',
'base' => $entity_info['base table'],
'base field' => $entity_info['entity keys']['id'],
'relationship table' => _field_sql_storage_tablename($field),
'relationship field' => 'entity_id',
'label' => t('!entity_type referencing products from !field_name', array('!entity_type' => $entity_info['label'], '!field_name' => $field['field_name'])),
'title' => t('!entity_type referencing products from !field_name', array('!entity_type' => $entity_info['label'], '!field_name' => $field['field_name'])),
'help' => t('Relate a product to the !entity_type referencing it.', array('!entity_type' => strtolower($entity_info['label']))),
);Thanks for any insight!
Comments
Comment #1
jsacksick commentedHi, if you install this module http://drupal.org/project/commerce_search_api this will add an additional property to the commerce product which will allow you to retrieve the referenced nodes.