Assuming that the problem is not getting any propterydata on the clone.
You need to call save on the clone, "repository.Save(clone, SaveAction.Publish);" for the change to be persistant.
/Oskar
Oskar's answer is correct - the change to any content (not just catalog content, but also CMS content) needs to be explicitly saved. It'll not be saved automatically when you set it.
Apparently I didn't read the question carefully, for IContentEvents you don't have to publish it explicitly
Not working as aspected:
Both tried with
var content = e.Content as RouteProductContent;
if (content.IconImage != null) return;
var parentContentReference = content.ParentLink;
var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var category = repository.Get<SondermautCategoryNodeContent>(parentContentReference);
if (category?.IconImage != null)
{
var clone = content.CreateWritableClone();
clone.Property["IconImage"].Value = category.IconImage;
repository.Publish(clone);
}
and with
repository.Save(clone);
On publishing event and published event.
Not saving the value
Trying to set a fallback image on a product.
Trying to get it from parent (that is category)
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ContentEvents : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var events = context.Locate.ContentEvents();
events.PublishingContent += EventsPublishingContent;
}
private void EventsPublishingContent(object sender, ContentEventArgs e)
{
if (e.Content is RouteProductContent)
{
var content = e.Content as ProductContent;
if (content.IconImage != null) return;
var parentContentReference = content.ParentLink;();(parentContentReference);
var repository = ServiceLocator.Current.GetInstance
var category = repository.Get
if (category.IconImage != null)
{
var clone = content.CreateWritableClone() as RouteProductContent;
clone.Property["IconImage"] = new PropertyContentReference(category.IconImage);
// have also tried with
clone.Property["IconImage"].value = category.IconImage;
// and
clone.IconImage = category.IconImage;
}
}
}
public void Uninitialize(InitializationEngine context)();
{
var contentEvents = ServiceLocator.Current.GetInstance
contentEvents.PublishingContent -= EventsPublishingContent;
}
}