protected virtual bool GetEnabledStatus(SellableItem sellableItem, string variantId)
        {
            if (sellableItem.IsBundle)
            {
                // TODO: Implement support for bundles
                return(true);
            }

            if (string.IsNullOrWhiteSpace(variantId))
            {
                if (!sellableItem.HasComponent <ItemVariationsComponent>())
                {
                    return(true);
                }

                var variants = sellableItem.GetComponent <ItemVariationsComponent>().GetComponents <ItemVariationComponent>();
                foreach (var variant in variants)
                {
                    if (!variant.Disabled)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                var variant = sellableItem.GetVariation(variantId);
                return(!variant.Disabled);
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Interface to Create or Update Catalog
        /// </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, CreateOrUpdateVariantParameter parameter, bool updateExisting)
        {
            // Try to create an item variant
            SellableItem sellableItem = await this._createSellableItemVariationCommand.Process(
                context,
                parameter.ProductName.ToEntityId <SellableItem>(),
                parameter.VariantName,
                parameter.Name,
                parameter.DisplayName);

            // Check if the item already existed previously and if so if it should be updated
            if (sellableItem == null && !updateExisting)
            {
                return(this._createSellableItemVariationCommand);
            }

            // If item already existed - get it
            if (sellableItem == null)
            {
                sellableItem = await this._getSellableItemCommand.Process(context, $"{parameter.CatalogName}|{parameter.ProductName}|", false);
            }

            // Get the Item Variants
            var itemVariationComponent = sellableItem.GetVariation(parameter.VariantName);
            // TODO Edit Item Variants

            // Edit the Item
            // TODO Sitecore Issue like in ProductImporter
            CatalogContentArgument catalogContentArgument = await this._editSellableItemCommand.Process(context, sellableItem);

            return(this._getSellableItemCommand);
        }
 protected virtual bool GetPricingStatus(SellableItem sellableItem, string variantId)
 {
     if (string.IsNullOrWhiteSpace(variantId))
     {
         return(sellableItem.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice != null);
     }
     else
     {
         var variant = sellableItem.GetVariation(variantId);
         return(variant.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice != null);
     }
 }
        protected async virtual Task <string> GetInventoryStatus(string inventorySetName, SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context)
        {
            if (sellableItem.IsBundle)
            {
                // TODO: Implement support for bundle
                return("Not Supported");
            }

            if (sellableItem.HasPolicy <AvailabilityAlwaysPolicy>())
            {
                return(Engine.CatalogConstants.InventoryStatus.Perpetual);
            }

            if (string.IsNullOrWhiteSpace(variantId) && !string.IsNullOrWhiteSpace(inventorySetName))
            {
                var inventoryInformation = await Commander.Command <GetInventoryInformationCommand>().Process(context.CommerceContext, inventorySetName, sellableItem.ProductId).ConfigureAwait(false);

                if (inventoryInformation != null)
                {
                    return(this.ToInventoryStatus(inventoryInformation));
                }
            }

            if (string.IsNullOrWhiteSpace(variantId))
            {
                var variants        = sellableItem.GetComponent <ItemVariationsComponent>().GetComponents <ItemVariationComponent>();
                var allNotAvailable = true;
                foreach (var variant in variants)
                {
                    var status = await GetVariantInventoryStatus(variant, inventorySetName, context).ConfigureAwait(false);

                    allNotAvailable &= status.Equals(Engine.CatalogConstants.InventoryStatus.NotAvailable, StringComparison.InvariantCultureIgnoreCase);
                    if (status.Equals(Engine.CatalogConstants.InventoryStatus.NotAvailable, StringComparison.InvariantCultureIgnoreCase) ||
                        status.Equals(Engine.CatalogConstants.InventoryStatus.OutOfStock, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    return(status);
                }

                return(allNotAvailable ? Engine.CatalogConstants.InventoryStatus.NotAvailable : Engine.CatalogConstants.InventoryStatus.OutOfStock);
            }
            else
            {
                var variant = sellableItem.GetVariation(variantId);
                return(await GetVariantInventoryStatus(variant, inventorySetName, context).ConfigureAwait(false));
            }
        }
Beispiel #5
0
        public static ProductExtensionComponent GetProductExtensionComponent(SellableItem instance, string variationId)
        {
            ItemVariationComponent variation = instance.GetVariation(variationId);

            if (variation.HasComponent <ProductExtensionComponent>() == false)
            {
                var component = instance.GetComponent <ProductExtensionComponent>().Clone();
                variation.SetComponent(component);

                return(component);
            }
            else
            {
                return(variation.GetComponent <ProductExtensionComponent>());
            }
        }
        protected async virtual Task <PricingModel> CreatePricingModel(SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context)
        {
            PricingModel pricingModel = null;

            if (string.IsNullOrWhiteSpace(variantId))
            {
                pricingModel = new PricingModel(sellableItem.ListPrice, sellableItem.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice, sellableItem.GetComponent <MessagesComponent>());
            }
            else
            {
                var variation = sellableItem.GetVariation(variantId);
                if (variation == null)
                {
                    return(await Task.FromResult(pricingModel).ConfigureAwait(false));
                }

                pricingModel = new PricingModel(variation.ListPrice, variation.GetPolicy <PurchaseOptionMoneyPolicy>().SellPrice, variation.GetComponent <MessagesComponent>());
            }

            return(await Task.FromResult(pricingModel).ConfigureAwait(false));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sellableItem"></param>
        /// <param name="itemId"></param>
        /// <param name="editedComponentType"></param>
        /// <returns></returns>
        public Sitecore.Commerce.Core.Component GetEditedComponent(SellableItem sellableItem, string itemId, Type editedComponentType)
        {
            var components = sellableItem.Components;

            if (!string.IsNullOrEmpty(itemId))
            {
                var variation = sellableItem.GetVariation(itemId);
                if (variation != null)
                {
                    components = variation.ChildComponents;
                }
            }

            Sitecore.Commerce.Core.Component component = components.SingleOrDefault(comp => comp.GetType() == editedComponentType);
            if (component == null)
            {
                component = (Sitecore.Commerce.Core.Component)Activator.CreateInstance(editedComponentType);
                components.Add(component);
            }

            return(component);
        }
Beispiel #8
0
        public async Task AddEntityProperties(CommercePipelineExecutionContext context, EntityView entityView, EntityView detailsView, SellableItem entity, bool isAddAction, bool isEditAction, string viewName)
        {
            var policy = context.GetPolicy <KnownCatalogViewsPolicy>();
            var itemId = entityView.ItemId;

            if (!string.IsNullOrEmpty(itemId))
            {
                detailsView.ItemId = itemId;
            }
            var variation     = entity.GetVariation(itemId);
            var flag1         = variation != null;
            var properties1   = detailsView.Properties;
            var viewProperty1 = new ViewProperty
            {
                Name       = flag1 ? "VariantId" : "ProductId",
                RawValue   = flag1 ? variation.Id : entity?.ProductId ?? string.Empty,
                IsReadOnly = !isAddAction,
                IsRequired = isAddAction | isEditAction,
                IsHidden   = false
            };

            properties1.Add(viewProperty1);
            var properties2   = detailsView.Properties;
            var viewProperty2 = new ViewProperty
            {
                Name       = "Name",
                RawValue   = variation != null ? variation.Name : entity?.Name ?? string.Empty,
                IsReadOnly = !isAddAction,
                IsRequired = isAddAction,
                IsHidden   = !isAddAction
            };

            properties2.Add(viewProperty2);
            var properties3   = detailsView.Properties;
            var viewProperty3 = new ViewProperty
            {
                Name       = "DisplayName",
                RawValue   = variation != null ? variation.DisplayName : entity?.DisplayName ?? string.Empty,
                IsReadOnly = !isAddAction && !isEditAction,
                IsRequired = isAddAction | isEditAction,
                IsHidden   = false
            };

            properties3.Add(viewProperty3);
            if (!isAddAction && !isEditAction)
            {
                var definitions = new List <string>();
                if (entity != null && entity.HasComponent <CatalogsComponent>())
                {
                    entity.GetComponent <CatalogsComponent>().Catalogs.Where(c => !string.IsNullOrEmpty(c.ItemDefinition)).ForEach(c => definitions.Add(
                                                                                                                                       $"{c.Name} - {c.ItemDefinition}"));
                }
                var properties4   = detailsView.Properties;
                var viewProperty4 = new ViewProperty
                {
                    Name         = "ItemDefinitions",
                    RawValue     = definitions,
                    IsReadOnly   = true,
                    IsRequired   = false,
                    UiType       = "List",
                    OriginalType = "List"
                };
                properties4.Add(viewProperty4);
            }
            var properties5   = detailsView.Properties;
            var viewProperty5 = new ViewProperty
            {
                Name       = "Description",
                RawValue   = variation != null ? variation.Description : entity?.Description ?? string.Empty,
                IsReadOnly = !isAddAction && !isEditAction,
                IsRequired = false,
                IsHidden   = false
            };

            properties5.Add(viewProperty5);
            var properties6   = detailsView.Properties;
            var viewProperty6 = new ViewProperty
            {
                Name       = "Brand",
                RawValue   = entity?.Brand ?? string.Empty,
                IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0,
                IsRequired = false,
                IsHidden   = false
            };

            properties6.Add(viewProperty6);
            var properties7   = detailsView.Properties;
            var viewProperty7 = new ViewProperty
            {
                Name       = "Manufacturer",
                RawValue   = entity?.Manufacturer ?? string.Empty,
                IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0,
                IsRequired = false,
                IsHidden   = false
            };

            properties7.Add(viewProperty7);
            var properties8   = detailsView.Properties;
            var viewProperty8 = new ViewProperty
            {
                Name       = "TypeOfGood",
                RawValue   = entity?.TypeOfGood ?? string.Empty,
                IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0,
                IsRequired = false,
                IsHidden   = false
            };

            properties8.Add(viewProperty8);
            var source        = ((variation?.Tags ?? entity?.Tags) ?? new List <Tag>()).Select(x => x.Name);
            var properties9   = detailsView.Properties;
            var viewProperty9 = new ViewProperty
            {
                Name         = "Tags",
                RawValue     = source.ToArray(),
                IsReadOnly   = !isAddAction && !isEditAction,
                IsRequired   = false,
                IsHidden     = false,
                UiType       = isEditAction | isAddAction ? "Tags" : "List",
                OriginalType = "List"
            };

            properties9.Add(viewProperty9);
            var flag2 = entityView.Name.Equals(policy.ConnectSellableItem, StringComparison.OrdinalIgnoreCase);

            if (flag2)
            {
                var properties4   = detailsView.Properties;
                var viewProperty4 = new ViewProperty
                {
                    Name       = "VariationProperties",
                    RawValue   = string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties4.Add(viewProperty4);
                var properties10   = detailsView.Properties;
                var viewProperty10 = new ViewProperty
                {
                    Name       = "SitecoreId",
                    RawValue   = entity?.SitecoreId ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = true
                };
                properties10.Add(viewProperty10);
                var properties11   = detailsView.Properties;
                var viewProperty11 = new ViewProperty
                {
                    Name       = "ParentCatalogList",
                    RawValue   = entity?.ParentCatalogList ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = true
                };
                properties11.Add(viewProperty11);
                var properties12   = detailsView.Properties;
                var viewProperty12 = new ViewProperty
                {
                    Name       = "ParentCategoryList",
                    RawValue   = entity?.ParentCategoryList ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = true
                };
                properties12.Add(viewProperty12);
            }
            if (isAddAction || isEditAction)
            {
                return;
            }
            var dictionary  = new Dictionary <string, object>();
            var entityView1 = new EntityView
            {
                DisplayName   = "Identifiers",
                Name          = "Identifiers",
                UiHint        = "Flat",
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = itemId
            };
            var entityView2 = entityView1;

            if (entity != null && entity.HasComponent <IdentifiersComponent>(itemId) | flag2)
            {
                var component = entity.GetComponent <IdentifiersComponent>(itemId);
                dictionary.Add("ISBN", component.ISBN);
                dictionary.Add("LEICode", component.LEICode);
                dictionary.Add("SKU", component.SKU);
                dictionary.Add("TaxID", component.TaxID);
                dictionary.Add("gtin8", component.gtin8);
                dictionary.Add("gtin12", component.gtin12);
                dictionary.Add("gtin13", component.gtin13);
                dictionary.Add("mbm", component.mbm);
                dictionary.Add("ISSN", component.ISSN);
                foreach (var keyValuePair in dictionary)
                {
                    var properties4   = entityView2.Properties;
                    var viewProperty4 = new ViewProperty
                    {
                        Name       = keyValuePair.Key,
                        RawValue   = keyValuePair.Value ?? string.Empty,
                        IsReadOnly = true,
                        IsRequired = false,
                        IsHidden   = false
                    };
                    properties4.Add(viewProperty4);
                }
            }
            var entityView3 = new EntityView
            {
                DisplayName   = "Display Properties",
                Name          = "DisplayProperties",
                UiHint        = "Flat",
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = itemId
            };
            var entityView4 = entityView3;

            dictionary.Clear();
            if (entity != null && entity.HasComponent <DisplayPropertiesComponent>(itemId) | flag2)
            {
                var component     = entity.GetComponent <DisplayPropertiesComponent>(itemId);
                var properties4   = entityView4.Properties;
                var viewProperty4 = new ViewProperty
                {
                    Name       = "Color",
                    RawValue   = component.Color ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties4.Add(viewProperty4);
                var properties10   = entityView4.Properties;
                var viewProperty10 = new ViewProperty
                {
                    Name       = "Size",
                    RawValue   = component.Size ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties10.Add(viewProperty10);
                var properties11   = entityView4.Properties;
                var viewProperty11 = new ViewProperty
                {
                    Name       = "DisambiguatingDescription",
                    RawValue   = component.DisambiguatingDescription ?? string.Empty,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties11.Add(viewProperty11);
                var properties12   = entityView4.Properties;
                var viewProperty12 = new ViewProperty
                {
                    Name       = "DisplayOnSite",
                    RawValue   = component.DisplayOnSite,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties12.Add(viewProperty12);
                var properties13   = entityView4.Properties;
                var viewProperty13 = new ViewProperty
                {
                    Name       = "DisplayInProductList",
                    RawValue   = component.DisplayInProductList,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties13.Add(viewProperty13);
                var properties14   = entityView4.Properties;
                var viewProperty14 = new ViewProperty
                {
                    Name       = "Style",
                    RawValue   = component.Style,
                    IsReadOnly = true,
                    IsRequired = false,
                    IsHidden   = false
                };
                properties14.Add(viewProperty14);
            }
            var entityView5 = new EntityView
            {
                DisplayName   = "Images",
                Name          = "Images",
                UiHint        = "Table",
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = itemId
            };
            var entityView6 = entityView5;
            var entityView7 = new EntityView
            {
                DisplayName   = "Item Specifications",
                Name          = "ItemSpecifications",
                UiHint        = "Flat",
                EntityId      = entityView.EntityId,
                EntityVersion = entityView.EntityVersion,
                ItemId        = itemId
            };
            var entityView8 = entityView7;

            dictionary.Clear();
            if (entity != null && entity.HasComponent <ItemSpecificationsComponent>(itemId) | flag2)
            {
                var component = entity.GetComponent <ItemSpecificationsComponent>(itemId);
                if (component.AreaServed == null)
                {
                    component.AreaServed = new GeoLocation();
                }
                var city       = component.AreaServed.City;
                var region     = component.AreaServed.Region;
                var postalCode = component.AreaServed.PostalCode;
                var str1       = string.IsNullOrWhiteSpace(region) ? "" : ", " + region;
                var str2       = string.IsNullOrWhiteSpace(postalCode) ? "" : ", " + postalCode;
                var str3       = $"{city}{str1}{str2}".TrimStart(',');
                dictionary.Add("AreaServed", str3);
                if (flag2)
                {
                    dictionary.Add("Weight", component.Weight);
                    dictionary.Add("WeightUnitOfMeasure", component.WeightUnitOfMeasure);
                    dictionary.Add("Length", component.Length);
                    dictionary.Add("Width", component.Width);
                    dictionary.Add("Height", component.Height);
                    dictionary.Add("DimensionsUnitOfMeasure", component.DimensionsUnitOfMeasure);
                    dictionary.Add("SizeOnDisk", component.Weight);
                    dictionary.Add("SizeOnDiskUnitOfMeasure", component.WeightUnitOfMeasure);
                }
                else
                {
                    dictionary.Add("Weight", $"{component.Weight} {component.WeightUnitOfMeasure}");
                    var str4 = string.Format("{0}{3}x{1}{3}x{2}{3}", component.Width, component.Height, component.Length, component.DimensionsUnitOfMeasure);
                    dictionary.Add("Dimensions", str4);
                    dictionary.Add("DigitalProperties", $"{component.SizeOnDisk} {component.SizeOnDiskUnitOfMeasure}");
                }
                foreach (var keyValuePair in dictionary)
                {
                    var properties4   = entityView8.Properties;
                    var viewProperty4 = new ViewProperty
                    {
                        Name       = keyValuePair.Key,
                        RawValue   = keyValuePair.Value,
                        IsReadOnly = true,
                        IsRequired = false,
                        IsHidden   = false
                    };
                    properties4.Add(viewProperty4);
                }
            }
            this.AddSellableItemPricing(entityView, entity, variation, context);
            AddSellableItemVariations(entityView, entity, context);
            await AddSellableItemParentCategories(entityView, entity, context);

            entityView.ChildViews.Add(entityView2);
            entityView.ChildViews.Add(entityView4);
            entityView.ChildViews.Add(entityView6);
            entityView.ChildViews.Add(entityView8);
            if (!entityView.Name.Equals("Variant", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            var properties15   = entityView.Properties;
            var viewProperty15 = new ViewProperty
            {
                DisplayName = "DisplayName",
                Name        = "DisplayName",
                RawValue    = variation?.DisplayName
            };

            properties15.Add(viewProperty15);
        }
Beispiel #9
0
        public override async Task <bool> Run(SellableItemInventorySetsArgument argument, CommercePipelineExecutionContext context)
        {
            AssociateStoreInventoryToSellablteItemBlock associateStoreInventoryToSellablteItemBlock = this;

            Condition.Requires(argument).IsNotNull(string.Format("{0}: The argument can not be null", argument));

            string         sellableItemId = argument.SellableItemId;
            CommerceEntity entity         = await associateStoreInventoryToSellablteItemBlock._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), sellableItemId, false), context).ConfigureAwait(false);

            CommercePipelineExecutionContext executionContext;

            if (!(entity is SellableItem))
            {
                executionContext = context;
                CommerceContext commerceContext = context.CommerceContext;
                string          validationError = context.GetPolicy <KnownResultCodes>().ValidationError;
                string          commerceTermKey = "EntityNotFound";
                object[]        args            = new object[1]
                {
                    argument.SellableItemId
                };
                string defaultMessage = string.Format("Entity {0} was not found.", argument.SellableItemId);
                executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context);
                executionContext = null;
                return(false);
            }

            SellableItem sellableItem = entity as SellableItem;

            if ((string.IsNullOrEmpty(argument.VariationId)) & sellableItem.HasComponent <ItemVariationsComponent>())
            {
                executionContext = context;
                executionContext.Abort(await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "AssociateInventoryWithVariant", new object[0], "Can not associate inventory to the base sellable item. Use one of the variants instead.").ConfigureAwait(false), context);
                executionContext = null;
                return(false);
            }

            ItemVariationComponent sellableItemVariation = null;

            if (argument.VariationId != null)
            {
                sellableItemVariation = sellableItem.GetVariation(argument.VariationId);
                if (!string.IsNullOrEmpty(argument.VariationId) && sellableItemVariation == null)
                {
                    executionContext = context;
                    CommerceContext commerceContext = context.CommerceContext;
                    string          validationError = context.GetPolicy <KnownResultCodes>().ValidationError;
                    string          commerceTermKey = "ItemNotFound";
                    object[]        args            = new object[1]
                    {
                        argument.VariationId
                    };
                    string defaultMessage = string.Format("Item '{0}' was not found.", argument.VariationId);
                    executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context);
                    executionContext = null;
                    return(false);
                }
            }

            List <InventoryAssociation> inventoryAssociations = new List <InventoryAssociation>();

            foreach (var inventorySetId in argument.InventorySetIds)
            {
                bool   isUpdate = false;
                Random rnd      = new Random();
                InventoryInformation inventoryInformation = await associateStoreInventoryToSellablteItemBlock._getInventoryInformationCommand
                                                            .Process(context.CommerceContext, inventorySetId, argument.SellableItemId, argument.VariationId, false)
                                                            .ConfigureAwait(false);

                IFindEntitiesInListPipeline entitiesInListPipeline  = associateStoreInventoryToSellablteItemBlock._findEntitiesInListPipeline;
                FindEntitiesInListArgument  entitiesInListArgument1 = new FindEntitiesInListArgument(typeof(SellableItem), string.Format("{0}-{1}", "InventorySetToInventoryInformation", inventorySetId.SimplifyEntityName()), 0, int.MaxValue);
                entitiesInListArgument1.LoadEntities = false;
                CommercePipelineExecutionContext context1 = context;
                FindEntitiesInListArgument       entitiesInListArgument2 = await entitiesInListPipeline.Run(entitiesInListArgument1, context1).ConfigureAwait(false);

                if (inventoryInformation != null && entitiesInListArgument2 != null)
                {
                    List <ListEntityReference> entityReferences = entitiesInListArgument2.EntityReferences.ToList();
                    string id = inventoryInformation.Id;

                    if (entityReferences != null && entityReferences.Any(er => er.EntityId == id))
                    {
                        inventoryInformation.Quantity = rnd.Next(50);
                        isUpdate = true;
                    }
                }

                if (!isUpdate)
                {
                    string inventorySetName = string.Format("{0}-{1}", inventorySetId.SimplifyEntityName(), sellableItem.ProductId);
                    if (!string.IsNullOrEmpty(argument.VariationId))
                    {
                        inventorySetName += string.Format("-{0}", argument.VariationId);
                    }

                    InventoryInformation inventoryInformation1 = new InventoryInformation();
                    inventoryInformation1.Id = string.Format("{0}{1}", CommerceEntity.IdPrefix <InventoryInformation>(), inventorySetName);

                    inventoryInformation1.FriendlyId = inventorySetName;
                    EntityReference entityReference1 = new EntityReference(inventorySetId, "");
                    inventoryInformation1.InventorySet = entityReference1;
                    EntityReference entityReference2 = new EntityReference(argument.SellableItemId, "");
                    inventoryInformation1.SellableItem = entityReference2;
                    string variationId = argument.VariationId;
                    inventoryInformation1.VariationId = variationId;
                    inventoryInformation1.Quantity    = rnd.Next(50);
                    inventoryInformation = inventoryInformation1;
                }

                inventoryInformation.GetComponent <TransientListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <InventoryInformation>());
                PersistEntityArgument persistEntityArgument1 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument((CommerceEntity)inventoryInformation), context).ConfigureAwait(false);

                RelationshipArgument relationshipArgument = await associateStoreInventoryToSellablteItemBlock._createRelationshipPipeline.Run(new RelationshipArgument(inventorySetId, inventoryInformation.Id, "InventorySetToInventoryInformation"), context).ConfigureAwait(false);

                InventoryAssociation inventoryAssociation = new InventoryAssociation()
                {
                    InventoryInformation = new EntityReference(inventoryInformation.Id, ""),
                    InventorySet         = new EntityReference(inventorySetId, "")
                };

                inventoryAssociations.Add(inventoryAssociation);
            }

            (sellableItemVariation != null ? sellableItemVariation.GetComponent <InventoryComponent>() : sellableItem.GetComponent <InventoryComponent>()).InventoryAssociations.AddRange(inventoryAssociations);

            PersistEntityArgument persistEntityArgument2 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument(sellableItem), context).ConfigureAwait(false);

            return(true);
        }