public static void AddTagsToProduct(Guid productId, string tagTitle)
{
CatalogManager catalogManager = CatalogManager.GetManager();
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
// Get the product
Product product = catalogManager.GetProduct(productId);
if (product == null)
{
return; // Product does not exist
}
// Get the taxonomy for "Tags"
Taxonomy tagTaxonomy = taxonomyManager.GetTaxonomies<Taxonomy>().Where(t => t.Name == "Tags").SingleOrDefault();
if (tagTaxonomy == null)
{
return; // The "Tags" taxonomy does not exist
}
//Get the tag
Taxon taxon = tagTaxonomy.Taxa.Where(t => t.Title == tagTitle).SingleOrDefault();
if (taxon == null)
{
return; //Taxon does not exist
}
product.Organizer.AddTaxa("Tags", taxon.Id);
catalogManager.SaveChanges();
}