Esempio n. 1
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        public static dataModel.CategoryBase ToDataModel(this coreModel.Category category)
        {
            var retVal = new dataModel.Category();

            var id = retVal.Id;

            retVal.InjectFrom(category);
            if (category.Id == null)
            {
                retVal.Id = id;
            }
            retVal.ParentCategoryId = category.ParentId;
            retVal.EndDate          = DateTime.UtcNow.AddYears(100);
            retVal.StartDate        = DateTime.UtcNow;

            if (category.PropertyValues != null)
            {
                retVal.CategoryPropertyValues = new ObservableCollection <dataModel.CategoryPropertyValue>();
                retVal.CategoryPropertyValues.AddRange(category.PropertyValues.Select(x => x.ToDataModel <dataModel.CategoryPropertyValue>()).OfType <dataModel.CategoryPropertyValue>());
            }

            if (category.Links != null)
            {
                retVal.OutgoingLinks = new ObservableCollection <dataModel.CategoryRelation>();
                retVal.OutgoingLinks.AddRange(category.Links.Select(x => x.ToDataModel(category)));
            }

            return(retVal);
        }
        // add not existing products or variations.
        public void DoImport(ImportManifest importManifest, Action<ImportProcessInfo> progressCallback)
        {
            var progressInfo = new ImportProcessInfo();
            progressInfo.Description = "Importing ...";
            progressCallback(progressInfo);

            _defaultCategory = GetCategoriesByCode(importManifest.DefaultCategoryCode, importManifest.CatalogId);
            _catalogProperties = _propertyService.GetAllCatalogProperties(importManifest.CatalogId);
            var zipModulePaths = Directory.GetFiles(importManifest.PackagesPath);
            progressInfo.TotalCount = zipModulePaths.Count();

            foreach (var zipModulePath in zipModulePaths)
            {
                ModuleManifest manifest = null;
                byte[] icon = null;
                using (ZipArchive archive = ZipFile.OpenRead(zipModulePath))
                {
                    var manifestEntry = archive.Entries.FirstOrDefault(x => x.Name == importManifest.ManifestFileName);
                    using (var manifestStream = manifestEntry.Open())
                    {
                        manifest = ManifestReader.Read(manifestStream);
                    }

                    icon = ReadIcon(archive, manifest.IconUrl);
                }

                var publishingResult = Publish(manifest, zipModulePath, icon);

                progressInfo.CreatedCount += publishingResult == PublishingResult.Product ? 1 : 0;
                progressInfo.UpdatedCount += publishingResult == PublishingResult.Variation ? 1 : 0;
                progressInfo.ProcessedCount++;
                progressCallback(progressInfo);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategoryBase">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.CategoryBase dbCategoryBase, coreModel.Catalog catalog,
                                                     coreModel.Property[] properties = null, dataModel.Category[] allParents = null)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            var retVal = new coreModel.Category();

            retVal.InjectFrom(dbCategoryBase);
            retVal.CatalogId = catalog.Id;
            retVal.Catalog   = catalog;
            retVal.ParentId  = dbCategoryBase.ParentCategoryId;

            var dbCategory = dbCategoryBase as dataModel.Category;

            if (dbCategory != null)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
                retVal.Virtual        = catalog.Virtual;
                retVal.Links          = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();
            }

            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

            return(retVal);
        }
Esempio n. 4
0
        public coreModel.Category Create(coreModel.Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            var dbCategory = category.ToDataModel();

            using (var repository = _catalogRepositoryFactory())
            {
                repository.Add(dbCategory);
                CommitChanges(repository);
            }
            //Need add seo separately
            if (category.SeoInfos != null)
            {
                foreach (var seoInfo in category.SeoInfos)
                {
                    seoInfo.ObjectId   = dbCategory.Id;
                    seoInfo.ObjectType = typeof(coreModel.Category).Name;
                    _commerceService.UpsertSeo(seoInfo);
                }
            }
            category.Id = dbCategory.Id;
            return(GetById(dbCategory.Id));
        }
Esempio n. 5
0
		public static moduleModel.Category ToModuleModel(this webModel.Category category)
		{
			var retVal = new moduleModel.Category();
			retVal.InjectFrom(category);
			retVal.SeoInfos = category.SeoInfos;
			if (category.Links != null)
			{
				retVal.Links = category.Links.Select(x => x.ToModuleModel()).ToList();
			}

		
			if (category.Properties != null)
			{
				retVal.PropertyValues = new List<moduleModel.PropertyValue>();
				foreach (var property in category.Properties)
				{
					foreach(var propValue in property.Values)
					{
						propValue.ValueType = property.ValueType;
						//Need populate required fields
						propValue.PropertyName = property.Name;
						retVal.PropertyValues.Add(propValue.ToModuleModel());
					}
				}
			
			}

			return retVal;
		}
Esempio n. 6
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        public static dataModel.Category ToDataModel(this coreModel.Category category, PrimaryKeyResolvingMap pkMap)
        {
            var retVal = new dataModel.Category();

            pkMap.AddPair(category, retVal);
            retVal.InjectFrom(category);

            retVal.ParentCategoryId = category.ParentId;
            retVal.EndDate          = DateTime.UtcNow.AddYears(100);
            retVal.StartDate        = DateTime.UtcNow;
            retVal.IsActive         = category.IsActive ?? true;

            if (category.PropertyValues != null)
            {
                retVal.CategoryPropertyValues = new ObservableCollection <dataModel.PropertyValue>();
                retVal.CategoryPropertyValues.AddRange(category.PropertyValues.Select(x => x.ToDataModel(pkMap)));
            }

            if (category.Links != null)
            {
                retVal.OutgoingLinks = new ObservableCollection <dataModel.CategoryRelation>();
                retVal.OutgoingLinks.AddRange(category.Links.Select(x => x.ToDataModel(category)));
            }

            #region Images
            if (category.Images != null)
            {
                retVal.Images = new ObservableCollection <dataModel.Image>(category.Images.Select(x => x.ToDataModel(pkMap)));
            }
            #endregion

            return(retVal);
        }
        public static moduleModel.Category ToModuleModel(this webModel.Category category)
        {
            var retVal = new moduleModel.Category();

            retVal.InjectFrom(category);
            retVal.SeoInfos = category.SeoInfos;

            if (category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToCoreModel()).ToList();
            }

            if (category.Properties != null)
            {
                retVal.PropertyValues = new List <moduleModel.PropertyValue>();
                foreach (var property in category.Properties)
                {
                    foreach (var propValue in property.Values)
                    {
                        propValue.ValueType = property.ValueType;
                        //Need populate required fields
                        propValue.PropertyId   = property.Id;
                        propValue.PropertyName = property.Name;
                        retVal.PropertyValues.Add(propValue.ToCoreModel());
                    }
                }
            }

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToCoreModel()).ToList();
            }

            return(retVal);
        }
Esempio n. 8
0
        public static moduleModel.Category ToModuleModel(this webModel.Category category)
        {
            var retVal = new moduleModel.Category();
            retVal.InjectFrom(category);

            return retVal;
        }
Esempio n. 9
0
        public static moduleModel.Category ToModuleModel(this webModel.Category category)
        {
            var retVal = new moduleModel.Category();

            retVal.InjectFrom(category);

            return(retVal);
        }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog = category.Catalog.ToWebModel();
            //Reset properties for size economy
            retVal.Catalog.Properties = null;
            retVal.SeoInfos           = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                foreach (var property in category.Properties)
                {
                    var webModelProperty = property.ToWebModel();
                    //Reset dict values to decrease response size
                    webModelProperty.DictionaryValues = null;
                    webModelProperty.Values           = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable     = true;
                    webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }
            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }
            return(retVal);
        }
        public coreModel.Category Create(coreModel.Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            Create(new[] { category });
            return(GetById(category.Id, Domain.Catalog.Model.CategoryResponseGroup.Info));
        }
Esempio n. 12
0
        public coreModel.CatalogProduct[] GetByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup)
        {
            // TODO: Optimize performance (Sasha)
            // 1. Catalog should be cached and not retrieved every time from the db
            // 2. SEO info can be retrieved for all items at once instead of one by one
            // 3. Optimize how main variation is loaded
            // 4. Associations shouldn't be loaded always and must be optimized as well
            // 5. No need to get properties meta data to just retrieve property ID
            var retVal = new List <coreModel.CatalogProduct>();

            using (var repository = _catalogRepositoryFactory())
            {
                var dbItems = repository.GetItemByIds(itemIds, respGroup);

                SeoInfo[] seoInfos = null;
                if ((respGroup & coreModel.ItemResponseGroup.Seo) == coreModel.ItemResponseGroup.Seo)
                {
                    seoInfos = _commerceService.GetObjectsSeo(dbItems.Select(x => x.Id).ToArray()).ToArray();
                }

                var categoriesIds = dbItems.SelectMany(x => x.CategoryLinks).Select(x => x.CategoryId).Distinct().ToArray();
                var dbCategories  = repository.GetCategoriesByIds(categoriesIds);
                foreach (var dbItem in dbItems)
                {
                    var associatedProducts = new List <coreModel.CatalogProduct>();
                    if ((respGroup & coreModel.ItemResponseGroup.ItemAssociations) == coreModel.ItemResponseGroup.ItemAssociations)
                    {
                        if (dbItem.AssociationGroups.Any())
                        {
                            foreach (var association in dbItem.AssociationGroups.SelectMany(x => x.Associations))
                            {
                                var associatedProduct = GetById(association.ItemId, coreModel.ItemResponseGroup.ItemAssets);
                                associatedProducts.Add(associatedProduct);
                            }
                        }
                    }
                    var dbCatalog = repository.GetCatalogById(dbItem.CatalogId);

                    var catalog = dbCatalog.ToCoreModel();
                    coreModel.Category category = null;
                    if (dbItem.Category != null)
                    {
                        category = dbItem.Category.ToCoreModel(catalog);
                    }

                    var item = dbItem.ToCoreModel(catalog: catalog, category: category, associatedProducts: associatedProducts.ToArray());
                    item.SeoInfos = seoInfos != null?seoInfos.Where(x => x.ObjectId == dbItem.Id).ToList() : null;

                    retVal.Add(item);
                }
            }

            return(retVal.ToArray());
        }
Esempio n. 13
0
        public coreModel.CatalogProduct[] GetByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup)
        {
            // TODO: Optimize performance (Sasha)
            // Associations shouldn't be loaded always and must be optimized as well
            var retVal = new List <coreModel.CatalogProduct>();

            using (var repository = _catalogRepositoryFactory())
            {
                var dbItems = repository.GetItemByIds(itemIds, respGroup);

                SeoInfo[] seoInfos = null;
                if ((respGroup & coreModel.ItemResponseGroup.Seo) == coreModel.ItemResponseGroup.Seo)
                {
                    seoInfos = _commerceService.GetObjectsSeo(dbItems.Select(x => x.Id).ToArray()).ToArray();
                }

                var categoriesIds = dbItems.SelectMany(x => x.CategoryLinks).Select(x => x.CategoryId).Distinct().ToArray();
                var dbCategories  = repository.GetCategoriesByIds(categoriesIds);

                foreach (var dbItem in dbItems)
                {
                    var associatedProducts = new List <coreModel.CatalogProduct>();
                    if ((respGroup & coreModel.ItemResponseGroup.ItemAssociations) == coreModel.ItemResponseGroup.ItemAssociations)
                    {
                        if (dbItem.AssociationGroups.Any())
                        {
                            foreach (var association in dbItem.AssociationGroups.SelectMany(x => x.Associations))
                            {
                                var associatedProduct = GetById(association.ItemId, coreModel.ItemResponseGroup.ItemAssets);
                                associatedProducts.Add(associatedProduct);
                            }
                        }
                    }
                    var dbCatalog = repository.GetCatalogById(dbItem.CatalogId);

                    var catalog = dbCatalog.ToCoreModel();
                    coreModel.Category category = null;
                    if (dbItem.Category != null)
                    {
                        var allParents = repository.GetAllCategoryParents(dbItem.Category).ToArray();
                        category = dbItem.Category.ToCoreModel(catalog, null, allParents);
                    }

                    var item = dbItem.ToCoreModel(catalog: catalog, category: category, associatedProducts: associatedProducts.ToArray());
                    item.SeoInfos = seoInfos != null?seoInfos.Where(x => x.ObjectId == dbItem.Id).ToList() : null;

                    retVal.Add(item);
                }
            }

            return(retVal.ToArray());
        }
Esempio n. 14
0
        public static webModel.Category ToWebModel(this moduleModel.Category category, moduleModel.Property[] properties = null)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);
            retVal.Catalog  = category.Catalog.ToWebModel();
            retVal.SeoInfos = category.SeoInfos;

            if (category.Parents != null)
            {
                retVal.Parents = category.Parents.ToDictionary(x => x.Id, x => x.Name);
            }
            //For virtual category links not needed
            if (!category.Virtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }
            retVal.Properties = new List <webModel.Property>();
            //Need add property for each meta info
            if (properties != null)
            {
                retVal.Properties = new List <webModel.Property>();
                foreach (var property in properties)
                {
                    var webModelProperty = property.ToWebModel();
                    webModelProperty.Values       = new List <webModel.PropertyValue>();
                    webModelProperty.IsManageable = true;
                    webModelProperty.IsReadOnly   = property.Type != moduleModel.PropertyType.Category;
                    retVal.Properties.Add(webModelProperty);
                }
            }

            //Populate property values
            if (category.PropertyValues != null)
            {
                foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                {
                    var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    if (property == null)
                    {
                        //Need add dummy property for each value without property
                        property = new webModel.Property(propValue, category.CatalogId, category.Id, moduleModel.PropertyType.Category);
                        retVal.Properties.Add(property);
                    }
                    property.Values.Add(propValue);
                }
            }

            return(retVal);
        }
Esempio n. 15
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this coreModel.Category source, dataModel.Category target, PrimaryKeyResolvingMap pkMap)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            //TODO: temporary solution because partial update replaced not nullable properties in db entity
            if (source.IsActive != null)
            {
                target.IsActive = source.IsActive.Value;
            }
            //Handle three valuable states (null, empty and have value states) for case when need reset catalog or category
            if (source.CatalogId == String.Empty)
            {
                target.CatalogId = null;
            }
            if (source.ParentId == String.Empty)
            {
                target.ParentCategoryId = null;
            }


            var dbSource = source.ToDataModel(pkMap) as dataModel.Category;
            var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
                var patchInjectionPolicy = new PatchInjection <dataModel.Category>(x => x.Code, x => x.Name, x => x.TaxType, x => x.CatalogId, x => x.ParentCategoryId);
                dbTarget.InjectFrom(patchInjectionPolicy, dbSource);

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

                if (!dbSource.OutgoingLinks.IsNullCollection())
                {
                    dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
                }

                if (!dbSource.Images.IsNullCollection())
                {
                    dbSource.Images.Patch(dbTarget.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
                }
            }
        }
Esempio n. 16
0
        public static webModel.Category ToWebModel(this moduleModel.Category category)
        {
            var retVal = new webModel.Category();

            retVal.InjectFrom(category);

            if (category.Parents != null && category.Parents.Any())
            {
                //retVal.Parents = category.Parents.Select(x => x.ToWebModel(keywords != null ? keywords.Where(k => k.KeywordValue == x.Id) : null));
                retVal.Parents = category.Parents.Select(x => x.ToWebModel());
            }

            if (category.SeoInfos != null)
            {
                retVal.Seo = category.SeoInfos.Select(x => x.ToWebModel());
            }

            return(retVal);
        }
Esempio n. 17
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategory">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.Category dbCategory, coreModel.Catalog catalog,
                                                     coreModel.Property[] properties = null, dataModel.Category[] allParents = null)
        {
            if (catalog == null)
            {
                throw new ArgumentNullException("catalog");
            }

            var retVal = new coreModel.Category();

            retVal.InjectFrom(dbCategory);
            retVal.CatalogId = catalog.Id;
            retVal.Catalog   = catalog;
            retVal.ParentId  = dbCategory.ParentCategoryId;
            retVal.IsActive  = dbCategory.IsActive;


            retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
            retVal.Virtual        = catalog.Virtual;
            retVal.Links          = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();


            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

            //Try to inherit taxType from parent category
            if (retVal.TaxType == null && retVal.Parents != null)
            {
                retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault();
            }

            #region Images
            if (dbCategory.Images != null)
            {
                retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
            }
            #endregion

            return(retVal);
        }
Esempio n. 18
0
        public coreModel.Category Create(coreModel.Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            var pkMap      = new PrimaryKeyResolvingMap();
            var dbCategory = category.ToDataModel(pkMap);

            using (var repository = _catalogRepositoryFactory())
            {
                repository.Add(dbCategory);
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
            //Need add seo separately
            _commerceService.UpsertSeoForObjects(new[] { category });
            return(GetById(dbCategory.Id, Domain.Catalog.Model.CategoryResponseGroup.Info));
        }
Esempio n. 19
0
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this coreModel.Category source, dataModel.Category target, PrimaryKeyResolvingMap pkMap)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            //TODO: temporary solution because partial update replaced not nullable properties in db entity
            if (source.IsActive != null)
            {
                target.IsActive = source.IsActive.Value;
            }

            var dbSource = source.ToDataModel(pkMap) as dataModel.Category;
            var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
                dbTarget.CatalogId        = string.IsNullOrEmpty(dbSource.CatalogId) ? null : dbSource.CatalogId;
                dbTarget.ParentCategoryId = string.IsNullOrEmpty(dbSource.ParentCategoryId) ? null : dbSource.ParentCategoryId;
                dbTarget.Code             = dbSource.Code;
                dbTarget.Name             = dbSource.Name;
                dbTarget.TaxType          = dbSource.TaxType;

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

                if (!dbSource.OutgoingLinks.IsNullCollection())
                {
                    dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
                }

                if (!dbSource.Images.IsNullCollection())
                {
                    dbSource.Images.Patch(dbTarget.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
                }
            }
        }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategory">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.Category dbCategory, coreModel.Catalog catalog,
                                                    coreModel.Property[] properties = null,  dataModel.Category[] allParents = null)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			var retVal = new coreModel.Category();
			retVal.InjectFrom(dbCategory);
			retVal.CatalogId = catalog.Id;
			retVal.Catalog = catalog;
			retVal.ParentId = dbCategory.ParentCategoryId;
			retVal.IsActive = dbCategory.IsActive;


			retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
			retVal.Virtual = catalog.Virtual;
			retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();


            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

			//Try to inherit taxType from parent category
			if(retVal.TaxType == null && retVal.Parents != null)
			{
				retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault();
			}

			#region Images
			if (dbCategory.Images != null)
			{
				retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
			}
			#endregion

            return retVal;

        }
Esempio n. 21
0
        public coreModel.Category GetById(string categoryId)
        {
            coreModel.Category retVal = null;
            using (var repository = _catalogRepositoryFactory())
            {
                var dbCategory = repository.GetCategoryById(categoryId);
                if (dbCategory != null)
                {
                    var dbCatalog    = repository.GetCatalogById(dbCategory.CatalogId);
                    var dbProperties = repository.GetAllCategoryProperties(dbCategory);
                    //var dbLinks = repository.GetCategoryLinks(categoryId);

                    var catalog    = dbCatalog.ToCoreModel();
                    var properties = dbProperties.Select(x => x.ToCoreModel(catalog, dbCategory.ToCoreModel(catalog)))
                                     .ToArray();
                    var allParents = repository.GetAllCategoryParents(dbCategory);

                    retVal          = dbCategory.ToCoreModel(catalog, properties, allParents);
                    retVal.SeoInfos = _commerceService.GetObjectsSeo(new string[] { categoryId }).ToList();
                }
            }
            return(retVal);
        }
Esempio n. 22
0
		private string[] GetOutlines(Category category)
		{
			var retVal = new List<string>();
			var stringBuilder = new StringBuilder();
			
			//first direct outline
			var outline = new string[] { category.CatalogId }.Concat(category.Parents.Select(x => x.Id)).Concat(new string[] { category.Id });
			retVal.Add(String.Join("/", outline));
			//Next direct links (need remove directory id from outline for displaying products in mapped virtual category)
			foreach(var link in category.Links)
			{
				outline = new string[] { link.CatalogId };
				if(link.CategoryId != null)
				{
					outline = outline.Concat(link.Category.Parents.Select(x => x.Id)).Concat(new string[] { link.CategoryId });
				}
				retVal.Add(String.Join("/", outline));
			}

			//Parent category links 
			foreach (var parent in category.Parents)
			{
				foreach (var link in parent.Links)
				{
					outline = new string[] { link.CatalogId };
					if (link.CategoryId != null)
					{
						outline = outline.Concat(link.Category.Parents.Select(x => x.Id)).Concat(new string[] { link.CategoryId });
					}
					outline = outline.Concat(new string[] { parent.Id });
					retVal.Add(String.Join("/", outline));
				}
			}

			return retVal.ToArray();

		}
        /// <summary>
        /// Patch changes
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void Patch(this coreModel.Category source, dataModel.Category target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            //TODO: temporary solution because partial update replaced not nullable properties in db entity
            if (source.IsActive != null)
            {
                target.IsActive = source.IsActive.Value;
            }

            var dbSource = source.ToDataModel() as dataModel.Category;
            var dbTarget = target as dataModel.Category;

            if (dbSource != null && dbTarget != null)
            {
                var patchInjectionPolicy = new PatchInjection <dataModel.Category>(x => x.Code, x => x.Name, x => x.TaxType);
                target.InjectFrom(patchInjectionPolicy, source);

                if (!dbSource.CategoryPropertyValues.IsNullCollection())
                {
                    dbSource.CategoryPropertyValues.Patch(dbTarget.CategoryPropertyValues, (sourcePropValue, targetPropValue) => sourcePropValue.Patch(targetPropValue));
                }

                if (!dbSource.OutgoingLinks.IsNullCollection())
                {
                    dbSource.OutgoingLinks.Patch(dbTarget.OutgoingLinks, new LinkedCategoryComparer(), (sourceLink, targetLink) => sourceLink.Patch(targetLink));
                }

                if (!dbSource.Images.IsNullCollection())
                {
                    dbSource.Images.Patch(dbTarget.Images, (sourceImage, targetImage) => sourceImage.Patch(targetImage));
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategoryBase">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.CategoryBase dbCategoryBase, coreModel.Catalog catalog,
                                                    coreModel.Property[] properties = null,  dataModel.Category[] allParents = null)
        {
            if (catalog == null)
                throw new ArgumentNullException("catalog");

			var retVal = new coreModel.Category();
			retVal.InjectFrom(dbCategoryBase);
			retVal.CatalogId = catalog.Id;
			retVal.Catalog = catalog;
			retVal.ParentId = dbCategoryBase.ParentCategoryId;
			retVal.IsActive = dbCategoryBase.IsActive;

            var dbCategory = dbCategoryBase as dataModel.Category;
            if (dbCategory != null)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel(properties)).ToList();
                retVal.Virtual = catalog.Virtual;
				retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();
            }

            if (allParents != null)
            {
                retVal.Parents = allParents.Select(x => x.ToCoreModel(catalog)).ToArray();
            }

			#region Images
			if (dbCategory.Images != null)
			{
				retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
			}
			#endregion

            return retVal;

        }
Esempio n. 25
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategory">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.Category dbCategory, bool convertProps = true)
        {
            var retVal = new coreModel.Category();

            retVal.InjectFrom(dbCategory);
            retVal.CatalogId = dbCategory.CatalogId;
            retVal.Catalog   = dbCategory.Catalog.ToCoreModel();
            retVal.ParentId  = dbCategory.ParentCategoryId;
            retVal.IsActive  = dbCategory.IsActive;

            retVal.Virtual = dbCategory.Catalog.Virtual;
            retVal.Links   = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();


            if (dbCategory.AllParents != null)
            {
                retVal.Parents = dbCategory.AllParents.Select(x => x.ToCoreModel()).ToArray();
                retVal.Level   = retVal.Parents.Count();
            }

            //Try to inherit taxType from parent category
            if (retVal.TaxType == null && retVal.Parents != null)
            {
                retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault();
            }

            if (dbCategory.Images != null)
            {
                retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
            }

            if (convertProps)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel()).ToList();

                var properties = new List <coreModel.Property>();
                //Add inherited from catalog properties
                properties.AddRange(retVal.Catalog.Properties);
                //For parents categories
                if (retVal.Parents != null)
                {
                    properties.AddRange(retVal.Parents.SelectMany(x => x.Properties));
                }
                //Self properties
                properties.AddRange(dbCategory.Properties.Select(x => x.ToCoreModel()));

                //property override - need leave only property has a min distance to target category
                //Algorithm based on index property in resulting list (property with min index will more closed to category)
                var propertyGroups = properties.Select((x, index) => new { PropertyName = x.Name.ToLowerInvariant(), Property = x, Index = index }).GroupBy(x => x.PropertyName);
                retVal.Properties = propertyGroups.Select(x => x.OrderBy(y => y.Index).First().Property).ToList();

                //Next need set Property in PropertyValues objects
                foreach (var propValue in retVal.PropertyValues.ToArray())
                {
                    propValue.Property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    //Because multilingual dictionary values for all languages may not stored in db then need to add it in result manually from property dictionary values
                    var localizedDictValues = propValue.TryGetAllLocalizedDictValues();
                    foreach (var localizedDictValue in localizedDictValues)
                    {
                        if (!retVal.PropertyValues.Any(x => x.ValueId == localizedDictValue.ValueId && x.LanguageCode == localizedDictValue.LanguageCode))
                        {
                            retVal.PropertyValues.Add(localizedDictValue);
                        }
                    }
                }
            }
            return(retVal);
        }
Esempio n. 26
0
 public virtual moduleModel.Category ToModel(moduleModel.Category category)
 {
     return(category);
 }
        public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, bool convertProps = true)
        {
            var retVal = new webModel.Category();

            //Do not use omu.InjectFrom for performance reasons
            retVal.Id           = category.Id;
            retVal.IsActive     = category.IsActive;
            retVal.IsVirtual    = category.IsVirtual;
            retVal.Name         = category.Name;
            retVal.ParentId     = category.ParentId;
            retVal.Path         = category.Path;
            retVal.TaxType      = category.TaxType;
            retVal.CatalogId    = category.CatalogId;
            retVal.Code         = category.Code;
            retVal.CreatedBy    = category.CreatedBy;
            retVal.CreatedDate  = category.CreatedDate;
            retVal.ModifiedBy   = category.ModifiedBy;
            retVal.ModifiedDate = category.ModifiedDate;

            retVal.SeoInfos = category.SeoInfos;
            if (!category.Outlines.IsNullOrEmpty())
            {
                //Minimize outline size
                retVal.Outlines = category.Outlines.Select(x => x.ToWebModel()).ToList();
            }

            //Init outline and path
            var parents = new List <moduleModel.Category>();

            if (category.Parents != null)
            {
                retVal.Outline = string.Join("/", category.Parents.Select(x => x.Id));
                retVal.Path    = string.Join("/", category.Parents.Select(x => x.Name));
            }

            //For virtual category links not needed
            if (!category.IsVirtual && category.Links != null)
            {
                retVal.Links = category.Links.Select(x => x.ToWebModel()).ToList();
            }

            //Need add property for each meta info
            retVal.Properties = new List <webModel.Property>();
            if (convertProps)
            {
                if (!category.Properties.IsNullOrEmpty())
                {
                    foreach (var property in category.Properties)
                    {
                        var webModelProperty = property.ToWebModel();
                        //Reset dict values to decrease response size
                        webModelProperty.DictionaryValues = null;
                        webModelProperty.Values           = new List <webModel.PropertyValue>();
                        webModelProperty.IsManageable     = true;
                        webModelProperty.IsReadOnly       = property.Type != moduleModel.PropertyType.Category;
                        retVal.Properties.Add(webModelProperty);
                    }
                }

                //Populate property values
                if (category.PropertyValues != null)
                {
                    foreach (var propValue in category.PropertyValues.Select(x => x.ToWebModel()))
                    {
                        var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId);
                        if (property == null)
                        {
                            property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName));
                        }
                        if (property == null)
                        {
                            //Need add dummy property for each value without property
                            property = new webModel.Property(propValue, category.CatalogId, moduleModel.PropertyType.Category);
                            retVal.Properties.Add(property);
                        }
                        property.Values.Add(propValue);
                    }
                }
            }

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
            }

            return(retVal);
        }
Esempio n. 28
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="dbCategory">The database category base.</param>
        /// <param name="catalog">The catalog.</param>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">catalog</exception>
        public static coreModel.Category ToCoreModel(this dataModel.Category dbCategory, bool convertProps = true)
        {
 			var retVal = new coreModel.Category();
			retVal.InjectFrom(dbCategory);
			retVal.CatalogId = dbCategory.CatalogId;
			retVal.Catalog = dbCategory.Catalog.ToCoreModel();
			retVal.ParentId = dbCategory.ParentCategoryId;
			retVal.IsActive = dbCategory.IsActive;
		
			retVal.Virtual = dbCategory.Catalog.Virtual;
			retVal.Links = dbCategory.OutgoingLinks.Select(x => x.ToCoreModel(retVal)).ToList();


            if (dbCategory.AllParents != null)
            {
                retVal.Parents = dbCategory.AllParents.Select(x => x.ToCoreModel()).ToArray();
                retVal.Level = retVal.Parents.Count();
            }

			//Try to inherit taxType from parent category
			if(retVal.TaxType == null && retVal.Parents != null)
			{
				retVal.TaxType = retVal.Parents.Select(x => x.TaxType).Where(x => x != null).FirstOrDefault();
			}

			if (dbCategory.Images != null)
			{
				retVal.Images = dbCategory.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
			}

            if (convertProps)
            {
                retVal.PropertyValues = dbCategory.CategoryPropertyValues.Select(x => x.ToCoreModel()).ToList();

                var properties = new List<coreModel.Property>();
                //Add inherited from catalog properties
                properties.AddRange(retVal.Catalog.Properties);
                //For parents categories
                if (retVal.Parents != null)
                {
                    properties.AddRange(retVal.Parents.SelectMany(x => x.Properties));
                }
                //Self properties
                properties.AddRange(dbCategory.Properties.Select(x => x.ToCoreModel()));

                //property override - need leave only property has a min distance to target category 
                //Algorithm based on index property in resulting list (property with min index will more closed to category)
                var propertyGroups = properties.Select((x, index) => new { PropertyName = x.Name.ToLowerInvariant(), Property = x, Index = index }).GroupBy(x => x.PropertyName);
                retVal.Properties = propertyGroups.Select(x => x.OrderBy(y => y.Index).First().Property).ToList();

                //Next need set Property in PropertyValues objects
                foreach (var propValue in retVal.PropertyValues.ToArray())
                {
                    propValue.Property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue));
                    //Because multilingual dictionary values for all languages may not stored in db then need to add it in result manually from property dictionary values
                    var localizedDictValues = propValue.TryGetAllLocalizedDictValues();
                    foreach (var localizedDictValue in localizedDictValues)
                    {
                        if (!retVal.PropertyValues.Any(x => x.ValueId == localizedDictValue.ValueId && x.LanguageCode == localizedDictValue.LanguageCode))
                        {
                            retVal.PropertyValues.Add(localizedDictValue);
                        }
                    }
                }
            }
            return retVal;
        }
Esempio n. 29
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.CategoryRelation ToDataModel(this coreModel.CategoryLink categoryLink, coreModel.Category category)
        {
            var retVal = new dataModel.CategoryRelation
            {
                SourceCategoryId = category.Id,
                TargetCategoryId = categoryLink.CategoryId,
                TargetCatalogId  = categoryLink.CatalogId
            };

            return(retVal);
        }
Esempio n. 30
0
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static coreModel.CategoryLink ToCoreModel(this dataModel.CategoryRelation linkedCategory, coreModel.Category category)
        {
            if (linkedCategory == null)
            {
                throw new ArgumentNullException("linkedCategory");
            }

            var retVal = new coreModel.CategoryLink();

            retVal.CategoryId = linkedCategory.TargetCategoryId;
            retVal.CatalogId  = linkedCategory.TargetCatalogId;

            return(retVal);
        }
Esempio n. 31
0
 public virtual Category FromModel(moduleModel.Category category)
 {
     return(this);
 }
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <returns></returns>
        public static coreModel.CatalogProduct ToCoreModel(this dataModel.Item dbItem, coreModel.Catalog catalog,
                                                           coreModel.Category category, coreModel.CatalogProduct[] associatedProducts)
        {
            var retVal = new coreModel.CatalogProduct();

            retVal.InjectFrom(dbItem);
            retVal.Catalog   = catalog;
            retVal.CatalogId = catalog.Id;

            if (category != null)
            {
                retVal.Category   = category;
                retVal.CategoryId = category.Id;
            }

            retVal.MainProductId = dbItem.ParentId;

            retVal.IsActive       = dbItem.IsActive;
            retVal.IsBuyable      = dbItem.IsBuyable;
            retVal.TrackInventory = dbItem.TrackInventory;

            retVal.MaxQuantity = (int)dbItem.MaxQuantity;
            retVal.MinQuantity = (int)dbItem.MinQuantity;


            #region Links
            retVal.Links = dbItem.CategoryLinks.Select(x => x.ToCoreModel()).ToList();
            #endregion

            #region Images
            if (dbItem.Images != null)
            {
                retVal.Images = dbItem.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
            }
            #endregion
            #region Assets
            if (dbItem.Assets != null)
            {
                retVal.Assets = dbItem.Assets.OrderBy(x => x.CreatedDate).Select(x => x.ToCoreModel()).ToList();
            }
            #endregion
            #region Property values
            if (dbItem.ItemPropertyValues != null)
            {
                retVal.PropertyValues = dbItem.ItemPropertyValues.OrderBy(x => x.Name).Select(x => x.ToCoreModel(null)).ToList();
            }
            #endregion


            #region Variations
            retVal.Variations = new List <coreModel.CatalogProduct>();
            foreach (var variation in dbItem.Childrens)
            {
                var productVaraition = variation.ToCoreModel(catalog, category, associatedProducts: null);
                productVaraition.MainProduct   = retVal;
                productVaraition.MainProductId = retVal.Id;

                retVal.Variations.Add(productVaraition);
            }
            #endregion

            #region EditorialReviews
            if (dbItem.EditorialReviews != null)
            {
                retVal.Reviews = dbItem.EditorialReviews.Select(x => x.ToCoreModel()).ToList();
            }
            #endregion

            #region Associations
            if (dbItem.AssociationGroups != null && associatedProducts != null)
            {
                retVal.Associations = new List <coreModel.ProductAssociation>();
                foreach (var association in dbItem.AssociationGroups.SelectMany(x => x.Associations))
                {
                    var associatedProduct = associatedProducts.FirstOrDefault(x => x.Id == association.ItemId);
                    if (associatedProduct != null)
                    {
                        var productAssociation = association.ToCoreModel(associatedProduct);
                        retVal.Associations.Add(productAssociation);
                    }
                }
            }
            #endregion

            //TaxType category inheritance
            if (retVal.TaxType == null && category != null)
            {
                retVal.TaxType = category.TaxType;
            }
            #region Variation property, assets, review inheritance
            if (dbItem.Parent != null)
            {
                //TaxType from main product inheritance
                if (dbItem.TaxType == null && dbItem.Parent.TaxType != null)
                {
                    retVal.TaxType = dbItem.Parent.TaxType;
                }
                var allProductPropertyNames = dbItem.Parent.ItemPropertyValues.Select(x => x.Name).Distinct().ToArray();
                //Property inheritance
                if (allProductPropertyNames != null)
                {
                    //Need copy not overridden property values from main product to variation
                    var overriddenPropertyNames   = retVal.PropertyValues.Select(x => x.PropertyName).ToArray();
                    var inheritedPropertyNames    = allProductPropertyNames.Except(overriddenPropertyNames);
                    var dbInheritedPropertyValues = dbItem.Parent.ItemPropertyValues.Where(x => inheritedPropertyNames.Contains(x.Name));
                    foreach (var dbInheritedPropertyValue in dbInheritedPropertyValues)
                    {
                        //Reset id for correct value override
                        var propertyValue = dbInheritedPropertyValue.ToCoreModel(null);
                        propertyValue.Id = null;
                        retVal.PropertyValues.Add(propertyValue);
                    }
                }
                //Image inheritance
                if (!retVal.Images.Any() && dbItem.Parent.Images != null)
                {
                    retVal.Images = dbItem.Parent.Images.OrderBy(x => x.SortOrder).Select(x => x.ToCoreModel()).ToList();
                    foreach (var image in retVal.Images)
                    {
                        //Reset id for correct override
                        image.Id = null;
                    }
                }
                //Review inheritance
                if ((retVal.Reviews == null || !retVal.Reviews.Any()) && dbItem.Parent.EditorialReviews != null)
                {
                    retVal.Reviews = dbItem.Parent.EditorialReviews.Select(x => x.ToCoreModel()).ToList();
                    foreach (var review in retVal.Reviews)
                    {
                        //Reset id for correct override
                        review.Id = null;
                    }
                }
            }
            #endregion

            return(retVal);
        }
Esempio n. 33
0
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.Property ToCoreModel(this dataModel.Property dbProperty, coreModel.Catalog catalog, coreModel.Category category)
        {
            if (dbProperty == null)
            {
                throw new ArgumentNullException("dbProperty");
            }

            var retVal = new coreModel.Property();

            retVal.InjectFrom(dbProperty);
            retVal.Required      = dbProperty.IsRequired;
            retVal.Multivalue    = dbProperty.IsMultiValue;
            retVal.Multilanguage = dbProperty.IsLocaleDependant;
            retVal.Dictionary    = dbProperty.IsEnum;
            retVal.ValueType     = (coreModel.PropertyValueType)dbProperty.PropertyValueType;
            retVal.CatalogId     = catalog.Id;
            retVal.Catalog       = catalog;
            retVal.CategoryId    = category == null ? null : category.Id;
            retVal.Category      = category;

            coreModel.PropertyType propertyType;
            if (!string.IsNullOrEmpty(dbProperty.TargetType) && Enum.TryParse(dbProperty.TargetType, out propertyType))
            {
                retVal.Type = propertyType;
            }

            retVal.DisplayNames = catalog.Languages.Select(x => new PropertyDisplayName {
                LanguageCode = x.LanguageCode
            }).ToList();
            if (dbProperty.PropertyAttributes != null)
            {
                retVal.Attributes = new List <coreModel.PropertyAttribute>();
                retVal.Attributes.AddRange(dbProperty.PropertyAttributes.Select(x => x.ToCoreModel(retVal)));

                //Load display names from attributes
                foreach (var displayNameAttribute in retVal.Attributes.Where(x => x.Name.StartsWith("DisplayName")))
                {
                    var languageCode = displayNameAttribute.Name.Substring("DisplayName".Length);
                    var displayName  = retVal.DisplayNames.FirstOrDefault(x => String.Equals(x.LanguageCode, languageCode, StringComparison.InvariantCultureIgnoreCase));
                    if (displayName != null)
                    {
                        displayName.Name = displayNameAttribute.Value;
                    }
                }
            }

            if (dbProperty.PropertyValues != null)
            {
                retVal.DictionaryValues = new List <coreModel.PropertyDictionaryValue>();
                retVal.DictionaryValues.AddRange(dbProperty.PropertyValues.Select(x => x.ToCoreModel(retVal)));
            }

            return(retVal);
        }
Esempio n. 34
0
        public void ImportProductsTest()
        {
            var catalogId = "57b2ed0c42a94eb88f1c7b97afaf183d";

            var product = new coreModel.CatalogProduct();
            //Auto detect mapping configuration
            var mappingConfiguration = new string[] { "Name", "Code", "Category", "Reviews" }.Select(x => new webModel.CsvImportMappingItem {
                EntityColumnName = x
            }).ToArray();

            DoAutoMapping(mappingConfiguration);
            //Edit mapping configuration in UI

            var reviewMappingItem = mappingConfiguration.First(x => x.EntityColumnName == "Reviews");

            reviewMappingItem.CsvColumnName = "Reviews";
            //Start import
            //read objects from csv use mapping configuration
            var csvProducts = new List <CatalogProduct>();

            using (var reader = new CsvReader(new StreamReader(@"c:\Projects\VCF\vc-community\PLATFORM\Modules\Catalog\VirtoCommerce.CatalogModule.Test\products.csv")))
            {
                reader.Configuration.Delimiter = ";";
                var initialized = false;
                while (reader.Read())
                {
                    if (!initialized)
                    {
                        var productMap = new ProductMap(reader.FieldHeaders, mappingConfiguration);
                        reader.Configuration.RegisterClassMap(productMap);
                        initialized = true;
                    }

                    var csvProduct = reader.GetRecord <coreModel.CatalogProduct>();
                    csvProducts.Add(csvProduct);
                }
            };

            var categories = new List <coreModel.Category>();

            //project product information to category structure (categories, properties etc)
            foreach (var csvProduct in csvProducts)
            {
                var productCategoryNames = csvProduct.Category.Path.Split('/');
                ICollection <coreModel.Category> levelCategories = categories;
                foreach (var categoryName in productCategoryNames)
                {
                    var category = levelCategories.FirstOrDefault(x => x.Name == categoryName);
                    if (category == null)
                    {
                        category = new coreModel.Category()
                        {
                            Name = categoryName, Code = categoryName.GenerateSlug()
                        };
                        category.CatalogId = catalogId;
                        category.Children  = new List <coreModel.Category>();
                        levelCategories.Add(category);
                    }
                    csvProduct.Category = category;
                    levelCategories     = category.Children;
                }
            }

            var categoryService = GetCategoryService();
            var newCategories   = new List <coreModel.Category>();

            //save to db
            //Categories
            foreach (var category in categories)
            {
                var newCategory = categoryService.Create(category);
                newCategories.Add(newCategory);
                foreach (var childCategory in category.Traverse(x => x.Children))
                {
                    newCategory = categoryService.Create(childCategory);
                    newCategories.Add(newCategory);
                }
            }
            var productService = GetItemService();

            //Products
            foreach (var csvProduct in csvProducts)
            {
                var sameProduct = csvProducts.FirstOrDefault(x => x.Name == csvProduct.Name && !x.IsTransient());
                if (sameProduct != null)
                {
                    //Detect variation
                    csvProduct.MainProductId = sameProduct.Id;
                }
                var category = newCategories.FirstOrDefault(x => x.Code == csvProduct.Category.Code);
                csvProduct.CategoryId = category.Id;
                csvProduct.CatalogId  = catalogId;
                var newProduct = productService.Create(csvProduct);
                csvProduct.Id = newProduct.Id;
            }
        }