3

I am using the below code to add the Images for products. Seems some thing is stopping to save the images. Any missing code here?

var components = new List<Component>
{

    new ItemVariationsComponent
    {
        ChildComponents = new List<Component>
        {
            new ItemVariationComponent
            {
                Id = "92604332591",
                Name = "HHHHH Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Stainless)",
                Policies = new List<Policy>
                {
                    new ListPricingPolicy(new List<Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) })
                },
                ChildComponents = new List<Component>
                {

                    new ImagesComponent{ Images = new List<string>{ "6042064_01", "6042064_02", "6042064_03" } }
                },

            }

        },
        Name ="test"

    }
};
addedItem.Components = components;
  • 1
    can you add mediafile ids and not 6042064_01 – Vlad Iobagiu Aug 10 '18 at 13:01
  • are you getting any errors in your log files? – Richard Seal Aug 10 '18 at 13:21
  • It works if i add Image Sitecore item id instead of Image name. ChildComponents = new List<Component> { new ImagesComponent{ Images = new List<string>{ "857eccd8-03a9-49cf-9ef7-a3168e4acb11" , "857eccd8-03a9-49cf-9ef7-a3168e4acb11" } } }, – Hussain Aug 10 '18 at 13:30
  • I will add my comment like an answer. Please mark it as right answer – Vlad Iobagiu Aug 10 '18 at 13:50
1

Images fields on commerce keep the images field like a list of media items id i. So a image field in commerce raw value is like : 857eccd8-03a9-49cf-9ef7-a3168e4acb11|abceccd8-a1a9-321f-9e21-a1112dsds4acb11

You need to replace in your code ids with media files ids

 var components = new List<Component>
    {
      new ItemVariationsComponent
      {
        ChildComponents = new List<Component>
        {
            new ItemVariationComponent
            {
                Id = "92604332591",
                Name = "HHHHH Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Stainless)",
                Policies = new List<Policy>
                {
                    new ListPricingPolicy(new List<Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) })
                },
                ChildComponents = new List<Component>
                {

                    new ImagesComponent{ Images = new List<string>{ "857eccd8-03a9-49cf-9ef7-a3168e4acb11" , "857eccd8-03a9-49cf-9ef7-a3168e4acb11" }}
                },

            }

        },
        Name ="test"
    }
};
addedItem.Components = components;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.