Is it possible to add a media file to a variant entirely from code? The imagefile i want to add already exists in the media library. Is it possible to update the Image field directly or would i need to connect the variant to the file with a pointer?
Hi,
If you want to add a media file entirely from code you have to do do somthing like that:
You have to inject the variant service in the constructor of your class.
var variant = _variantService.Get("your variant id or system id");
variant = variant.MakeWritableClone()
// image ids is a list of Guid that contains all the image ids that will be connected to the variant
variant.Fields.AddOrUpdateValue(SystemFieldDefinitionConstants.Images, imageIds);
_variantService.Update(variant);