AI OnAI Off
You can add an indexing command in the OnPublished event for all variants of the products? Something like this
private static void AddToIndex(IEnumerable<IContent> itemsToAdd)
{
IContentIndexer contentIndexer = ServiceLocator.Current.GetInstance<IContentIndexer>();
contentIndexer.Index(
contentItems: itemsToAdd,
options: new IndexOptions { IndexAllLanguageVersions = true });
}
You can listen to IContentEvents.PublishedContent, check if the content published is Product or not, if yes, use IRelationRepository to load its variants, then index those.
Thank you so much Jeroen and Quan that work marvelously. I am posting the complete code for future references:
[InitializableModule]
[ModuleDependency(typeof(ServiceContainerInitialization))]
public class DependencyResolution : IConfigurableModule
{
private IContentEvents _contentEvents;
private Injected<IRelationRepository> _relationRepository;
private Injected<IContentLoader> _contentLoader;
private Injected<IContentIndexer> _contentIndexer;
public void Initialize(InitializationEngine context)
{
if (_contentEvents == null)
{
_contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
}
_contentEvents.PublishedContent += contentEvents_PublishedContent;
}
void contentEvents_PublishedContent(object sender, ContentEventArgs e)
{
if (e.Content is ProductContent product)
{
var variants = _relationRepository.Service.GetChildren<ProductVariation>(product.ContentLink);
AddToIndex(variants.Select(x => _contentLoader.Service.Get<IContent>(x.Child)));
}
}
private void AddToIndex(IEnumerable<IContent> itemsToAdd)
{
_contentIndexer.Service.Index(
contentItems: itemsToAdd,
options: new IndexOptions { IndexAllLanguageVersions = true });
}
public void Uninitialize(InitializationEngine context)
{
if (_contentEvents == null)
{
_contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>();
}
_contentEvents.PublishedContent -= contentEvents_PublishedContent;
}
public void ConfigureContainer(ServiceConfigurationContext context)
{
}
}
Hello,
I have created extension methods on my variant content like ProductDescription, ProductStyle, and ProductSubStyle. The values come from the parent product. If I update a variant item, their custom properties are indexed correctly in Epifind, but if I update their products (e.g. ProductDescription field), the custom field in the variants is not updated. How can I include the variant dependencies of products when indexing?