Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gary Winter 15 posts 156 karma points
    Jul 24, 2019 @ 10:13
    Gary Winter
    0

    Extended Content Updating

    I am trying to update a couple of fields within Extended Content against a product, this is a viewCount and likeCount which a customer can like a product or watch a video attached to a product after they have purchased the item. I am struggling to get this to work I can access iProduct Content to read the current viewCount and likeCount values but am unable to Save the updated values back to the Product.

    Can anyone point me in the right direction please?

  • Puck Holshuijsen 90 posts 352 karma points
    Sep 23, 2019 @ 12:34
    Puck Holshuijsen
    100

    Hi Gary,

    You should get the product with the product service.

    string productId = "YOURSKU";
    var product = Merchello.Core.MerchelloContext.Current.Services.ProductVariantService.GetBySku(productId);
    

    You can get the product multiple ways, but in my example I use a SKU.

    Then you can iterate through the detached contents (these are the extended content, and each detached content is 1 language).

    int viewCount = 100;
    string viewCountPropertyAlias = "viewCount";    
    foreach (var dc in product.DetachedContents) {
                                            dc.DetachedDataValues.AddOrUpdate(viewCountPropertyAlias, viewCount, (key, oldValue) => viewCount);
                                        }
    

    After you're done adding/updating the value, you need to save the product.

    Merchello.Core.MerchelloContext.Current.Services.ProductVariantService.Save(product);
    

    I hope this helps :)

    //Puck

  • Gary Winter 15 posts 156 karma points
    Sep 24, 2019 @ 09:08
    Gary Winter
    0

    Thank you, I shall give this a try later, and let you know how I get on.

    Thanks Again

  • Puck Holshuijsen 90 posts 352 karma points
    Sep 24, 2019 @ 09:18
    Puck Holshuijsen
    0

    By the way, this is the productvariantservice, you also have the productservice.

    Maybe you need that one ;)

    //Puck

  • Gary Winter 15 posts 156 karma points
    Sep 24, 2019 @ 22:03
    Gary Winter
    0

    I did need the ProductService in the end, but that worked a treat, many thanks for your help.

    Gary

  • Puck Holshuijsen 90 posts 352 karma points
    Sep 25, 2019 @ 06:01
    Puck Holshuijsen
    0

    Good to hear!

    No problem ;)

Please Sign in or register to post replies

Write your reply to:

Draft