public override async Task <bool> Run(CreateComposerTemplatesArgument arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull($"{this.Name}: The argument can not be null"); //Create the template, add the view and the properties string itemId = $"Composer-{Guid.NewGuid()}"; var composerTemplate = new ComposerTemplate(GenericTaxesConstants.ComposerViewValue); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.LinkedEntities = new List <string>() { "Sitecore.Commerce.Plugin.Catalog.SellableItem" }; composerTemplate.Name = "GenericTaxes"; composerTemplate.DisplayName = "Generic Taxes"; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); var composerTemplateView = new EntityView { Name = "Generic Taxes", DisplayName = "GenericTaxes", DisplayRank = 0, ItemId = itemId, EntityId = composerTemplate.Id }; GenericTaxPolicy taxPolicy = context.GetPolicy <GenericTaxPolicy>(); AvailableSelectionsPolicy availableSelectionsPolicy = new AvailableSelectionsPolicy(); foreach (decimal whiteListEntry in taxPolicy.Whitelist) { availableSelectionsPolicy.List.Add(new Selection() { Name = whiteListEntry.ToString(), DisplayName = whiteListEntry.ToString(), }); } composerTemplateView.Properties.Add(new ViewProperty() { DisplayName = taxPolicy.TaxFieldName, Name = taxPolicy.TaxFieldName, OriginalType = "System.String", RawValue = string.Empty, Value = string.Empty, Policies = new List <Policy>() { availableSelectionsPolicy } }); composerTemplateViewComponent.View.ChildViews.Add(composerTemplateView); var persistResult = await this._commerceCommander.PersistEntity(context.CommerceContext, composerTemplate); return(await Task.FromResult(true)); }
private async Task CreateManufacturerDataTemplate(CommercePipelineExecutionContext context) { var composerTemplate = new ComposerTemplate("Manufacturing".ToEntityId <ComposerTemplate>()); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.LinkedEntities = new List <string>() { "Sitecore.Commerce.Plugin.Catalog.SellableItem" }; composerTemplate.Name = "Manufacturing"; composerTemplate.DisplayName = "Manufacturing"; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); var composerTemplateView = new EntityView { Name = "Manufacturing", DisplayName = "Manufacturing", DisplayRank = 0, ItemId = $"Composer-{System.Guid.NewGuid()}", EntityId = composerTemplate.Id }; composerTemplateView.Properties.Add(new ViewProperty { Name = "CountryOfOrigin", DisplayName = "Country of Origin", OriginalType = "System.String", }); composerTemplateView.Properties.Add(new ViewProperty { Name = "ManufacturerType", DisplayName = "Manufacturer Type", OriginalType = "System.String", Policies = new List <Policy> { new AvailableSelectionsPolicy { List = new List <Selection> { new Selection { DisplayName = "Hand", Name = "Hand" }, new Selection { DisplayName = "Automated", Name = "Automated" } } } } }); composerTemplateViewComponent.View.ChildViews.Add(composerTemplateView); await _commerceCommander.PersistEntity(context.CommerceContext, composerTemplate); }
private async Task <ComposerTemplate> EnsureComposerTemplateProperty(SyncForceClientPolicy syncForcePolicy, ComposerTemplate template, CommerceContext context, EntityView childView, string name, string propertyType) { var entityViewComponent = template.GetComponent <EntityViewComponent>(); if (childView.Properties.All(p => p.Name != name)) { if (entityViewComponent.View.GetChildView( it => String.Equals(it.Name, syncForcePolicy.CommonComposerTemplateName, StringComparison.InvariantCultureIgnoreCase)) is EntityView templateView) { templateView.Properties.Add(new ViewProperty() { DisplayName = name, IsHidden = false, OriginalType = propertyType, IsRequired = false, IsReadOnly = false, Name = name }); template.SetComponent(entityViewComponent); return((await _persistEntityPipeline.Run(new PersistEntityArgument(template), context.PipelineContextOptions))?.Entity as ComposerTemplate); } } return(template); }
private async Task CreateSizingTemplate(CommercePipelineExecutionContext context) { var composerTemplate = new ComposerTemplate("Sizing".ToEntityId <ComposerTemplate>()); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.LinkedEntities = new List <string>() { "Sitecore.Commerce.Plugin.Catalog.SellableItem" }; composerTemplate.Name = "Sizing"; composerTemplate.DisplayName = "Sizing"; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); var composerTemplateView = new EntityView { Name = "Sizing", DisplayName = "Sizing Data", DisplayRank = 0, ItemId = $"Composer-{System.Guid.NewGuid()}", EntityId = composerTemplate.Id }; composerTemplateView.Properties.Add(new ViewProperty { Name = "Waist", DisplayName = "Waist", OriginalType = "System.Int64", }); composerTemplateView.Properties.Add(new ViewProperty { Name = "InsideLeg", DisplayName = "Inside Leg", OriginalType = "System.Int64", }); composerTemplateView.Properties.Add(new ViewProperty { Name = "OutsideLeg", DisplayName = "Outside Leg", OriginalType = "System.Int64", }); composerTemplateViewComponent.View.ChildViews.Add(composerTemplateView); await _commerceCommander.PersistEntity(context.CommerceContext, composerTemplate); }
/// <summary> /// To Composer Template /// </summary> /// <param name="input">Custom Composer Template</param> /// <returns>Composer Tewmplate</returns> public static ComposerTemplate ToComposerTemplate(this CustomComposerTemplate input) { var composerTemplate = new ComposerTemplate(input.Id); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.LinkedEntities = input.LinkedEntities; composerTemplate.Name = input.Name; composerTemplate.DisplayName = input.DisplayName; composerTemplate.Version = input.Version; composerTemplate.EntityVersion = input.EntityVersion; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); composerTemplateViewComponent.View.ChildViews.Add(input.ChildView.ToEntityView()); return(composerTemplate); }
private void AddItemDefinitionsFromProxy(ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate) { var proxyItemDefinitionsComponent = proxyComposerTemplate?.Components?.OfType <ProxyCatalog.ItemDefinitionsComponent>().FirstOrDefault(); if (proxyItemDefinitionsComponent == null) { return; } engineComposerTemplate.GetComponent <ItemDefinitionsComponent>().AddDefinitions(proxyItemDefinitionsComponent.Definitions); }
public override async Task <ComposerTemplateContentArgument> Run(CreateComposerTemplateArgument arg, CommercePipelineExecutionContext context) { Condition.Requires <CreateComposerTemplateArgument>(arg).IsNotNull <CreateComposerTemplateArgument>($"{this.Name}: The argument can not be null"); var composerTemplateId = $"{CommerceEntity.IdPrefix<ComposerTemplate>()}{arg.ComposerTemplateId}"; var errorCodes = context.GetPolicy <KnownResultCodes>(); if (await _doesEntityExistPipeline.Run(new FindEntityArgument(typeof(ComposerTemplate), composerTemplateId), context.CommerceContext.PipelineContextOptions)) { var errorMessage = await context.CommerceContext.AddMessage(errorCodes.ValidationError, "NameAlreadyInUse", new object[1] { arg.ComposerTemplateId }, $"Name '{arg.ComposerTemplateId}' is already in use."); return(new ComposerTemplateContentArgument()); } var composerTemplate = new ComposerTemplate(composerTemplateId) { Name = !string.IsNullOrEmpty(arg.Name) ? arg.Name : arg.ComposerTemplateId, DisplayName = arg.DisplayName, FriendlyId = arg.ComposerTemplateId }; composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); var entityView = CreateEntityView(context.CommerceContext, arg.ComposerTemplateId, arg.Name, arg.DisplayName); if (entityView != null) { composerTemplate.GetComponent <EntityViewComponent>().AddChildView(entityView); } var persistResult = await _persistEntityPipeline.Run(new PersistEntityArgument(composerTemplate), context.CommerceContext.PipelineContextOptions); return(new ComposerTemplateContentArgument() { ComposerTemplate = persistResult?.Entity as ComposerTemplate }); }
private void AddComposerTemplateListMembershipsFromProxy(ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate) { var proxyListMembershipComponent = proxyComposerTemplate?.Components?.OfType <ProxyManagedLists.ListMembershipsComponent>().FirstOrDefault(); if (proxyListMembershipComponent == null) { return; } foreach (var membership in proxyListMembershipComponent.Memberships) { engineComposerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(membership); } }
/// <summary> /// To Custom Composer Template /// </summary> /// <param name="input">Composer Template input</param> /// <returns>Custom Composer Template output</returns> public static CustomComposerTemplate ToCustomComposerTemplate(this ComposerTemplate input) { EntityView entityView = input.GetComponent <EntityViewComponent>().View.ChildViews.FirstOrDefault() as EntityView; entityView.EntityId = string.IsNullOrEmpty(entityView.EntityId) ? entityView.EntityId : input.Id; return(new CustomComposerTemplate() { EntityVersion = input.EntityVersion, Id = input.Id, Name = input.Name, DisplayName = input.DisplayName, Version = input.Version, LinkedEntities = input.LinkedEntities, ChildView = entityView.ToCustomEntityView() }); }
private async Task AddComposerTemplateEntityViewFromProxy(CommerceContext commerceContext, ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate) { var proxyEntityViewComponent = proxyComposerTemplate.Components.OfType <ProxyViews.EntityViewComponent>().FirstOrDefault(); if (proxyEntityViewComponent == null || proxyEntityViewComponent.View == null || proxyEntityViewComponent.View.ChildViews == null || !proxyEntityViewComponent.View.ChildViews.Any()) { return; } var proxyChildView = proxyEntityViewComponent.View?.ChildViews[0] as ProxyEntityViews.EntityView; EntityView engineEntityChildView = new EntityView(); engineEntityChildView.ItemId = proxyChildView.ItemId; engineEntityChildView.EntityId = proxyChildView.EntityId; engineEntityChildView.Name = proxyChildView?.Name; engineEntityChildView.DisplayName = proxyChildView.DisplayName; engineEntityChildView.Icon = proxyChildView.Icon; engineEntityChildView.DisplayRank = proxyChildView.DisplayRank; var isNameValid = await this.RunValidCheckOnName(engineEntityChildView, commerceContext); if (!isNameValid) { return; } engineComposerTemplate.GetComponent <EntityViewComponent>().AddChildView(engineEntityChildView); if (proxyChildView.Properties != null) { foreach (var proxyViewProperty in proxyChildView.Properties) { await this.AddPropertyToViewFromProxy(commerceContext, engineEntityChildView, proxyViewProperty); } } }
private async void CreateBlockchainInformationTemplate(CommercePipelineExecutionContext context) { string templateId = $"{CommerceEntity.IdPrefix<ComposerTemplate>()}{"BlockchainInformation"}"; try { // delete the existing template (this does not delete data from products) var deleteTemplate = await _commerceCommander.DeleteEntity(context.CommerceContext, templateId); var composerTemplate = new ComposerTemplate(templateId); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.Tags.Add(new Tag("Blockchain")); composerTemplate.Name = "BlockchainInformation"; composerTemplate.DisplayName = "Blockchain Information"; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); composerTemplateViewComponent.Id = "95DACDDD-151E-4527-A068-A27C9275967J"; var composerTemplateView = new EntityView { Name = Constants.Pipelines.Views.BlockchainInformationViewName, DisplayName = Constants.Pipelines.Views.BlockchainInformationViewDisplayName, DisplayRank = 0, ItemId = Constants.Pipelines.Views.BlockchainInformationViewId, EntityId = composerTemplate.Id }; composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "Identity Contract Address", Name = Constants.Pipelines.Fields.IdentityContractAddressFieldName, OriginalType = "System.String", RawValue = "", Value = "" }); composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "Publish Purchased Products", Name = Constants.Pipelines.Fields.PublishProductsFieldName, OriginalType = "System.Boolean", RawValue = false, Value = "false" }); composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "ETH Balance", Name = Constants.Pipelines.Fields.EthBalanceFieldName, OriginalType = "System.String", RawValue = string.Empty, Value = string.Empty, IsReadOnly = true }); composerTemplateViewComponent.View.ChildViews.Add(composerTemplateView); var persistResult = await this._commerceCommander.PersistEntity(context.CommerceContext, composerTemplate); } catch (Exception ex) { context.Logger.LogError(string.Format("{0}. Unable to generate Composer tamplate '{1}'. {2}", Constants.Pipelines.Blocks.CreateComposerTemplatesBlock, templateId, ex.Message), Array.Empty <object>()); } }