private async Task AssociateEntity(CommerceContext commerceContext, CatalogReferenceArgument arg) { await _commerceCommander.ProcessWithTransaction(commerceContext, () => _commerceCommander.Pipeline <IAssociateSellableItemToParentPipeline>().Run( arg, commerceContext.PipelineContextOptions)) .ConfigureAwait(false); }
public override async Task <ImportSingleCsvLineArgument> Run(ImportSingleCsvLineArgument arg, CommercePipelineExecutionContext context) { Condition.Requires(arg, nameof(arg)).IsNotNull(); Condition.Requires(arg.Line, nameof(arg.Line)).IsNotNull(); var catalogReferenceArgument = new CatalogReferenceArgument(arg.Line.FullEntityCatalogName, arg.Line.FullEntityCategoryName, arg.Line.FullEntitySellableItemName); await _associateSellableItemToParentPipeline.Run(catalogReferenceArgument, context); return(arg); }
/// <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); }