 .../views_extra/commerce_extra_views_extra.info    |  6 ++
 .../views_extra/commerce_extra_views_extra.module  | 35 ++++++++++
 .../includes/commerce_extra_views_extra.views.inc  | 74 ++++++++++++++++++++++
 3 files changed, 115 insertions(+)

diff --git a/modules/views_extra/commerce_extra_views_extra.info b/modules/views_extra/commerce_extra_views_extra.info
new file mode 100644
index 0000000..224fb00
--- /dev/null
+++ b/modules/views_extra/commerce_extra_views_extra.info
@@ -0,0 +1,6 @@
+name = Commerce Extra Views Extra
+description = Adds relationships, handlers, or any other views related components that would be missing from Drupal Commerce Views integration.
+package = Commerce Extra
+core = 7.x
+dependencies[] = views
+dependencies[] = commerce
diff --git a/modules/views_extra/commerce_extra_views_extra.module b/modules/views_extra/commerce_extra_views_extra.module
new file mode 100644
index 0000000..5356adf
--- /dev/null
+++ b/modules/views_extra/commerce_extra_views_extra.module
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Defines additional views components for Drupal Commerce fields and objects.
+ *
+ * Anything that would be missing from Drupal Commerce Views integration could
+ * be included in this module, such as relationships, handlers, plugins,
+ * default views, etc...
+ */
+
+/**
+ * Implements hook_views_api().
+ */
+function commerce_extra_views_extra_views_api() {
+  return array(
+    'api' => 3,
+    'path' => drupal_get_path('module', 'commerce_extra_views_extra') . '/includes',
+  );
+}
+
+/**
+ * Implementation hook_help().
+ */
+function commerce_extra_views_extra_help($path, $arg) {
+  switch ($path) {
+    case 'admin/help#commerce_extra_views_extra':
+      $output = '<p>'.t('The Commerce Extra Views Extra module currently provides <strong>two additional relationships</strong> to the objects defined by Drupal Commerce for the <strong>Product Reference</strong> and <strong>Customer Profile Reference fields</strong>:').'</p>';
+      $output .= '<ol><li>'.t('A <strong>reverse Product Reference relationship</strong> can be configured for views on <strong>Line Item</strong> entities.<br/><strong>In practice</strong>, it means it is possible to <strong>relate a product to a Line Item entity that is referencing it through one of its Product Reference fields</strong>.<br/><em>For example</em>, for the commerce_product field, on Product Line Item entities, a new views relationship called <em>Commerce Product: Commerce Line item referencing products from commerce_product</em> could be configured.').'</li>';
+      $output .= '<li>'.t('A <strong>reverse Customer Profile relationship</strong> can be configured for views on <strong>Customer Profile</strong> entities.<br/><strong>Concretelly speaking</strong>, this means that it is possible to <strong>relate a Customer Profile entity with another entity that is referencing it through one of its Customer Profile Reference fields</strong>.<br/><em>For example</em>, for the commerce_customer_billing field, a new views relationship called <em>Commerce Customer Profile: Commerce Order referencing customer profiles from commerce_customer_billing</em> could be configured on a views on customer profiles.').'</li></ol>';
+      return $output;
+      break;
+    default: break;
+  }
+}
diff --git a/modules/views_extra/includes/commerce_extra_views_extra.views.inc b/modules/views_extra/includes/commerce_extra_views_extra.views.inc
new file mode 100644
index 0000000..da8663c
--- /dev/null
+++ b/modules/views_extra/includes/commerce_extra_views_extra.views.inc
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Provide Commerce related Views extra integration.
+ */
+
+/**
+ * Implements hook_views_data_alter().
+ *
+ * Allows module to declare two types of reverse views relationships for
+ * Product Reference and Customer Reference field types.
+ */
+function commerce_extra_views_extra_views_data_alter(&$data) {
+  // Adds inverse relationships between the product and entity types referencing
+  // it (for example, nodes).
+  foreach (field_info_fields() as $field_name => $field) {
+    if ($field['type'] !== 'commerce_product_reference') {
+      continue;
+    }
+    // Only add the relationship for commerce_line_item since product_reference
+    // already adds it for all other entities.
+    foreach ($field['bundles'] as $entity_type => $bundles) {
+      if ($entity_type != 'commerce_line_item') {
+        continue;
+      }
+
+      $entity_info = entity_get_info($entity_type);
+      $data['commerce_product'][$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']))),
+      );
+    }
+  }
+
+  // Adds inverse relationships between the customer profile and entity types
+  // referencing it (for example, nodes).
+  foreach (field_info_fields() as $field_name => $field) {
+    if ($field['type'] !== 'commerce_customer_profile_reference') {
+      continue;
+    }
+
+    // Add a join to commerce_customer_profile so that it can be used by the inverse relationship.
+    $data[_field_sql_storage_tablename($field)]['table']['join']['commerce_customer_profile'] = array(
+      'left_field' => 'profile_id',
+      'field' => $field['field_name'] . '_profile_id',
+      'extra' => array(
+        array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
+      ),
+    );
+
+    foreach ($field['bundles'] as $entity_type => $bundles) {
+
+      $entity_info = entity_get_info($entity_type);
+      $data['commerce_customer_profile'][$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 customer profiles from !field_name', array('!entity_type' => $entity_info['label'], '!field_name' => $field['field_name'])),
+        'title' => t('!entity_type referencing customer profiles from !field_name', array('!entity_type' => $entity_info['label'],  '!field_name' => $field['field_name'])),
+        'help' => t('Relate a customer profile to the !entity_type referencing it.', array('!entity_type' => strtolower($entity_info['label']))),
+      );
+    }
+  }
+}
