What if you have a pre-existing catalog connection and your customer asks you to switch from a single value field (generally ItemCategory) to a multivalue field?
In a ideal world you should quote this and say "don't do it, don't even think about it"
In a business world you'll say "Yes, why not?".
I tried to convert the single value field in a multivalue field... trust me... don't try this if you don't like strange side effects.
AS IS
This is the typical product catalog configuration:
- A product catalog site which is used as backend website
- Contents are crawled by search service application
- Public sites connect to indexed catalog
Solution
To understand next steps, mind every link under categories navigation term is allowed.
Let's assume you have a term set like that
- Category 1
- Subcategory 11
- Subcategory 12
- Category 2
- Subcategory 21
http://site/category1
http://site/category1/subcategory11
http://site/category1/subcategory11
http://site/category2
http://site/category2/subcategory21
So let's assume i have a product named Test, which is tagged on ItemCategory with term "Subcategory 11", i'll go to URL http://site/category1/subcategory11/test .
But what if i tell you that links like these below will not repond with a 404?
http://site/category1/test
http://site/category1/subcategory12/test
http://site/category2/test
http://site/category2/subcategory21/test
This behaviour will be extremely useful for us.
Editing product catalog
Because you don't want to destroy catalog connection, you just have to add a TaxonomyFieldTypeMulti field to the product catalog item content type
Link this new field to the term set you use to tag catalog items.TextField {024FECDC-E8A7-4DAC-BEB1-E9C373708BE5}
After that, you can create a event receiver in order to write the first value entered in MultivalueItemCategory field in ItemCategory field (or the field you use for the catalog connection).
Create Content Search Web Part replacements
This is the most annoying part, we have to create a Web Part that we will use in category pages.
This web part does essentially three things:
- Recover the current navigation term
- Make a query searching che term related to the navigation term, in the MultivalueItemCategory we defined above
- Substitute Path values (catalog item friendly url) in order to make links relative to the current navigation term
- Show results
This web part, must get the product using the navigation term and the friendly url segment and show the result.
Editing publishing site
In pages document library, you have to create a category page (which contains the category CSWP replacement), and a product page (which contains the product CSWP replacement) and then edit target page settings for terms like this
And that's all folks.
0 commenti:
Post a Comment
Because of a lot of SPAM about courses, I need to moderate all comments here.
I ensure you that I will answer whenever possible (if you are not a spammer).