This project is read-only.

Copy and reset value

Feb 22, 2009 at 4:13 PM
Hi,

what would be the (best) way to reset an attribute value when an item is copied?
I have an attribute which is set to readonly which displays the number of items sold. This value is updated by code.
When the item (product) is copied to be used as the basis of a new product I would like to reset the value of this attribute to 0....

Thanks!

Martijn
Feb 22, 2009 at 9:56 PM
I would probably go for the clone method on the content item or the itemcopying event on the persister.
Feb 23, 2009 at 8:22 AM
Thanks, again an easy way :-)
Extended the clone method like this:

public override ContentItem Clone(bool includeChildren)
    {
        ContentItem clonedItem = base.Clone(includeChildren);
        ContentDetail detAantalGekocht = clonedItem.Details.ContainsKey("AantalGekocht")
                                             ? clonedItem.Details["AantalGekocht"]
                                             : null;
        if(detAantalGekocht != null) detAantalGekocht.Value = 0;
        return clonedItem;
    }