0

I need show the product and Version from the below folder structure. Please help to achieve on this.

Requirement Screen Shot Need to show product and Version

Sitecore Folder Structure

sitecore folder structure

So far I wrote some code for review

var item = ItemHelper.GetChildItems("{D25F6421-4578-4EB2-8C6D-C9BE2C355099}");

public static IEnumerable<Item> GetChildItems(string itemId)
{
    var sitecoreItem = Sitecore.Context.Database.GetItem(new ID(itemId));
  
    if (sitecoreItem.HasChildren)
    {
        return sitecoreItem.GetChildren().InnerChildren;

    }

    return null;
}

 var productList = item.Where(x => x.Fields["ProductTitle"] != null).Select(y =>
 new Product
 {
     Name = y.Name,
     Id = y.ID,
     ProductTitle = y.Fields["ProductTitle"].Value,
     Version = y.GetChildren().InnerChildren
 });

I need version list also to bind.

3
  • Please share what you have done so far and maybe people can help identify a problem Nov 19, 2023 at 12:31
  • @DeanOBrien code added. Please review on it. if you aware of it.
    – Hasanshali
    Nov 19, 2023 at 12:57
  • You need to add more information to this like which is that item that has id - {D25F6421-4578-4EB2-8C6D-C9BE2C355099} ? Definition of Product object. Out of my assumption, try this - Version = y.GetChildren() Nov 20, 2023 at 6:31

2 Answers 2

1
 public static IEnumerable<Models.Product> GetProductList(ID itemId)
 {
     var childItem = GetChildItems(itemId.ToString());

     IEnumerable<Models.Product> productList = new List<Models.Product>();

     if (childItem != null)
     {
         productList = childItem.Where(x => x.Fields["ProductTitle"] != null)
                             .Select(y => new Models.Product
                             {
                                 Name = y.Name,
                                 Id = y.ID,
                                 ProductTitle = y.Fields["ProductTitle"].Value,
                                 ProductItem = y,
                                 Version = y.GetChildren().InnerChildren
                                 .Select(z => new ProductVersion
                                 {
                                     Name = z.Name,
                                     Id = z.ID,
                                     VersionItem = z,
                                     ModuleList = z.GetChildren().InnerChildren
                                      .Select(m => new ProductModule
                                      {
                                          Name = m.Name,
                                          Id = m.ID,
                                          TemplateId = m.TemplateID,
                                          ModuleItem = m
                                      })

                                 })
                             });

     }


     return productList;
 }
1
  • Above code Will it be faster? if i have more than 500 records. @Vikrant Punwatkar
    – Hasanshali
    Nov 20, 2023 at 7:54
0

Can you try this

var versions = Sitecore.Data.Managers.ItemManager.GetVersions(item);
var allVersions = versions.Select(x => item.Database.Items[item.ID, item.Language, x]);
1
  • version is custom folder, not sitecore version. please read the question and see the screenshot.
    – Hasanshali
    Nov 22, 2023 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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