Edit "collection products" view: show child items
Hello,
I'm trying to modify the default "collection products" view because I have a lot of sub-categories.
For example, in the "Sample Category 1" I have a list of sub-categories with relative products.
I added the sub-catergories as child taxonomy terms of "Sample Category 1" but if I click the link "Sample Category 1" in the homepage, the view returns only the products that are in that Category and not in the child categories.
Is there a solution for displaying products that are child of the main category?
Thanks!!!
Comments
In your view you can change
In your view you can change the 'Contextual filters' ( right hand column ) to be "Content: Has taxonomy term ID (with depth)". That will select the descendants of the term and should give you what you're after.
Sorry but in the available
Sorry but in the available filters I don't have that... And the actual contextual filter is "Indexed Node: Product category" that refers to filed "field_product_category", so I suppose that it isn't a taxonomy view.
I'm talking about the DEFAULT view "Collection products".
Sorry but in the available
Sorry but in the available filters I don't have that... And the actual contextual filter is "Indexed Node: Product category" that refers to filed "field_product_category", so I suppose that it isn't a taxonomy view.
I'm talking about the DEFAULT view "Collection products".
Sorry, 1/ for the delay - I
Sorry, 1/ for the delay - I only just got notification that you replied and 2/ For assuming that the site I was looking at was using the default collection view. It wasn't. I don't have much time today, so here is a paste of the view that a different site is using.
You'll need to change the names, fields & urls etc but it works for showing all of the node of child categories on the parent page.
If you're not able to use the below post back and I'll see if I can make it more general when i have a chance. I suspect it's just a modification of the standard Views taxonomy replacement view.
$view = new view();
$view->name = 'taxonomy_term';
$view->description = 'A view to emulate Drupal core\'s handling of taxonomy/term.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Taxonomy term';
$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['css_class'] = 'view-collection-products';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['expose_sort_order'] = FALSE;
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Content: Referenced products */
$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'] = TRUE;
/* Relationship: Content: Taxonomy terms on node */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
'blog_category' => 0,
'brand' => 0,
'food_and_groceries' => 0,
'ingredients' => 0,
'tags' => 0,
);
/* Relationship: Commerce Product: Referencing Node */
$handler->display->display_options['relationships']['field_product']['id'] = 'field_product';
$handler->display->display_options['relationships']['field_product']['table'] = 'commerce_product';
$handler->display->display_options['relationships']['field_product']['field'] = 'field_product';
$handler->display->display_options['relationships']['field_product']['relationship'] = 'field_product_product_id';
/* Field: Content: 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']['element_label_colon'] = FALSE;
/* Field: Content: Path */
$handler->display->display_options['fields']['path']['id'] = 'path';
$handler->display->display_options['fields']['path']['table'] = 'node';
$handler->display->display_options['fields']['path']['field'] = 'path';
$handler->display->display_options['fields']['path']['label'] = '';
$handler->display->display_options['fields']['path']['exclude'] = TRUE;
$handler->display->display_options['fields']['path']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['path']['absolute'] = TRUE;
/* Field: Field: Images */
$handler->display->display_options['fields']['field_images']['id'] = 'field_images';
$handler->display->display_options['fields']['field_images']['table'] = 'field_data_field_images';
$handler->display->display_options['fields']['field_images']['field'] = 'field_images';
$handler->display->display_options['fields']['field_images']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['field_images']['label'] = '';
$handler->display->display_options['fields']['field_images']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['field_images']['alter']['path'] = '[path]';
$handler->display->display_options['fields']['field_images']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_images']['type'] = 'image_delta';
$handler->display->display_options['fields']['field_images']['settings'] = array(
'deltas' => '0',
'deltas_reversed' => 0,
'image_style' => 'product_thumbnail',
'image_link' => '',
);
$handler->display->display_options['fields']['field_images']['delta_offset'] = '0';
/* Field: Content: 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']['label'] = '';
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Brand */
$handler->display->display_options['fields']['field_brand']['id'] = 'field_brand';
$handler->display->display_options['fields']['field_brand']['table'] = 'field_data_field_brand';
$handler->display->display_options['fields']['field_brand']['field'] = 'field_brand';
$handler->display->display_options['fields']['field_brand']['alter']['text'] = 'Brand:';
$handler->display->display_options['fields']['field_brand']['element_type'] = '0';
$handler->display->display_options['fields']['field_brand']['element_wrapper_type'] = 'div';
$handler->display->display_options['fields']['field_brand']['hide_empty'] = TRUE;
/* Field: Content: Product variations */
$handler->display->display_options['fields']['field_product']['id'] = 'field_product';
$handler->display->display_options['fields']['field_product']['table'] = 'field_data_field_product';
$handler->display->display_options['fields']['field_product']['field'] = 'field_product';
$handler->display->display_options['fields']['field_product']['label'] = '';
$handler->display->display_options['fields']['field_product']['element_type'] = '0';
$handler->display->display_options['fields']['field_product']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_product']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['field_product']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['field_product']['settings'] = array(
'show_quantity' => 1,
'default_quantity' => '1',
'combine' => 1,
'show_single_product_attributes' => 0,
'line_item_type' => 'product',
);
$handler->display->display_options['fields']['field_product']['delta_offset'] = '0';
/* Sort criterion: Content: Sticky */
$handler->display->display_options['sorts']['sticky']['id'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['table'] = 'node';
$handler->display->display_options['sorts']['sticky']['field'] = 'sticky';
$handler->display->display_options['sorts']['sticky']['order'] = 'DESC';
/* Sort criterion: Commerce Product: Title */
$handler->display->display_options['sorts']['title']['id'] = 'title';
$handler->display->display_options['sorts']['title']['table'] = 'commerce_product';
$handler->display->display_options['sorts']['title']['field'] = 'title';
$handler->display->display_options['sorts']['title']['relationship'] = 'field_product_product_id';
/* 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_argument_type'] = 'fixed';
$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']['depth'] = '10';
$handler->display->display_options['arguments']['term_node_tid_depth']['set_breadcrumb'] = TRUE;
/* Contextual filter: Content: Has taxonomy term ID depth modifier */
$handler->display->display_options['arguments']['term_node_tid_depth_modifier']['id'] = 'term_node_tid_depth_modifier';
$handler->display->display_options['arguments']['term_node_tid_depth_modifier']['table'] = 'node';
$handler->display->display_options['arguments']['term_node_tid_depth_modifier']['field'] = 'term_node_tid_depth_modifier';
$handler->display->display_options['arguments']['term_node_tid_depth_modifier']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['term_node_tid_depth_modifier']['summary']['format'] = 'default_summary';
/* Filter criterion: Content: Published or admin */
$handler->display->display_options['filters']['status_extra']['id'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['table'] = 'node';
$handler->display->display_options['filters']['status_extra']['field'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['group'] = 0;
$handler->display->display_options['filters']['status_extra']['expose']['operator'] = FALSE;
/* Filter criterion: Commerce Product: Status */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'commerce_product';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['relationship'] = 'field_product_product_id';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['relationships'] = FALSE;
/* Relationship: Content: Referenced products */
$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'] = TRUE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* 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'] = 'not found';
$handler->display->display_options['arguments']['term_node_tid_depth']['default_argument_type'] = 'fixed';
$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']['depth'] = '10';
$handler->display->display_options['path'] = 'taxonomy/term/%';
/* Display: Feed */
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = 15;
$handler->display->display_options['style_plugin'] = 'rss';
$handler->display->display_options['row_plugin'] = 'node_rss';
$handler->display->display_options['path'] = 'taxonomy/term/%/%/feed';
$handler->display->display_options['displays'] = array(
'page' => 'page',
'default' => 0,
);
/* Display: Food and Groceries */
$handler = $view->new_display('page', 'Food and Groceries', 'page_1');
$handler->display->display_options['display_description'] = 'Node listings for the Vocab';
$handler->display->display_options['defaults']['relationships'] = FALSE;
/* Relationship: Content: Referenced products */
$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'] = TRUE;
/* Relationship: Content: Taxonomy terms on node */
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
$handler->display->display_options['relationships']['term_node_tid']['required'] = TRUE;
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
'food_and_groceries' => 'food_and_groceries',
'blog_category' => 0,
'brand' => 0,
'ingredients' => 0,
'tags' => 0,
);
/* Relationship: Taxonomy term: Content using Product category */
$handler->display->display_options['relationships']['reverse_field_product_category_node']['id'] = 'reverse_field_product_category_node';
$handler->display->display_options['relationships']['reverse_field_product_category_node']['table'] = 'taxonomy_term_data';
$handler->display->display_options['relationships']['reverse_field_product_category_node']['field'] = 'reverse_field_product_category_node';
$handler->display->display_options['relationships']['reverse_field_product_category_node']['relationship'] = 'term_node_tid';
$handler->display->display_options['relationships']['reverse_field_product_category_node']['required'] = TRUE;
/* Relationship: Content: Brand (field_brand) */
$handler->display->display_options['relationships']['field_brand_tid']['id'] = 'field_brand_tid';
$handler->display->display_options['relationships']['field_brand_tid']['table'] = 'field_data_field_brand';
$handler->display->display_options['relationships']['field_brand_tid']['field'] = 'field_brand_tid';
$handler->display->display_options['relationships']['field_brand_tid']['required'] = TRUE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: 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']['element_label_colon'] = FALSE;
/* Field: Content: Path */
$handler->display->display_options['fields']['path']['id'] = 'path';
$handler->display->display_options['fields']['path']['table'] = 'node';
$handler->display->display_options['fields']['path']['field'] = 'path';
$handler->display->display_options['fields']['path']['label'] = '';
$handler->display->display_options['fields']['path']['exclude'] = TRUE;
$handler->display->display_options['fields']['path']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['path']['absolute'] = TRUE;
/* Field: Field: Images */
$handler->display->display_options['fields']['field_images']['id'] = 'field_images';
$handler->display->display_options['fields']['field_images']['table'] = 'field_data_field_images';
$handler->display->display_options['fields']['field_images']['field'] = 'field_images';
$handler->display->display_options['fields']['field_images']['relationship'] = 'field_product_product_id';
$handler->display->display_options['fields']['field_images']['label'] = '';
$handler->display->display_options['fields']['field_images']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['field_images']['alter']['path'] = '[path]';
$handler->display->display_options['fields']['field_images']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_images']['click_sort_column'] = 'fid';
$handler->display->display_options['fields']['field_images']['type'] = 'image_delta';
$handler->display->display_options['fields']['field_images']['settings'] = array(
'deltas' => '0',
'deltas_reversed' => 0,
'image_style' => 'product_thumbnail',
'image_link' => '',
);
$handler->display->display_options['fields']['field_images']['delta_offset'] = '0';
/* Field: Content: 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']['label'] = '';
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Brand */
$handler->display->display_options['fields']['field_brand']['id'] = 'field_brand';
$handler->display->display_options['fields']['field_brand']['table'] = 'field_data_field_brand';
$handler->display->display_options['fields']['field_brand']['field'] = 'field_brand';
$handler->display->display_options['fields']['field_brand']['alter']['text'] = 'Brand:';
$handler->display->display_options['fields']['field_brand']['element_type'] = '0';
$handler->display->display_options['fields']['field_brand']['element_wrapper_type'] = 'div';
$handler->display->display_options['fields']['field_brand']['hide_empty'] = TRUE;
/* Field: Content: Product variations */
$handler->display->display_options['fields']['field_product']['id'] = 'field_product';
$handler->display->display_options['fields']['field_product']['table'] = 'field_data_field_product';
$handler->display->display_options['fields']['field_product']['field'] = 'field_product';
$handler->display->display_options['fields']['field_product']['label'] = '';
$handler->display->display_options['fields']['field_product']['element_type'] = '0';
$handler->display->display_options['fields']['field_product']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_product']['element_wrapper_type'] = '0';
$handler->display->display_options['fields']['field_product']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['field_product']['settings'] = array(
'show_quantity' => 1,
'default_quantity' => '1',
'combine' => 1,
'show_single_product_attributes' => 0,
'line_item_type' => 'product',
);
$handler->display->display_options['fields']['field_product']['delta_offset'] = '0';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Taxonomy vocabulary: Vocabulary ID */
$handler->display->display_options['arguments']['vid']['id'] = 'vid';
$handler->display->display_options['arguments']['vid']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['arguments']['vid']['field'] = 'vid';
$handler->display->display_options['arguments']['vid']['relationship'] = 'term_node_tid';
$handler->display->display_options['arguments']['vid']['default_action'] = 'default';
$handler->display->display_options['arguments']['vid']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['vid']['title'] = '%1';
$handler->display->display_options['arguments']['vid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['vid']['default_argument_options']['argument'] = '3';
$handler->display->display_options['arguments']['vid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['vid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['vid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['vid']['specify_validation'] = TRUE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Content: Published or admin */
$handler->display->display_options['filters']['status_extra']['id'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['table'] = 'node';
$handler->display->display_options['filters']['status_extra']['field'] = 'status_extra';
$handler->display->display_options['filters']['status_extra']['group'] = 0;
$handler->display->display_options['filters']['status_extra']['expose']['operator'] = FALSE;
$handler->display->display_options['path'] = 'food-and-groceries';
$handler->display->display_options['menu']['title'] = 'Food and Groceries';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
Thank you veru much and don't
Thank you veru much and don't worry for the delay!
Index hierarchy
Hi,
You need to enable "Index hierarchy" on /admin/config/search/search_api/index/product_display/workflow. This allows to index hierarchical fields along with all their ancestors.
Next under "Callback settings" and the "Index hierarchy" tab, you'll have to enable the field you wish to index the hierarchy for (presumably Product category > Parent terms).
Kind regards