I have a requirement to make a variant property readonly after the page's initial save. Does anyone know of a way that this can be achieved? I've tried playing around with the Editable and Readonly attributes, however these attributes do not seem to be able to do what I need (namely there is not enough finesse that allows for the readonly status to be conditional)
In case it makes a difference, the property that I need to change in this way is the Code property, and the property will need to be set.
One possible approach is
- Add a boolean property (FirstSave or something) to the variation content type.
- Listen to IContentEvents.SavingContent
- If the FirstSave is false, allow saving, otherwise throw exception or cancel event.
And you even don't have to add FirstSave property, just check the Last modified date or publish status (based on your criteria of "Save")
You could try looking into the IMetadataExtender interface (I have not tried this in Commerce), it allows you to interact with the property meta data programmatically (I am pretty sure you can mark the property as read only).
See these links for examples of using it: