3

I have a requirement where I need t convert the data in to sitecore items. Each data has its own language content. so I want to move the data from source to sitecore as shown in the below

  1. create sitecore items with language versions
  2. update those items frequently

Any reference or code sample to insert the sitecore items with language versions?

| improve this question | | | | |
  • Well I don't remember creating a language version item from Adam's webinar. In case you are looking for code snippet help for DEF you can try here – phani Dec 5 '16 at 9:44
3

Try this. Add references: Sitecore.DataExchange.Local,Sitecore.Services.Core,Sitecore.Services.Infrastructure, Sitecore.Services.Infrastructure.Sitecore.

Create a custom repository class based on InProcItemModelRepository.

public class CustomRepository : InProcItemModelRepository
  {
    public override Guid Create(string itemName, Guid templateId, Guid parentId, string language)
    {
      var parentItem = base.Get(parentId);
      if (parentItem == null)
      {
        return Guid.Empty;
      }
      var path = parentItem[ItemModel.ItemPath].ToString();
      //
      var itemModel = new ItemModel();
      itemModel[ItemModel.ItemName] = itemName;
      itemModel[ItemModel.TemplateID] = templateId.ToString();
      var handler = base.HandlerProvider.GetHandler<CreateItemHandler>();
      var command = new CreateItemCommand
      {
        ItemModel = itemModel,
        Path = path,
        Language = language

      };
      var response = handler.Handle(command) as CreateItemResponse;
      return response.ItemId;
    }

    public override bool Update(Guid id, ItemModel itemModel, string language, int version)
    {
      var handler = base.HandlerProvider.GetHandler<UpdateItemHandler>();
      var command = new UpdateItemCommand
      {
        Id = id,
        Database = base.DatabaseName,
        ItemModel = itemModel,
        Language = language,
        Version = version.ToString()
      };
      handler.Handle(command);
      return true;
    }
  }

Add you config. You need replace repository with your custom.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <dataExchange>
            <itemModelRepository type="Custom.DataExchange.CustomRepository, Custom.DataExchange", patch:instead="processor[@type='Sitecore.DataExchange.Local.Repositories.InProcItemModelRepository, Sitecore.DataExchange.Local']">
                <databaseName>master</databaseName>
            </itemModelRepository>
        </dataExchange>
    </sitecore>
</configuration>

Example:

var repo = (CustomRepository)DataExchange.Context.ItemModelRepository;
var templateId = new Guid("{A0691A54-6175-4C10-9E10-9A1FA0134517}");
var parentId = new Guid("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}");
var itemId = repo.Create("My Product", templateId, parentId, "de");
repo.Update(itemId, new ItemModel() { { "ProductName", "My Product Name" } }, "de", 1);
| improve this answer | | | | |
  • 1
    Hello Vald, thanks for your reply. Here do we require DXF pipeline configurations, tenant settings ? I am configuring all DXF tenant , mapping, endpoint etc in sitecore. – Hussain Shaik Dec 6 '16 at 4:57
  • Can you be a more specific here? – Vlad Shpak Dec 6 '16 at 19:42
  • Yes, you still need to create the various components within Sitecore so that you can use and configure the custom repository that Vlad describes. Adding support for this is in our roadmap, but we're currently focusing a bit more on the xDB side of things, because that is where there is a lot less familiarity in how to integrate data. – Adam Conn Dec 6 '16 at 22:25
  • <configuration xmlns:patch="sitecore.net/xmlconfig"> <sitecore> <dataExchange> <itemModelRepository type="Custom.DataExchange.CustomRepository, Custom.DataExchange", patch:instead="itemModelRepository[@type='Sitecore.DataExchange.Local.Repositories.InProcItemModelRepository, Sitecore.DataExchange.Local']"> <databaseName>master</databaseName> </itemModelRepository> </dataExchange> </sitecore> </configuration> – Hussain Shaik Dec 13 '16 at 12:16
  • small correction in answer , In custom repository class - public virtual Guid Create should be public override Guid Create – Rama Krshna Ila Mar 1 '18 at 5:24

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.