Try our conversational search powered by Generative AI!

Make a variant property readonly after the first save

Vote:
 

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.

#133499
Sep 07, 2015 18:30
Vote:
 

Hi,

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") 

Regards,

/Q

#133502
Edited, Sep 07, 2015 19:07
Vote:
 

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:

David

#133682
Edited, Sep 08, 2015 21:43
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.