Using client generated image as product image in the cart

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello Nop experts!

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"?
4 years ago
I think that would would then affect all customers looking at that product.  If you want it just for the specific customer who uploaded the image as an attribute so that it only appears in his " flyout cart and the checkout", then you need to make code adjustments in those areas of the code that retrieve the image.
4 years ago
Hi, thanks for your reply.

This is indeed the problem I am wrestling with at the moment. As you're saying, a product isn't customer specific so setting an image on product level isn't a solution.

I will take a look at the individual areas where the image is fetched.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.