Sitefinity - Ecommerce - How to get all tags currently associated with any given product.
I have been searching for solutions or hints and can't seem to find any on this. I have a custom set of drop down menus on my master file. Those drop down menus assign a value to session variables that I want to use to filter results from default "Product List" widget. I have considered options to pass a query string like one of the telerik support technicians suggested. The only query string that I see that can filter products, do so on a SINGLE tag like this: http://localhost:60393/EC/the-store/-in-Tags/Tags/blue
Although not sure there is a version of that querystring that can use a "OR" for example show me all products with tag1 OR tag2 OR tag3 attached to them.
So, this all led me to research a way to manually databind product list with required tags in a repeater or something. But then I can't figure out how to filter tags. SOOOO......(drum-roll)
My question is: What line of code can I use to return a list of tags already associated with any given Product.id? (In the ecommerce context)
I figure, I would have to use these two managers below:
CatalogManager cmanager = CatalogManager.GetManager();
TaxonomyManager tmanager = TaxonomyManager.GetManager();
IQueryable<
Product
> allProducts = cmanager.GetProducts();
Hello, James.
Yes it is possible and here is how:
CatalogManager catalogManager = CatalogManager.GetManager();
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
var products = catalogManager.GetProducts();
// Get the taxonomy for "Tags"
FlatTaxonomy tagTaxonomy = taxonomyManager.GetTaxonomies<FlatTaxonomy>().Where(t => t.Name ==
"Tags"
).SingleOrDefault();
foreach
(Product product
in
products)
// get IDs of all tags associated with this product
var tagIds = product.GetValue<TrackedList<Guid>>(
"Tags"
);
foreach
(Guid tagId
in
tagIds)
// get the Tag taxon from its Id
Taxon tag = tagTaxonomy.Taxa.Where(x => x.Id == tagId).SingleOrDefault();
// your code to manipulate the tag goes here
using
Telerik.Sitefinity.Modules.Ecommerce.Catalog;
using
Telerik.Sitefinity.Taxonomies;
using
Telerik.Sitefinity.Taxonomies.Model;
using
Telerik.Sitefinity.Model;
using
Telerik.Sitefinity.Ecommerce.Catalog.Model;
using
Telerik.OpenAccess;
Randy,
I was sooo close. I really appreciate your help! That is exactly what I needed!
This tiny snippet of code will allow me to do many things with my Sitefinity website, so it is very much appreciated. Thanks again man!
James