Discussions

Product catalog with terms and nodes

Hi all!!

I have a product taxonomy which it has hierarchy product categories. The taxonomy looks like this:

vocabulary
    term1
       term1.1
           term1.2
               PD1
               PD2
    term2
        term2.1
            PD3
    term3
       PD4

As you can see the product display node can only be on a sheet of the hierarchy. That is, in the above example on term1.2, term2.1 and term3. I am interested in a view that lists subterms when I click on a non-sheet term with all its fields (including image field) and when I click on a sheet term lists only product display nodes belonging to that taxonomy term.

How can I do that on Views?

Thank you very much.

Best regards.

Posted: Aug 11, 2013

Comments

joshmiller Josh Miller on August 12, 2013

So this is easier to show than it is to write about...

STEP BY STEP

1) Create a Taxonomy Vocabulary here: admin/structure/taxonomy (And create a few terms)

2) Create a Taxonomy View here: admin/structure/views/add

You want to make sure that you choose "taxonomy" entities.

3) Add a contextual filter for "Taxonomy term: Parent term"

Make sure to select "Default Filter" and choose "Taxonomy term from url." Also, specify a "Default validation criteria" for "Taxonomy term" and choose "Convert taxonomy name to ID" and select "Transform dashes in url..."

4) Add a new page to this view, remove the contextual filter from this view and add a filter for "Taxonomy term: Parent term" and set it to "equal to" and leave the field there blank.

5) Save that view and create a new view here: admin/structure/views/add

Make sure this view is a for "Content" of type "Product Display" (or whatever entity bundle has the field for your taxonomy terms).

6) Add a contextual filter for your taxonomy term, mine was called "Product Categories"

Make sure this contextual filter displays "Contents of No Results." Also, specify a "Default validation criteria" for "Taxonomy term" and choose "Convert taxonomy name to ID" and select "Transform dashes in url..."

7) Add a "No results" item called a "View Area" and select "Page_1" from your first view (this is the second page we created)

8) Save this view and go back to the first view.

9) Add a "No results" item called a "View Area" and select the second view that we just made.

10) Make sure your title field in the Taxonomy View doesn't link to the taxonomy term, but it outputs the field as a link to "catalog/[name]" that way your catalog names are clickable :)

11) Profit!

ekth0r on August 13, 2013

Hi Josh!

You are the F***G master! You solved my issue! Thank you very much! You are worthy of a beer! ;-)

benoitl13 on August 14, 2013

I need to build a catalog for woodstove and fireplaces. In my menu, I have different levels:
Level 1 - Product Type (fireplace, woodstove, bbq, etc.)
Level 2 - Type of combustible(wood, gaz, propane, ethanol, etc.)
Level 3 - Manufacturer (Name 1, Name 2, etc.)
Level 4 - Series (Serie A, Serie B, Seri C...)

Now what I was thinking was to create a different taxonomy per level so that when the user create the product, he can associate the appropriate terms based on what he needs. Now here's where I am stuck:
If I click on a level 1 term, I want to be presented all terms that belongs to level 2 and associated to products that has the level 1 term (kind of a filter).
If I click on a level 2 term, same thing but for level 3
If I click on a level 3 term, same thing but for level 4...and so on...

The thing is that I could have one manufacturer for different type of products, different type of combustibles and I don't want the user to repeat the term again and again and making the catalog hard to manage...

joshmiller Josh Miller on August 20, 2013

You're in luck! I just posted another video that walks through this.

PRE-FLIGHT CHECKLIST

Before you walkthrough the video and the step-by-step below, make sure you have three taxonomy vocabularies with three taxonomy terms each. Additionally, confirm your Product Display has a field per taxonomy field.

STEP BY STEP

1) Create a View: admin/structure/views/add
- Call it "Catalog" and leave the "page" selected
- Show type "Taxonomy" for Level 1
- Click "Continue"

2) Edit the field that shows for this taxonomy
- Rewrite the output and select "output this field as a link"
- Choose the path to be "catalog/[name]" and select to convert spaces to dashes

3) Create a new view: admin/structure/views/add
- Call this view "Catalog - Products"
- Change name to "Catalog" and url to "catalog"
- Show "Content" of type "Product Display"

4) Edit the view by doing the following:
- Change the path to "catalog/%/%/%"
- Add a contextual filter for all three Taxonomy Vocabulary Fields that you added in Preflight
- Add a relationship for all three Taxonomy Vocabulary Fields that you added in Preflight
- Call this display "Products"

5) Add a new page
- Change the path to "catalog/%/%"
- Change the name of the display to "Level 3"
- Remove the Level 3 contextual filter FOR THIS PAGE ONLY
- Change the Content Format to "Fields" FOR THIS PAGE ONLY
- Remove the title field and add a Taxonomy term name field
- Change the relationship to be level 3 relationship
- Modify the output of the taxonomy term name field to output a link to "catalog/%1/%2/[name]"
- Check the "Convert spaces to dashes" checkbox

6) Add a page
- Path should be "catalog/%"
- Change Display to be called "Level 2"
- Remove Level 3 and Level 2 contextual filters FOR THIS PAGE ONLY
- Change Display format to Fields FOR THIS PAGE ONLY
- Modify the taxonomy term name relationship to be Level 2
- Modify the output of the taxonomy term name field to output a link to "catalog/%1/[name]"
- Check the "Convert spaces to dashes" checkbox

7) Profit!

bisonbleu on March 30, 2015

See update at end of post.

Hey Josh, thanks for 2 great tutorials. Really helpful!

I'm seeing requests here and on d.o (see CK2 issues 2329087 & 2198765) for a common use case where one adds child terms to the terms of the Product category vocab. Under such circumstances, it makes sense to not only display products tagged with the parent term but also those that are tagged with its child terms.

Unfortunately, the Taxonomy: Term ID (with depth)" contextual filter is not available in the Collection products (Product display) view.

Any idea how we can solve this in CK2 ?
Cheers!

UPDATE: found a workaround. Works great. Can you please advise whether or not this has adverse effects elsewhere in CK2 ?

Argus on August 16, 2013

Nice explanation, thanks for that! I was wondering if it is possible to get this to work with the search-api products page that Commerce Kickstart uses? I've been trying to mimic it for those pages but can't get it to work. Another point is if you use term names instead of TID, you cannot use the same term in different branches.

edit: I got the search-api page working using Content: Product Category (field_product_category) as contextual filter, same settings as in the example. No idea why it didn't work before.

najim on October 29, 2013

Hi Josh

Well thank you for this screencast, i have a similar taxonomy implementation like above, everythings comes from one vocabulary, except in my situation a product can be classified under multiple terms at any level i.e at term1.2 and term3.

The catalog bit is just fine but i want the node to have a url pattern that contain the full path of the parent and child term if any plus the node title

In my implentation i have the following alias products/[node:field_product_category]/[node:title] where field_product_category is the term reference field

this is not working out fine for me because the resulting url path is missing the major parent i.e PD3 url path is only containing url as such
products/term2.1/pd3

instead of products/term2/term/2.1/pd3 in that hierarchy, will be grateful to get a response from any viewer.

seismicmike on December 6, 2013

Josh,

This was extremely helpful to me on a project I'm working on, but my use case is ever so slightly more complicated than this in that there can be products and terms at the same level in my use case. Having set up the views in your video, I can either see terms or products at each level. In those cases, I'd like to display folders at the top and files underneath.

What I ended up doing is moving the product view out of the "No Results Behavior" and putting it in the Footer instead.

The one thing I'm still working on, though.... how would I add a breadcrumb link to allow the user to easily browse up to view the parent term? In other words, if I'm looking at Niche Category 1 under Minor Category 1, how would I add a link to go up to view Minor Category 1?

joshmiller Josh Miller on December 10, 2013

It's possible that some combination of one of the many breadcrumb modules in Drupal would help. The problem is determining "one" minor category. But if we assume niches always only have one parent, then I would create a view gives us the parent and grandparent of a niche term and call it "breadcrumbs."

Untested, but should be feasible with some combination of embeddable views.

seismicmike on December 12, 2013

I appreciate the feedback, but we're pushing breadcrumbs to a future release. For now, I'm getting an odd issue with the view in that on the "front page" (no arguments... displays the Major Categories") there is an error message:

Notice: Undefined offset: 1 in _menu_translate() (line 777 of includes/menu.inc).

I would guess that it has something to do with the missing argument, but haven't found the solution yet.

If you know anything about it, that would be helpful. Thanks :)

Mja388 on January 20, 2014

Hi Josh
This tutorial is superb! Do you happen to know if there are any issues using this with taxonomy menu? I've been trying to get the two working together but as soon as I add taxonomy menu to my product categories taxonomy I get "no results in secondary category. No products to show. And the the list of my primary categories." But when I click on one of those, rather than get tongs a list of my sub categories, I get "there is currently no content classified with this term".
Any advice would be greatly received.
Many thanks.

ekth0r on August 15, 2013

Hi Josh!

Is this possible to do with the taxonomy base path? That is, /taxonomy/term/%.

Thanks in advance!! :-)

maryts85 on October 27, 2013

Hi Josh,

Fabulous tutorial by the way. Loved it!

I've been trying to do the same thing you did but instead of using 'page', I used 'block'. Couldn't get nowhere. Can this be done using 'block' instead?

What I am actually trying to do is using Taxonomy menu and selecting a parent term, I want a list of nodes which are assigned to child terms.

E.g.

Parent term 1
   - Child term 1
       - Prod 1
       - Prod 2
       - Prod 3
   - Child term 2
       - Prod 4
Parent term 2
   - Child term 1
       - Prod 1
 

So if I click on 'Parent term 1', I want 'Prod 1, Prod 2, Prod 3 and Prod 4' to be displayed in another block and page also. If I click on 'Child term 1', I want 'Prod 1, Prod 2 and Prod 3' to be displayed. So I thought configuring the Depth from 0 to 2 on the 'Contextual Filters' in 'Content: Has taxonomy term ID (with depth)' Taxonomy term view, will solve my case. But it hasn't. The nodes appear only when I click on say 'Child term 1'. They don't appear when I click on say 'Parent term 1'.

So I thought maybe I could accomplish something similar by following your tutorial using 'block' instead.

Do you think there may be a workaround to my issue? Have been searching everywhere for something that might work. Came across to your tutorial.

Thanks in advance.

drupkirchroa kirchroa on July 29, 2014

I really loved this tutorial and it works perfectly! Thanks.

But what I love to create is a different few in various levels.

In the 'Major' view i would like to show a few minor terms by every major term. And at the 'minor-view' page i would like to show 3 nodes which are related to that term. Is this possible?

Ann B on August 28, 2014

Hello,

I can't say enough positive things about the Multi-vocabulary Hierarchy Views Catalog tutorial on youtube. It is so helpful. Thank you very much for posting.

The only question I have is if it is possible to display a menu block on the level 2+ pages. My menu block displays fine on the level 1 page (the separate view we first created that just displays the taxonomy items for the level 1 vocabulary and no contextual filters used). But starting with level 2 (the separate view we created that uses contextual filters) the menu block disappears. Can you provide any guidance? I know I might need to ask the Views or Menu Block (or even Core) maintainers.

Thanks again,
Ann