2
Answers
Vote up!
1
Vote down!

How to add a Related Products View for Commerce Kickstart?

I am trying to show related products in the products display. I tried using the method outlined here: https://www.drupal.org/node/1465920 - but ran into a couple of issues:

1. The "Target Type" in the entity reference field (the field used for the related product) does not show "Node" as an option.

2. The SQL error mentioned in the tutorial appeared when selecting "Aggregate" in the view.

The bottom line is I couldn't get this to work of Commerce Kickstart.

Has anyone had any success in getting this to work for Kickstart, or an alternative approach?

Thanks in advance for any insight into this.

Scott Jenkins
Asked by: Scott Jenkins
on July 9, 2015

2 Answers

Vote up!
1
Vote down!

Hi Scott,

At the bottom is a simplistic related items block that selects 3 items with the same taxonomy term. If this will work for you then edit it to use a vocabulary and view mode that exist on your site and you should be good.

If it won't then what target types do you have in the entity reference field? Do you have 'Product display'?

=============================

$view = new view();
$view->name = 'related_items';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Related items';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'You may also love';
$handler->display->display_options['css_class'] = 'view-display-products';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '3';
$handler->display->display_options['style_plugin'] = 'list';
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['style_options']['class'] = 'all-products';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Rendered Content */
$handler->display->display_options['fields']['rendered_entity']['id'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['rendered_entity']['field'] = 'rendered_entity';
$handler->display->display_options['fields']['rendered_entity']['label'] = '';
$handler->display->display_options['fields']['rendered_entity']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['rendered_entity']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['rendered_entity']['link_to_entity'] = 1;
$handler->display->display_options['fields']['rendered_entity']['display'] = 'view';
$handler->display->display_options['fields']['rendered_entity']['view_mode'] = 'product_list';
$handler->display->display_options['fields']['rendered_entity']['bypass_access'] = 0;
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['nid']['not'] = TRUE;
/* Contextual filter: Content: Has taxonomy term ID (with depth) */
$handler->display->display_options['arguments']['term_node_tid_depth']['id'] = 'term_node_tid_depth';
$handler->display->display_options['arguments']['term_node_tid_depth']['table'] = 'node';
$handler->display->display_options['arguments']['term_node_tid_depth']['field'] = 'term_node_tid_depth';
$handler->display->display_options['arguments']['term_node_tid_depth']['default_action'] = 'default';
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_type'] = 'taxonomy_tid';
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_options']['term_page'] = FALSE;
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_options']['node'] = TRUE;
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_options']['limit'] = TRUE;
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_options']['vocabularies'] = array(
'collections' => 'collections',
);
$handler->display->display_options['arguments']['term_node_tid_depth']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['term_node_tid_depth']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['term_node_tid_depth']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['term_node_tid_depth']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['term_node_tid_depth']['depth'] = '0';
$handler->display->display_options['arguments']['term_node_tid_depth']['break_phrase'] = TRUE;
/* Filter criterion: Content: 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;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: 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_display' => 'product_display',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');

Andy @ BlueFusion
Posted: Jul 12, 2015

Comments

Hi Scott,

I had a look at that page and there seems to be an easier way to achieve the same outcome than there was when it was written. I've updated the instructions, if you have the time to try them out and can confirm they now work that would help a lot of people.

Cheers,

Andy

- Andy @ BlueFusion on July 14, 2015

Hi,
it would by great if You could explain step by step how to do it.

- 0xhiryuu on June 19, 2018
Vote up!
0
Vote down!

Hi, Andy,

I tried this solution myself and it works like a champ! My question is that is there anyway to prioritize the taxonomy vocabularies? I'm building an online bookstore and for example some of the taxonomies are Series, Population Group or Issues and say you want the Contextual filter to bring up results for Series first and Issues second. Can such further refinements be done?

Thank you for your help?
Kai

Answer by: kaicyee
Posted: Apr 13, 2017