Catalog View
With the latest commits to Drupal Commerce and a patch pending for Views, I've got full Views relationship support working through product reference fields. This means you can pull any field from a product into a Node View if that product has been referenced by a Node in the View. If that's too much to wrap your head around, I can say it simply:
We now support product catalog Views! Woohoo! ; )
And here's my first draft, albeit untested on multi-value product references thus far. I plan to get to that shortly...
I have this all set to be uploaded to d.o in a module, but I didn't know if I should do that or wait and see if a DC Features server would materialize. Any thoughts on that?
$view = new view;
$view->name = 'catalog';
$view->description = 'A basic product catalog.';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'title' => 'title',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
'title' => array(
'sortable' => 0,
'align' => '',
'separator' => '',
),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* Relationship: Fields: Referenced product */
$handler->display->display_options['relationships']['field_product_product_id']['id'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['table'] = 'field_data_field_product';
$handler->display->display_options['relationships']['field_product_product_id']['field'] = 'field_product_product_id';
$handler->display->display_options['relationships']['field_product_product_id']['required'] = 1;
/* Field: Node: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['exclude'] = TRUE;
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
/* Field: Fields: field_image */
$handler->display->display_options['fields']['entity_id']['id'] = 'entity_id';
$handler->display->display_options['fields']['entity_id']['table'] = 'field_data_field_image';
$handler->display->display_options['fields']['entity_id']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['entity_id']['label'] = 'Product';
$handler->display->display_options['fields']['entity_id']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['path'] = 'node/[nid]';
$handler->display->display_options['fields']['entity_id']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id']['empty_zero'] = 0;
$handler->display->display_options['fields']['entity_id']['type'] = 'image__thumbnail';
/* Field: Node: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Fields: base_price */
$handler->display->display_options['fields']['entity_id_1']['id'] = 'entity_id_1';
$handler->display->display_options['fields']['entity_id_1']['table'] = 'field_data_base_price';
$handler->display->display_options['fields']['entity_id_1']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id_1']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['entity_id_1']['label'] = 'Price';
$handler->display->display_options['fields']['entity_id_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id_1']['empty_zero'] = 0;
/* Field: Fields: field_product */
$handler->display->display_options['fields']['entity_id_2']['id'] = 'entity_id_2';
$handler->display->display_options['fields']['entity_id_2']['table'] = 'field_data_field_product';
$handler->display->display_options['fields']['entity_id_2']['field'] = 'entity_id';
$handler->display->display_options['fields']['entity_id_2']['label'] = 'Buy it now!';
$handler->display->display_options['fields']['entity_id_2']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['trim'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['entity_id_2']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['entity_id_2']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['entity_id_2']['alter']['html'] = 0;
$handler->display->display_options['fields']['entity_id_2']['hide_empty'] = 0;
$handler->display->display_options['fields']['entity_id_2']['empty_zero'] = 0;
$handler->display->display_options['fields']['entity_id_2']['type'] = 'commerce_cart_add_to_cart_form';
/* Filter: Node: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Filter: Node: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'product' => 'product',
);
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'catalog';
Comments
Sounds fantastic. I tried to
Sounds fantastic. I tried to use this, but ran into the following problems when I went to admin/structure/views/import and tried to import the view from code using the code above:
* Debug: 'Missing handler: field_data_field_product entity_id field' in views_get_handler() (line 724 of /home/clients/websites/w_dc/public_html/dc/sites/all/modules/views/views.module).
* Debug: 'Missing handler: field_data_field_product field_product_product_id relationship' in views_get_handler() (line 724 of /home/clients/websites/w_dc/public_html/dc/sites/all/modules/views/views.module).
* Debug: 'Missing handler: field_data_field_product entity_id field' in views_get_handler() (line 724 of /home/clients/websites/w_dc/public_html/dc/sites/all/modules/views/views.module).
* Debug: 'Missing handler: field_data_field_product field_product_product_id relationship' in views_get_handler() (line 724 of /home/clients/websites/w_dc/public_html/dc/sites/all/modules/views/views.module).
I'm using the latest updates to drupalcommerce pulled directly from rszrama/drupalcommerce just a few minutes ago, and the latest Views -dev release also downloaded just a few minutes ago.
By "patch pending for Views" I assume you mean http://drupal.org/node/722180 ? I applied that without a problem, but it didn't change the error message I got when trying to import your Views code above.
Curious - I guess I didn't
Curious - I guess I didn't actually try importing it... I wonder if there's a bug in export / import for Views with relationships? DamZ told me to always assume it's a Views bug. : P
The errors come from these
The errors come from these two blocks of code:
/* Relationship: Fields: Referenced product */
/* Field: Fields: field_product */
Removing those blocks allows the view to import, but of course it doesn't have the needed functionality then.
Hmm, ok, so I'm not sure what
Hmm, ok, so I'm not sure what the deal is. I just imported the View into my test site and it worked just fine. Gonna rebuild my site and try it with a clean DB, but as it is now I'm running a clean copy of my repo with the patched Views (although it does look like my patch has already been accepted).
Worked fine on a clean
Worked fine on a clean install, too... I wonder if something has changed in Views to break relationship importing? Will try tomorrow with the latest Views code from CVS.
Just a heads up - this View
Just a heads up - this View won't work atm because I've committed a patch from pcambra updating the names of the Views handlers.
Finally got around to
Finally got around to re-rolling this View since the commits surrounding pcambra's work. It works fine for me on a local dev site, and I'll get it online ASAP. Will be presenting it tomorrow at DrupalCamp Colorado. : )
Where can I find the catalog
Where can I find the catalog views used in the demo site?
Are there any issue filed for including default catalog views? I can probably work on that if you give me some directions.
Thanks!
I need a default catalog view too
I'm in the same boat as Henrique and I'd like to get a new site running in a few months and would like to work out as many issues as I can in advance. Trying to import that code to define a view gives the errors listed above in drupal7alpha6.
Is code available for the demo site on the catalog views? I can also try to assist if I can get some pointers.
Thanks for any help you can provide.
This view is not working in drupal 7.0-beta1
I downloaded Drupal 7.0-beta1 and DC 7.x-1.x-dev (Oct 12) and I'm still getting errors importing the view listed above. Here are the errors reported from a MAMP installation under OS X. Any help getting past these errors would be much appreciated!
Debug: 'Missing handler: field_data_field_product entity_id field' in views_get_handler() (line 733 of /Applications/MAMP/htdocs/drupal-7.0-beta1/sites/all/modules/views/views.module).
Debug: 'Missing handler: field_data_field_product field_product_product_id relationship' in views_get_handler() (line 733 of /Applications/MAMP/htdocs/drupal-7.0-beta1/sites/all/modules/views/views.module).
Debug: 'Missing handler: field_data_field_product entity_id field' in views_get_handler() (line 733 of /Applications/MAMP/htdocs/drupal-7.0-beta1/sites/all/modules/views/views.module).
Debug: 'Missing handler: field_data_field_product field_product_product_id relationship' in views_get_handler() (line 733 of /Applications/MAMP/htdocs/drupal-7.0-beta1/sites/all/modules/views/views.module).
I was able to get the view
I was able to get the view created by changing these items in the snippet above so they match the column names in the DB tables:
1) Change field_data_field_product to field_data_product
2) Change field_product_product_id to product_product_id
However, even though the view can be defined, I get this error when attempting to preview the newly defined view:
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /drupal-7.0-beta1/admin/structure/views/ajax/preview/Catalog
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_product_id' in 'on clause': SELECT COUNT(*) AS expression
FROM
(SELECT node.nid AS nid, node.title AS node_title, commerce_product_field_data_product__field_data_base_price.entity_id AS commerce_product_field_data_product__field_data_base_price_e, commerce_product_field_data_product__field_data_base_price.etid AS commerce_product_field_data_product__field_data_base_price_e_1, entity_id AS entity_id, etid AS etid, 1 AS expression
FROM
{node} node
INNER JOIN {commerce_product} commerce_product_field_data_product ON product_product_id = commerce_product_field_data_product.product_id
LEFT JOIN {field_data_base_price} commerce_product_field_data_product__field_data_base_price ON commerce_product_field_data_product.product_id = commerce_product_field_data_product__field_data_base_price.entity_id AND commerce_product_field_data_product__field_data_base_price.etid = :views_join_condition_0
WHERE (( (node.status <> :db_condition_placeholder_0) AND (node.type IN (:db_condition_placeholder_1)) ))) subquery; Array
(
[:db_condition_placeholder_0] => 0
[:db_condition_placeholder_1] => product
[:views_join_condition_0] => 4
)
in views_plugin_pager->execute_count_query() (line 141 of /Applications/MAMP/htdocs/drupal-7.0-beta1/sites/all/modules/views/plugins/views_plugin_pager.inc).
The concept shown in this
The concept shown in this view worked for me. However, I did run into a problem with attributes. Specifically when you have multiple products referenced by 1 display, I only want the first product to show up on the catalog. With this view all the attributed products show up as separate catalog items.
How can we work this out? I'm
How can we work this out?
I'm facing the same problem can somebody explain how it can be managed because I have 3 different views facing the same problem and don't find a proper solution...
Im working, with last dev of
Im working, with last dev of views and commerce, and from first i had the same problem with multiple products referenced by 1 display.
After that im put inside a views a display content id field ,maked it exclude from display and in Query Settings im checked "Distinct" option so now its working ok.
I made this option in "page" view and "default" display of view saparate, becuase views have still viewd behaviour some times its just not working or not showing the changes, im thing problem is vith cache, so try to empty cache for views and a page too, more than one time.
If still will not work i can sent a screen of my config or exactly the steps how i did it.
Just give me know.
Hi Yuri, A screenshot of
Hi Yuri,
A screenshot of your settings would be most appreciated.
When I move into a fields based view, (with product reference in my relationships) - I can choose to display price as a field, I have every product attribute variation in my display (even if the price is consistent between a product with multiple attribute settings).
'distinct' is set in query settings, but it doesn't seem to do be affecting the price field.
This seems to be a MUST HAVE
This seems to be a MUST HAVE for any eCommerce module, to present product into a catalog view style. Prestashop or Magento have this natively. Is there a way to create such a view with Commerce?