Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Interface to Create or Update Catalog
        /// Currently no dissasociation of categories is implemented
        /// </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, CreateOrUpdateCategoryParameter parameter, bool updateExisting)
        {
            // Try to get existing Category
            string   categoryId = $"{CommerceEntity.IdPrefix<Category>()}{parameter.CatalogName}-{parameter.Name}";
            Category category   = await this._getCategoryCommand.Process(context, categoryId);

            // If existing - Check if it should be updated
            if (category != null && !updateExisting)
            {
                return(this._getCategoryCommand);
            }

            // If existing - Get Current Category
            bool createdFlag = true;

            if (category == null)
            {
                createdFlag = false;
                category    = await this._createCategoryCommand.Process(context, parameter.CatalogName, parameter.Name, parameter.DisplayName, parameter.Description);
            }

            // Only update category if it was not created previously
            if (!createdFlag)
            {
                CatalogContentArgument editCategoryResult = await this._editCategoryCommand.Process(context, category, parameter.DisplayName, parameter.Description);
            }

            // Workaround to get all Parent Entities for the current Entity
            List <string> parentEntities = await this._associatedItemRetrievalService.GetAllParentEnitites(context, category.Name, parameter.CatalogName);

            // Check with the given paremter.ParentNames and the existing Parents, which ones have to be deleted
            foreach (string parentEntity in parentEntities)
            {
                // If both lists containt the entity, it should not be deleted
                if (parameter.ParentNames.Contains(parentEntity))
                {
                    continue;
                }

                // TargetName = Current Item
                string targetName;
                // SourceName = Parent
                string sourceName;
                // RelationshiptTypes - "CatalogToCategory","CatalogToSellableItem","CategoryToCategory","CategoryToSellableItem"
                string relationshipType;

                // Check if the entity is a catalog or category
                if (parentEntity.Equals(parameter.CatalogName))
                {
                    // Disassociate Catalog To Category
                    targetName       = category.Id;
                    sourceName       = $"{parentEntity}".ToEntityId <Catalog>();
                    relationshipType = "CatalogToCategory";
                }
                else
                {
                    // Disassociate Category To Category
                    targetName       = category.Id;
                    sourceName       = $"{parameter.CatalogName}-{parentEntity}".ToEntityId <Category>();
                    relationshipType = "CategoryToCategory";
                }

                RelationshipArgument relationshipArgument = await this._deleteRelationshipCommand.Process(context, sourceName, targetName, relationshipType);
            }

            // Associate category to parent
            string catalogId = parameter.CatalogName.ToEntityId <Catalog>();

            foreach (string parentName in parameter.ParentNames)
            {
                string entityIdentifier = parentName.Equals(parameter.CatalogName)
                  ? CommerceEntity.IdPrefix <Catalog>()
                  : $"{CommerceEntity.IdPrefix<Category>()}{parameter.CatalogName}-";
                string parentId = $"{entityIdentifier}{parentName}";
                CatalogContentArgument associateCategoryToParentResult = await this._associateCategoryToParentCommand.Process(context, catalogId, parentId, category.Id);
            }

            return(this._associateCategoryToParentCommand);
        }