I have a case where I need to take an image generated in the client (a base64 string) and set it as a product image to be used in a flyout cart and the checkout. I am a bit unfamiliar with this particular project, but have a rough idea what the original author wanted to do.
I have partially succeeded by setting it as the product image, but it only seems to be cached for a while (an hour, according to the code), which means a user could leave the site and come back and the image has gone back to the default. The code for caching a different image in ShoppingCartController.PrepareCartItemPictureModel:
XDocument xml = XDocument.Parse(sci.AttributesXml);
XElement elems = xml.Descendants("ProductAttribute").Where(x => x.Attribute("ID").Value ==
completedLureId.ToString()).First();
var b64string = elems.Element("ProductAttributeValue").Element("Value").Value;
var pictureCacheKey = string.Format(ModelCacheEventConsumer.CART_PICTURE_MODEL_KEY, sci.Id, pictureSize, true,
_workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id);
var model = _cacheManager.Get(pictureCacheKey,
60, () =>
{
var sciPicture = sci.Product.GetProductPicture(sci.AttributesXml, _pictureService,
_productAttributeParser);
return new PictureModel()
{
ImageUrl = String.Concat("data:image/png;base64,", b64string),
Title = sci.Product.Name,
AlternateText = sci.Product.Name
};
});
Could I do this some other way to make the change "permanent"?