public override async Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull(arg.Name + ": The argument cannot be null"); ViewProperty condition = arg.Properties.FirstOrDefault(p => p.Name.EqualsOrdinalIgnoreCase("Condition")); if (condition == null || !condition.RawValue.ToString().StartsWith("Hc_") || !condition.RawValue.ToString().EndsWith("PaymentCondition")) { return(arg); } ViewProperty paymentSelection = arg.Properties.FirstOrDefault(x => x.Name.EqualsOrdinalIgnoreCase("Hc_SpecificPayment")); if (paymentSelection != null) { IEnumerable <PaymentMethod> paymentMethods = await _getCommand.Process(context.CommerceContext); IEnumerable <Selection> options = paymentMethods.Select(x => new Selection { DisplayName = x.DisplayName, Name = x.Name }); var policy = new AvailableSelectionsPolicy(options); paymentSelection.Policies.Add(policy); } return(arg); }
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)); }
/// <summary> /// To Custom View Property /// </summary> /// <param name="input">View Property</param> /// <returns>Custom View Proerty</returns> public static CustomViewProperty ToCustomViewProperty(this ViewProperty input) { AvailableSelectionsPolicy availableSelectionPolicy = input.GetPolicy <AvailableSelectionsPolicy>(); return(new CustomViewProperty() { DisplayName = input.DisplayName, Name = input.Name, OriginalType = input.OriginalType, RawValue = input.RawValue, Value = input.Value, AvailableSelectionPolicy = availableSelectionPolicy.List == null || !availableSelectionPolicy.List.Any() ? null : availableSelectionPolicy.ToCustomAvailableSelectionPolicy() }); }
/// <summary> /// Executes the pipeline block. /// </summary> /// <param name="arg">The entity view.</param> /// <param name="context">The context.</param> /// <returns></returns> public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context) { Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null"); var viewsPolicy = context.GetPolicy <Policies.KnownInventoryViewsPolicy>(); var entityViewArgument = context.CommerceContext.GetObject <EntityViewArgument>(); var enablementPolicy = context.GetPolicy <Policies.InventoryFeatureEnablementPolicy>(); if (!enablementPolicy.InventoryFromProductView || string.IsNullOrEmpty(entityViewArgument?.ViewName) || !entityViewArgument.ViewName.Equals(viewsPolicy.SelectInventorySet, StringComparison.OrdinalIgnoreCase)) { return(await Task.FromResult(entityView).ConfigureAwait(false)); } var inventorySets = await CommerceCommander.Pipeline <FindEntitiesInListPipeline>().Run( new FindEntitiesInListArgument( typeof(InventorySet), $"{CommerceEntity.ListName<InventorySet>()}", 0, int.MaxValue), context).ConfigureAwait(false); var availableSelectionsPolicy = new AvailableSelectionsPolicy( inventorySets.List.Items.Select(s => new Selection { DisplayName = s.DisplayName, Name = s.Name }).ToList() ?? new List <Selection>()); var viewProperty = new ViewProperty() { Name = "Inventory Set", UiType = "SelectList", Policies = new List <Policy>() { availableSelectionsPolicy }, RawValue = availableSelectionsPolicy.List.Where(s => s.IsDefault).FirstOrDefault()?.Name ?? availableSelectionsPolicy.List?.FirstOrDefault().Name }; entityView.Properties.Add(viewProperty); return(entityView); }
private void AddOptionConstraintToPropertyFromProxy(ViewProperty engineViewProperty, ProxyCore.AvailableSelectionsPolicy proxyAvailableSelectionsPolicy) { if (proxyAvailableSelectionsPolicy.List == null || !proxyAvailableSelectionsPolicy.List.Any()) { return; } AvailableSelectionsPolicy engineAvailableSelectionPolicy = engineViewProperty.GetPolicy <AvailableSelectionsPolicy>(); foreach (var proxySelection in proxyAvailableSelectionsPolicy.List) { Selection selection = new Selection(); selection.DisplayName = proxySelection.DisplayName; selection.Name = proxySelection.Name; selection.IsDefault = proxySelection.IsDefault; engineAvailableSelectionPolicy.List.Add(selection); } }
public override Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context) { GetSelectCommerceEngineEnvironmentToPullTemplatesBlock getSelectCommerceEngineEnvironmentToPullTemplatesBlock = this; Condition.Requires(arg).IsNotNull(getSelectCommerceEngineEnvironmentToPullTemplatesBlock.Name + ": The entity view cannot be null."); if (string.IsNullOrEmpty(arg.Action) || (!arg.Action.Equals(context.GetPolicy <KnownComposerActionsPolicy>().SelectCommerceEngineEnvironmentToPullTemplates, StringComparison.OrdinalIgnoreCase))) { return(Task.FromResult(arg)); } var ceEnvironmentPolicy = context.GetPolicy <KnownApplicationEnvironmentsPolicy>(); if (ceEnvironmentPolicy == null || ceEnvironmentPolicy.Environments == null || !ceEnvironmentPolicy.Environments.Any()) { return(Task.FromResult(arg)); } AvailableSelectionsPolicy availableEnvironments = new AvailableSelectionsPolicy(); ceEnvironmentPolicy.Environments.ForEach(e => { List <Selection> list = availableEnvironments.List; list.Add(new Selection() { Name = e.Name, DisplayName = e.Name }); }); List <ViewProperty> properties = arg.Properties; ViewProperty viewProperty = new ViewProperty(new List <Policy>() { availableEnvironments }); viewProperty.Name = ComposerConstants.EnvironmentDropdownPropertyName; viewProperty.RawValue = string.Empty; properties.Add(viewProperty); return(Task.FromResult(arg)); }
public override async Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context) { if (string.IsNullOrEmpty(arg?.Action) || !arg.Action.Equals(context.GetPolicy <KnownCustomPricingActionsPolicy>().SelectMembershipCurrency, StringComparison.OrdinalIgnoreCase) || !arg.Name.Equals(context.GetPolicy <KnownCustomPricingViewsPolicy>().PriceCustomRow, StringComparison.OrdinalIgnoreCase)) { return(arg); } var card = context.CommerceContext.GetObjects <PriceCard>().FirstOrDefault(p => p.Id.Equals(arg.EntityId, StringComparison.OrdinalIgnoreCase)); if (card == null) { return(arg); } KnownResultCodes policy = context.GetPolicy <KnownResultCodes>(); if (string.IsNullOrEmpty(arg.ItemId)) { await context.CommerceContext.AddMessage(policy.ValidationError, "InvalidOrMissingPropertyValue", new object[] { "ItemId" }, "Invalid or missing value for property 'ItemId'.") .ConfigureAwait(false); return(arg); } PriceSnapshotComponent snapshot = card.Snapshots.FirstOrDefault(s => s.Id.Equals(arg.ItemId, StringComparison.OrdinalIgnoreCase)); if (snapshot == null) { await context.CommerceContext.AddMessage(policy.ValidationError, "PriceSnapshotNotFound", new object[] { arg.ItemId, card.FriendlyId }, "Price snapshot " + arg.ItemId + " on price card " + card.FriendlyId + " was not found.") .ConfigureAwait(false); return(arg); } var currencyProperty = arg.Properties.FirstOrDefault(p => p.Name.Equals("Currency", StringComparison.OrdinalIgnoreCase)); string currency = currencyProperty?.Value; if (string.IsNullOrEmpty(currency)) { await context.CommerceContext.AddMessage(policy.ValidationError, "InvalidOrMissingPropertyValue", new object[] { currencyProperty == null ? "Currency" : currencyProperty.DisplayName }, "Invalid or missing value for property 'Currency'.") .ConfigureAwait(false); return(arg); } if (snapshot.Tiers.Any(t => t.Currency.Equals(currency, StringComparison.OrdinalIgnoreCase))) { await context.CommerceContext.AddMessage(policy.ValidationError, "CurrencyAlreadyExists", new object[] { currency, snapshot.Id, card.FriendlyId }, "Currency " + currency + " already exists for snapshot " + snapshot.Id + " on price card " + card.FriendlyId + ".") .ConfigureAwait(false); return(arg); } CurrencySet currencySet = null; string entityTarget = (await _findEntityCommand.Process(context.CommerceContext, typeof(PriceBook), card.Book.EntityTarget, false).ConfigureAwait(false) as PriceBook)?.CurrencySet.EntityTarget; if (!string.IsNullOrEmpty(entityTarget)) { currencySet = await _getCurrencySetCommand.Process(context.CommerceContext, entityTarget).ConfigureAwait(false); if (currencySet != null) { var currencies = currencySet.GetComponent <CurrenciesComponent>().Currencies; string str = string.Join(", ", currencies.Select(c => c.Code)); if (!currencies.Any(c => c.Code.Equals(currency, StringComparison.OrdinalIgnoreCase))) { CommercePipelineExecutionContext executionContext = context; CommerceContext commerceContext = context.CommerceContext; string validationError = context.GetPolicy <KnownResultCodes>().ValidationError; string commerceTermKey = "InvalidCurrency"; var args = new object[] { currency, str }; string defaultMessage = "Invalid currency '" + currency + "'. Valid currencies are '" + str + "'."; executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context); executionContext = null; return(arg); } } } currencyProperty.IsReadOnly = true; currencyProperty.Policies = new List <Policy>() { new AvailableSelectionsPolicy(currencySet == null || !currencySet.HasComponent <CurrenciesComponent>() ? new List <Selection>() : currencySet.GetComponent <CurrenciesComponent>() .Currencies.Select(c => { return(new Selection() { DisplayName = c.Code, Name = c.Code }); }).ToList(), false) }; EntityView priceCustomCellEntityView = new EntityView { Name = context.GetPolicy <KnownCustomPricingViewsPolicy>().PriceCustomCell, EntityId = card.Id, ItemId = snapshot.Id }; var membershipLevels = context.GetPolicy <MembershipLevelPolicy>().MembershipLevels; List <Selection> selections = currencySet == null || !currencySet.HasComponent <CurrenciesComponent>() ? new List <Selection>() : membershipLevels.Select(c => { return(new Selection() { DisplayName = c.MemerbshipLevelName, Name = c.MemerbshipLevelName }); }).ToList(); AvailableSelectionsPolicy availableSelectionsPolicy = new AvailableSelectionsPolicy(selections, false); List <Policy> commercePolicies = new List <Policy>() { availableSelectionsPolicy }; ViewProperty membershipLevelViewProperty = new ViewProperty() { Name = "MembershipLevel", OriginalType = typeof(string).FullName, Policies = commercePolicies }; priceCustomCellEntityView.Properties.Add(membershipLevelViewProperty); ViewProperty quantityViewProperty = new ViewProperty(); quantityViewProperty.Name = "Quantity"; quantityViewProperty.OriginalType = typeof(decimal).FullName; priceCustomCellEntityView.Properties.Add(quantityViewProperty); ViewProperty priceViewProperty = new ViewProperty { Name = "Price", RawValue = null, OriginalType = typeof(decimal).FullName }; priceCustomCellEntityView.Properties.Add(priceViewProperty); arg.ChildViews.Add(priceCustomCellEntityView); arg.UiHint = "Grid"; context.CommerceContext.AddModel(new MultiStepActionModel(context.GetPolicy <KnownCustomPricingActionsPolicy>().AddMembershipCurrency)); return(arg); }
protected virtual async Task PopulateDetails(EntityView view, Customer customer, bool isAddAction, bool isEditAction, CommercePipelineExecutionContext context) { if (view == null) { return; } ValidationPolicy validationPolicy = ValidationPolicy.GetValidationPolicy(context.CommerceContext, typeof(Customer)); ValidationPolicy detailsValidationPolicy = ValidationPolicy.GetValidationPolicy(context.CommerceContext, typeof(CustomerDetailsComponent)); CustomerPropertiesPolicy propertiesPolicy = context.GetPolicy <CustomerPropertiesPolicy>(); EntityView details = (EntityView)null; if (customer != null && customer.HasComponent <CustomerDetailsComponent>()) { details = customer.GetComponent <CustomerDetailsComponent>().View.ChildViews.FirstOrDefault <Model>((Func <Model, bool>)(v => v.Name.Equals("Details", StringComparison.OrdinalIgnoreCase))) as EntityView; } List <string> languages = new List <string>(); Shop shop = context.CommerceContext.GetObjects <Shop>().FirstOrDefault <Shop>(); if (shop != null && shop.Languages.Any <string>()) { languages = shop.Languages; } foreach (string detailsProperty in propertiesPolicy?.DetailsProperties) { string propertyName = detailsProperty; if (!isAddAction || !propertyName.Equals(propertiesPolicy?.AccountNumber, StringComparison.OrdinalIgnoreCase)) { ValidationAttributes validationAttributes = validationPolicy.Models.FirstOrDefault <Model>((Func <Model, bool>)(m => m.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))) as ValidationAttributes; if (propertyName.Equals(propertiesPolicy?.AccountStatus, StringComparison.OrdinalIgnoreCase)) { KnownCustomersStatusesPolicy statusesPolicy = context.GetPolicy <KnownCustomersStatusesPolicy>(); List <Selection> statuses = new List <Selection>(); string currentStatus = customer?.AccountStatus ?? string.Empty; if (isAddAction | isEditAction) { PropertyInfo[] propertyInfoArray = typeof(KnownCustomersStatusesPolicy).GetProperties(); for (int index = 0; index < propertyInfoArray.Length; ++index) { PropertyInfo propertyInfo = propertyInfoArray[index]; if (!propertyInfo.Name.Equals("PolicyId", StringComparison.OrdinalIgnoreCase) && !propertyInfo.Name.Equals("Models", StringComparison.OrdinalIgnoreCase)) { string status = propertyInfo.GetValue((object)statusesPolicy, (object[])null) as string; if (!string.IsNullOrEmpty(status)) { LocalizedTerm localizedTerm = await this._getLocalizedCustomerStatusPipeline.Run(new LocalizedCustomerStatusArgument(status, (object[])null), context); List <Selection> selectionList = statuses; Selection selection = new Selection(); selection.DisplayName = localizedTerm?.Value; selection.Name = status; selectionList.Add(selection); status = (string)null; } } } propertyInfoArray = (PropertyInfo[])null; } else if (!string.IsNullOrEmpty(currentStatus)) { LocalizedTerm localizedTerm = await this._getLocalizedCustomerStatusPipeline.Run(new LocalizedCustomerStatusArgument(currentStatus, (object[])null), context); if (!string.IsNullOrEmpty(localizedTerm?.Value)) { currentStatus = localizedTerm?.Value; } } List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertiesPolicy?.AccountStatus; viewProperty.RawValue = (object)currentStatus; viewProperty.IsReadOnly = !isAddAction && !isEditAction; ValidationAttributes validationAttributes1 = validationAttributes; viewProperty.IsRequired = validationAttributes1 != null && validationAttributes1.MinLength > 0; viewProperty.Policies = (IList <Policy>) new List <Policy>() { (Policy) new AvailableSelectionsPolicy() { List = statuses } }; properties.Add(viewProperty); } else if (propertyName.Equals(propertiesPolicy?.LoginName, StringComparison.OrdinalIgnoreCase)) { List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertiesPolicy?.LoginName; viewProperty.RawValue = (object)(customer?.LoginName ?? string.Empty); viewProperty.IsReadOnly = !isAddAction; viewProperty.IsRequired = true; List <Policy> policyList; if (isAddAction) { ValidationAttributes validationAttributes1 = validationAttributes; if ((validationAttributes1 != null ? (validationAttributes1.MaxLength > 0 ? 1 : 0) : 0) != 0) { policyList = new List <Policy>() { (Policy) new MaxLengthPolicy() { MaxLengthAllow = validationAttributes.MaxLength } }; goto label_28; } } policyList = new List <Policy>(); label_28: viewProperty.Policies = (IList <Policy>)policyList; properties.Add(viewProperty); } else if (propertyName.Equals(propertiesPolicy?.Domain, StringComparison.OrdinalIgnoreCase)) { List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertiesPolicy?.Domain; viewProperty.RawValue = (object)(customer?.Domain ?? string.Empty); viewProperty.IsReadOnly = !isAddAction; viewProperty.IsRequired = true; List <Policy> policyList; if (!isAddAction) { policyList = new List <Policy>(); } else { policyList = new List <Policy>(); AvailableSelectionsPolicy selectionsPolicy = new AvailableSelectionsPolicy(); List <Selection> selectionList; if (propertiesPolicy?.Domains == null || !propertiesPolicy.Domains.Any <string>() || !(isAddAction | isEditAction)) { selectionList = new List <Selection>(); } else { CustomerPropertiesPolicy propertiesPolicy1 = propertiesPolicy; selectionList = propertiesPolicy1 != null?propertiesPolicy1.Domains.Select <string, Selection>((Func <string, Selection>)(s => { return(new Selection() { DisplayName = s, Name = s }); })).ToList <Selection>() : (List <Selection>)null; } selectionsPolicy.List = selectionList; policyList.Add((Policy)selectionsPolicy); } viewProperty.Policies = (IList <Policy>)policyList; properties.Add(viewProperty); } else if (propertyName.Equals(propertiesPolicy?.UserName, StringComparison.OrdinalIgnoreCase)) { if (!isAddAction) { List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertiesPolicy?.UserName; viewProperty.RawValue = (object)(customer?.UserName ?? string.Empty); viewProperty.IsReadOnly = !isAddAction; viewProperty.IsRequired = true; List <Policy> policyList; if (isAddAction) { ValidationAttributes validationAttributes1 = validationAttributes; if ((validationAttributes1 != null ? (validationAttributes1.MaxLength > 0 ? 1 : 0) : 0) != 0) { policyList = new List <Policy>() { (Policy) new MaxLengthPolicy() { MaxLengthAllow = validationAttributes.MaxLength } }; goto label_43; } } policyList = new List <Policy>(); label_43: viewProperty.Policies = (IList <Policy>)policyList; properties.Add(viewProperty); } } else if (propertyName.Equals(propertiesPolicy?.Language, StringComparison.OrdinalIgnoreCase)) { object obj = details?.GetPropertyValue(propertiesPolicy?.Language) ?? (((languages == null ? 0 : (languages.Any <string>() ? 1 : 0)) & (isAddAction ? 1 : 0)) != 0 ? (object)languages.FirstOrDefault <string>() : (object)string.Empty); List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertiesPolicy?.Language; viewProperty.RawValue = obj ?? (object)string.Empty; viewProperty.IsReadOnly = !isAddAction && !isEditAction; ValidationAttributes validationAttributes1 = validationAttributes; viewProperty.IsRequired = validationAttributes1 != null && validationAttributes1.MinLength > 0; viewProperty.Policies = (IList <Policy>) new List <Policy>() { (Policy) new AvailableSelectionsPolicy() { List = (languages == null || !languages.Any <string>() || !(isAddAction | isEditAction) ? new List <Selection>() : languages.Select <string, Selection>((Func <string, Selection>)(s => { return(new Selection() { DisplayName = s, Name = s }); })).ToList <Selection>()) } }; properties.Add(viewProperty); } else if (propertyName.Equals("IsCompany", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, !isAddAction, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else if (propertyName.Equals("ConsentRegulation", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, false, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else if (propertyName.Equals("ConsentProcessingContactData", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, false, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else if (propertyName.Equals("CanPurchase", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, false, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else if (propertyName.Equals("CanCreateOrders", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, false, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else if (propertyName.Equals("CanSeeDiscountPrices", StringComparison.OrdinalIgnoreCase)) { ViewProperty viewProperty = _registrationHelper.SetCustomViewProperty(details, propertyName, false, false.GetType(), true); if (viewProperty != null) { view.Properties.Add(viewProperty); } } else { PropertyInfo property = typeof(Customer).GetProperty(propertyName); if (property != (PropertyInfo)null) { List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertyName; viewProperty.RawValue = customer == null ? (object)string.Empty : property.GetValue((object)customer, (object[])null); viewProperty.IsReadOnly = !isAddAction && !isEditAction || propertyName.Equals(propertiesPolicy?.AccountNumber, StringComparison.OrdinalIgnoreCase); ValidationAttributes validationAttributes1 = validationAttributes; viewProperty.IsRequired = validationAttributes1 != null && validationAttributes1.MinLength > 0; List <Policy> policyList; if (isAddAction | isEditAction) { ValidationAttributes validationAttributes2 = validationAttributes; if ((validationAttributes2 != null ? (validationAttributes2.MaxLength > 0 ? 1 : 0) : 0) != 0) { policyList = new List <Policy>() { (Policy) new MaxLengthPolicy() { MaxLengthAllow = validationAttributes.MaxLength } }; goto label_51; } } policyList = new List <Policy>(); label_51: viewProperty.Policies = (IList <Policy>)policyList; properties.Add(viewProperty); } else { object propertyValue = details?.GetPropertyValue(propertyName); ValidationAttributes validationAttributes1 = detailsValidationPolicy.Models.FirstOrDefault <Model>((Func <Model, bool>)(m => m.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))) as ValidationAttributes; List <ViewProperty> properties = view.Properties; ViewProperty viewProperty = new ViewProperty(); viewProperty.Name = propertyName; viewProperty.RawValue = propertyValue ?? (object)string.Empty; viewProperty.IsReadOnly = !isAddAction && !isEditAction; viewProperty.IsRequired = validationAttributes1 != null && validationAttributes1.MinLength > 0; List <Policy> policyList; if (!(isAddAction | isEditAction) || validationAttributes1 == null || validationAttributes1.MaxLength <= 0) { policyList = new List <Policy>(); } else { policyList = new List <Policy>() { (Policy) new MaxLengthPolicy() { MaxLengthAllow = validationAttributes1.MaxLength } } }; viewProperty.Policies = (IList <Policy>)policyList; properties.Add(viewProperty); validationAttributes = (ValidationAttributes)null; } } } } List <string> stringList1 = new List <string>(); if (customer?.Tags != null && customer.Tags.Any <Tag>()) { List <string> stringList2 = stringList1; Customer customer1 = customer; IEnumerable <string> collection = (customer1 != null ? customer1.Tags.Where <Tag>((Func <Tag, bool>)(t => !t.Excluded)) : (IEnumerable <Tag>)null).Select <Tag, string>((Func <Tag, string>)(tag => tag.Name)); stringList2.AddRange(collection); } if (isAddAction) { return; } List <ViewProperty> properties1 = view.Properties; ViewProperty viewProperty1 = new ViewProperty(); viewProperty1.Name = "IncludedTags"; viewProperty1.RawValue = (object)stringList1.ToArray(); viewProperty1.IsReadOnly = !isAddAction && !isEditAction; viewProperty1.IsRequired = false; viewProperty1.Policies = (IList <Policy>) new List <Policy>(); viewProperty1.UiType = isEditAction ? "Tags" : "List"; viewProperty1.OriginalType = "List"; properties1.Add(viewProperty1); } }
/// <summary> /// To Custom Available Selection Policy /// </summary> /// <param name="input">AvailableSelectionsPolicy</param> /// <returns>CustomAvailableSelectionPolicy</returns> public static CustomAvailableSelectionPolicy ToCustomAvailableSelectionPolicy(this AvailableSelectionsPolicy input) { return(new CustomAvailableSelectionPolicy() { AllowMultiSelect = input.AllowMultiSelect, PolicyId = input.PolicyId, Selection = input.List.ToCustomSelections() }); }
public override async Task ModifyView(CommercePipelineExecutionContext context, Sitecore.Commerce.EntityViews.EntityView entityView, SellableItem entity, VariantDetailsComponent component) { entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.ERPManaged), DisplayName = "ERP Managed", IsRequired = false, RawValue = component.ERPManaged }); entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.PIN), DisplayName = "PIN", IsRequired = false, RawValue = component.PIN }); var languageSelectionsPolicy = new AvailableSelectionsPolicy(); var selectizeConfig = await this.GetLanguages(context); if (selectizeConfig != null) { languageSelectionsPolicy.List.AddRange(selectizeConfig.Options); } entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.Language), DisplayName = "Language", IsRequired = false, RawValue = component.Language, IsReadOnly = false, UiType = "Dropdown", Policies = new List <Policy>() { languageSelectionsPolicy } }); var formatSelectionsPolicy = new AvailableSelectionsPolicy(); var formatConfig = await this.GetFormats(context); if (formatConfig != null) { formatSelectionsPolicy.List.AddRange(formatConfig.Options); } entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.Format), DisplayName = "Format", IsRequired = false, RawValue = component.Format, IsReadOnly = false, UiType = "Dropdown", Policies = new List <Policy>() { formatSelectionsPolicy } }); entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.CanBundle), DisplayName = "Can Bundle", IsRequired = false, RawValue = component.CanBundle }); entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.Year), DisplayName = "Year", IsRequired = false, RawValue = component.Year }); entityView.Properties.Add(new ViewProperty { Name = nameof(VariantDetailsComponent.SortOrder), DisplayName = "Sort Order", IsRequired = false, RawValue = component.SortOrder }); }
/// <summary> /// Interface to Create or Update Catalog /// Currently Sellable Items cannot be dissasociatioed from parent /// </summary> /// <param name="context">context</param> /// <param name="parameter">parameter</param> /// <param name="updateExisting">Flag to determine if an existing catalog should be updated</param> /// <returns>Commerce Command</returns> public async Task <CommerceCommand> ExecuteImport(CommerceContext context, CreateOrUpdateProductParameter parameter, bool updateExisting) { SellableItem sellableItem = await this._createSellableItemCommand.Process( context, parameter.ProductId, parameter.Name, parameter.DisplayName, parameter.Description, parameter.Brand, parameter.Manufacturer, parameter.TypeOfGood, parameter.Tags.ToArray()); // If existing - Check if it should be updated if (sellableItem == null && !updateExisting) { return(this._createSellableItemCommand); } // If existing - Get Current SellableItem bool createdFlag = true; if (sellableItem == null) { createdFlag = false; // Get SellableItem sellableItem = await this._getSellableItemCommand.Process(context, $"{parameter.CatalogName}|{parameter.ProductId}|", false); } // Edit Composer Generated View Properties //****************************************** // Get General Sellable Item Overview View var sellableItemEntityView = await _getEntityViewCommand.Process(context, sellableItem.Id, "Master", "", ""); // Extract the Composer Generated View var composerView = sellableItemEntityView.ChildViews.Where(x => x.Name == "Custom Plugins View").FirstOrDefault() as EntityView; if (composerView != null) { // Call an Edit View of the Composer Generated View EntityView composerViewForEdit = await _getEntityViewCommand.Process(context, sellableItem.Id, "EditView", "EditView", composerView.ItemId); // Get the Property we want to change - This time the Taxes property for demonstration reason // At this point we could also iterate through a various number of properties based on input parameters ViewProperty propertyToChange = composerViewForEdit.Properties.FirstOrDefault(element => element.Name.Equals("Taxes")); if (propertyToChange != null) { // Special Case - Out Taxes property has an availableSelectionPolicy we want to obtain // Currently only values 0.07 and 0.19 are allowed - Selection Option Contraint from Composer AvailableSelectionsPolicy availableSelectionPolicy = propertyToChange.Policies.FirstOrDefault(element => element is AvailableSelectionsPolicy) as AvailableSelectionsPolicy; string newValue = "0.19"; // Check if our new value can be found within all selections Selection isAvailable = availableSelectionPolicy.List.FirstOrDefault(element => element.Name.Equals(newValue)); if (isAvailable != null) { // If so - change the value propertyToChange.Value = newValue; propertyToChange.RawValue = newValue; } else { // If not - Obtain the constraint and dont change the value context.Logger.LogDebug(string.Format("New Value {0} is not allowed for property {1}", newValue, propertyToChange.Name)); } } // In the end update the changed view var result = await _doActionCommand.Process(context, composerViewForEdit); } // End Edit Composer generated Propertis //********************************************* // Edit SellableItem only if it is not created within that call if (!createdFlag) { // Todo There is currently an error that if editsellableitemcommand is executed SQL server will throw a PK exception when it tries to ADD the current sellableitem again to DB // Sitecore Support Ticket ID 515689 // CatalogContentArgument catalogContentArgument = await this._editSellableItemCommand.Process(context, parameter.UpdateSellableItem(sellableItem)); } // TODO Implement Dissasociation!!! // Build Association Item string entityIdentifier = parameter.ParentName.Equals(parameter.CatalogName) ? CommerceEntity.IdPrefix <Catalog>() : CommerceEntity.IdPrefix <Category>(); string parentId = $"{entityIdentifier}{parameter.ParentName}"; // Associate CatalogReferenceArgument catalogReferenceArgument = await this._associateSellableItemToParentCommand.Process( context, parameter.CatalogName.ToEntityId <Catalog>(), parentId, sellableItem.Id); return(this._associateSellableItemToParentCommand); }