When copying, the values that were set by SetDefaultValues on the original page are in the copied content item right? Which is what I would expect. SetDefaultValues only gets called when creating a new content item as far as I know.
You could attach some functionality to the CreatedContent or CreatingContent event. Set the values there?
Don't forget to check, in your case, if the item is copied
if (contentEventArgs.GetType() == typeof(CopyContentEventArgs)) { }
The method which Stemerdink suggested for detecting a product duplication works perfectly but I gave me some other issues.
The Content property on the contentEventArgs was NULL so I had to Get the content using the ContentRepository and the ContentLink. This was only possible at CreatedContent event (At the CreatingContent event both content and content link was NULL).
Now that I have the content, I tried to chance the product Code by assigning a new value to the property. This throws an exception stating that Code is read only. Anyone know how to change the product code programmably?
You can't change it when you create a WriteableClone?
Don't forget to save it again, probably you should force the current version when saving, else you get an extra version
If i create a writeableclone it's possible to update the code. I saved the clone with
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
contentRepository.Save(content, SaveAction.Publish, AccessLevel.NoAccess);
Thanks!
When a new product is created in our catalog we override the default product code suggested by episerver from the SetDefaultValue function. However, this function is not called when a product is duplicated and we want to suggest
Are there any way to default values when duplicating?