Пример #1
0
  public void Create(coreModel.CatalogProduct[] items)
  {
      var pkMap = new PrimaryKeyResolvingMap();
      using (var repository = _catalogRepositoryFactory())
      {
          foreach (var item in items)
          {
              var dbItem = item.ToDataModel(pkMap);
              repository.Add(dbItem);
              if (item.Variations != null)
              {
                  foreach (var variation in item.Variations)
                  {
                      variation.MainProductId = dbItem.Id;
                      variation.CatalogId = dbItem.CatalogId;
                      var dbVariation = variation.ToDataModel(pkMap);
                      repository.Add(dbVariation);
                  }
              }
          }
          CommitChanges(repository);
          pkMap.ResolvePrimaryKeys();
      }
 
      //Update SEO 
      var itemsWithVariations = items.Concat(items.Where(x => x.Variations != null).SelectMany(x => x.Variations)).ToArray();
      _commerceService.UpsertSeoForObjects(itemsWithVariations);
  }
Пример #2
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);
        }
		public coreModel.Property Create(coreModel.Property property)
		{
			if (property.CatalogId == null)
			{
				throw new NullReferenceException("property.CatalogId");
			}
		
			var dbProperty = property.ToDataModel();
			using (var repository = _catalogRepositoryFactory())
			{
				if (property.CategoryId != null)
				{
					var dbCategory = repository.GetCategoryById(property.CategoryId);
					repository.SetCategoryProperty(dbCategory, dbProperty);
				}
				else
				{
					var dbCatalog = repository.GetCatalogById(property.CatalogId) as dataModel.Catalog;
					if(dbCatalog == null)
					{
						throw new OperationCanceledException("Add property only to catalog");
					}
					repository.SetCatalogProperty(dbCatalog, dbProperty);
				}
				repository.Add(dbProperty);
				CommitChanges(repository);
			}
			var retVal = GetById(dbProperty.Id);
			return retVal;
		}
 public static module.CatalogProduct GetByIdsOptimized(
     this IItemService service,
     string[] itemIds,
     module.ItemResponseGroup respGroup)
 {
     return null;
 }
Пример #5
0
		public static webModel.Pricelist ToWebModel(this coreModel.Pricelist priceList, coreCatalogModel.CatalogProduct[] products = null, coreCatalogModel.Catalog[] catalogs = null, ConditionExpressionTree etalonEpressionTree = null)
		{
			var retVal = new webModel.Pricelist();
			retVal.InjectFrom(priceList);
			retVal.Currency = priceList.Currency;
			if (priceList.Prices != null)
			{
				retVal.ProductPrices = new List<webModel.ProductPrice>();
				foreach(var group in priceList.Prices.GroupBy(x=>x.ProductId))
				{
					var productPrice = new webModel.ProductPrice(group.Key, group.Select(x=> x.ToWebModel()));
					
					retVal.ProductPrices.Add(productPrice);
					if (products != null)
					{
						var product = products.FirstOrDefault(x => x.Id == productPrice.ProductId);
						if(product != null)
						{
							productPrice.ProductName = product.Name;
						}
					}
				}
				
			}
			if(priceList.Assignments != null)
			{
				retVal.Assignments = priceList.Assignments.Select(x => x.ToWebModel(catalogs, etalonEpressionTree)).ToList();
			}
			return retVal;
		}
Пример #6
0
        public static googleModel.Product ToGoogleModel(this moduleModel.CatalogProduct product, IBlobUrlResolver assetUrlResolver, moduleModel.Property[] properties = null)
        {
            var retVal = new googleModel.Product();
            retVal.InjectFrom(product);
            var langCode = product.Catalog.Languages.First().LanguageCode;

            retVal.Link = @"http://virtocommerce-test.azurewebsites.net/";

            retVal.OfferId = product.Id;
            retVal.Title = product.Name;
            retVal.Description = product.Reviews.Any() ? product.Reviews.First(x => x.LanguageCode == langCode).Content : product.Name;
            retVal.Link = @"http://virtocommerce-test.azurewebsites.net/";
            retVal.ImageLink = assetUrlResolver.GetAbsoluteUrl(product.Assets.First().Url).TrimStart('/');
            retVal.ContentLanguage = langCode;
            retVal.TargetCountry = "US";
            retVal.Channel = "online";
            retVal.Availability = "in stock";
            retVal.Condition = "new";
            retVal.GoogleProductCategory = "Media > Books";
            retVal.Gtin = "9780007350896";
            retVal.Taxes = new[] { new googleModel.ProductTax { Country = "US", Rate = 10, Region = "CA" } };
            retVal.Shipping = new[]
            {
                new googleModel.ProductShipping
                {
                    Country = "US",
                    Price = new googleModel.Price { Currency = "USD", Value = "5"}
                }
            };

            return retVal;
        }
        public coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup, string catalogId = null)
        {
            coreModel.Category[] result;

            using (var repository = _catalogRepositoryFactory())
            {
                result = repository.GetCategoriesByIds(categoryIds, responseGroup)
                    .Select(c => c.ToCoreModel())
                    .ToArray();
            }

            // Fill outlines for products
            if (responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines))
            {
                _outlineService.FillOutlinesForObjects(result, catalogId);
            }

            // Fill SEO info
            if ((responseGroup & coreModel.CategoryResponseGroup.WithSeo) == coreModel.CategoryResponseGroup.WithSeo)
            {
                var objectsWithSeo = new List<ISeoSupport>(result);

                var outlineItems = result
                    .Where(c => c.Outlines != null)
                    .SelectMany(c => c.Outlines.SelectMany(o => o.Items));
                objectsWithSeo.AddRange(outlineItems);

                _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray());
            }

            return result;
        }
Пример #8
0
        //initial version of product converter to amazon product.
        //it should be adopted to the particular customer needs as many Amazon properties (like category) are unique and can't be mapped automatically.
        public static Product ToAmazonModel(this moduleModel.CatalogProduct product, IBlobUrlResolver assetUrlResolver, moduleModel.Property[] properties = null)
        {
            var amazonProduct = new Product();
            amazonProduct.InjectFrom(product);

            amazonProduct.DescriptionData = new ProductDescriptionData
            {
                Brand = "Brand",
                Description = "Product description",

            };

            amazonProduct.Condition = new ConditionInfo { ConditionType = ConditionType.New };
            if (product.Images != null && product.Images.Any())
                amazonProduct.ExternalProductUrl = assetUrlResolver.GetAbsoluteUrl(product.Images.First().Url.TrimStart('/'));
            amazonProduct.SKU = product.Code;
            amazonProduct.StandardProductID = new StandardProductID { Value = amazonProduct.SKU, Type = StandardProductIDType.ASIN };

            //var mainCat = new Home();
            //var subCat = new Kitchen();
            //mainCat.ProductType = new HomeProductType { Item = subCat };

            //amazonProduct.ProductData = new ProductProductData { Item = mainCat };

            return amazonProduct;
        }        
Пример #9
0
        public coreModel.Property Create(coreModel.Property property)
        {
            if (property.CatalogId == null)
            {
                throw new NullReferenceException("property.CatalogId");
            }

            var dbProperty = property.ToDataModel();
            using (var repository = _catalogRepositoryFactory())
            {
                if (property.CategoryId != null)
                {
                    var dbCategory = repository.GetCategoriesByIds(new[] { property.CategoryId }, coreModel.CategoryResponseGroup.Info).FirstOrDefault();
                    if (dbCategory == null)
                    {
                        throw new NullReferenceException("dbCategory");
                    }
                    dbCategory.Properties.Add(dbProperty);
                }
                else
                {
                    var dbCatalog = repository.GetCatalogById(property.CatalogId);
                    if (dbCatalog == null)
                    {
                        throw new NullReferenceException("dbCatalog");
                    }
                    dbCatalog.Properties.Add(dbProperty);
                }
                repository.Add(dbProperty);
                CommitChanges(repository);
            }
            var retVal = GetById(dbProperty.Id);
            return retVal;
        }
Пример #10
0
        private IEnumerable<moduleModel.CatalogProduct> Search(CatalogIndexedSearchCriteria criteria, out CatalogItemSearchResults results, moduleModel.ItemResponseGroup responseGroup)
        {
            var items = new List<moduleModel.CatalogProduct>();
            var itemsOrderedList = new List<string>();

            var foundItemCount = 0;
            var dbItemCount = 0;
            var searchRetry = 0;

            //var myCriteria = criteria.Clone();
            var myCriteria = criteria;

            do
            {
                // Search using criteria, it will only return IDs of the items
                var scope = _searchConnection.Scope;
                var searchResults = _searchProvider.Search(scope, criteria) as SearchResults;
                var itemKeyValues = searchResults.GetKeyAndOutlineFieldValueMap<string>();
                results = new CatalogItemSearchResults(myCriteria, itemKeyValues, searchResults);

                searchRetry++;

                if (results.Items == null)
                {
                    continue;
                }

                //Get only new found itemIds
                var uniqueKeys = results.Items.Keys.Except(itemsOrderedList).ToArray();
                foundItemCount = uniqueKeys.Length;

                if (!results.Items.Any())
                {
                    continue;
                }

                itemsOrderedList.AddRange(uniqueKeys);

                // Now load items from repository
                var currentItems = _itemService.GetByIds(uniqueKeys.ToArray(), responseGroup);

                var orderedList = currentItems.OrderBy(i => itemsOrderedList.IndexOf(i.Id));
                items.AddRange(orderedList);
                dbItemCount = currentItems.Length;

                //If some items where removed and search is out of sync try getting extra items
                if (foundItemCount > dbItemCount)
                {
                    //Retrieve more items to fill missing gap
                    myCriteria.RecordsToRetrieve += (foundItemCount - dbItemCount);
                }
            }
            while (foundItemCount > dbItemCount && results.Items.Any() && searchRetry <= 3 &&
                (myCriteria.RecordsToRetrieve + myCriteria.StartingRecord) < results.TotalCount);

            return items;
        }
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.CatalogLanguage ToCoreModel(this dataModel.CatalogLanguage dbLanguage, coreModel.Catalog catalog)
		{
			var retVal = new coreModel.CatalogLanguage();
			retVal.InjectFrom(dbLanguage);

			retVal.CatalogId = catalog.Id;
			retVal.LanguageCode = dbLanguage.Language;

			return retVal;
		}
Пример #12
0
		/// <summary>
		/// Create property meta information from property value
		/// </summary>
		/// <param name="propValue"></param>
		/// <param name="catalogId"></param>
		/// <param name="categoryId"></param>
		/// <param name="propertyType"></param>
		public Property(PropertyValue propValue, string catalogId, string categoryId, coreModel.PropertyType propertyType)
		{
			Id = propValue.Id;
			CatalogId = catalogId;
			IsManageable = false;
			Name = propValue.PropertyName;
			Type = propertyType;
			ValueType = propValue.ValueType;
			Values = new List<PropertyValue>();
		}
		public static webModel.Category ToWebModel(this moduleModel.Category category, IBlobUrlResolver blobUrlResolver = null, 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);
				}
			}

			if (category.Images != null)
			{
				retVal.Images = category.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList();
			}
			return retVal;
		}
Пример #14
0
		public coreModel.Catalog Create(coreModel.Catalog catalog)
		{
			var dbCatalog = catalog.ToDataModel();
			coreModel.Catalog retVal = null;
			using (var repository = _catalogRepositoryFactory())
			{
				repository.Add(dbCatalog);
				CommitChanges(repository);
			}
			retVal = GetById(dbCatalog.Id);
			return retVal;
		}
        public IHttpActionResult ListItemsSearch(coreModel.SearchCriteria searchCriteria)
        {
            ApplyRestrictionsForCurrentUser(searchCriteria);

            searchCriteria.WithHidden = true;
            //Need search in children categories if user specify keyword
            if (!string.IsNullOrEmpty(searchCriteria.Keyword))
            {
                searchCriteria.SearchInChildren = true;
                searchCriteria.SearchInVariations = true;
            }

            var retVal = new webModel.ListEntrySearchResult();

            int categorySkip = 0;
            int categoryTake = 0;
            //Because products and categories represent in search result as two separated collections for handle paging request 
            //we should join two resulting collection artificially
            //search categories
            if ((searchCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithCategories) == coreModel.SearchResponseGroup.WithCategories)
            {
                searchCriteria.ResponseGroup = searchCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithProducts;
                var categoriesSearchResult = _searchService.Search(searchCriteria);
                var categoriesTotalCount = categoriesSearchResult.Categories.Count();

                categorySkip = Math.Min(categoriesTotalCount, searchCriteria.Skip);
                categoryTake = Math.Min(searchCriteria.Take, Math.Max(0, categoriesTotalCount - searchCriteria.Skip));
                var categories = categoriesSearchResult.Categories.Skip(categorySkip).Take(categoryTake).Select(x => new webModel.ListEntryCategory(x.ToWebModel(_blobUrlResolver))).ToList();

                retVal.TotalCount = categoriesTotalCount;
                retVal.ListEntries.AddRange(categories);

                searchCriteria.ResponseGroup = searchCriteria.ResponseGroup | coreModel.SearchResponseGroup.WithProducts;
            }

            //search products
            if ((searchCriteria.ResponseGroup & coreModel.SearchResponseGroup.WithProducts) == coreModel.SearchResponseGroup.WithProducts)
            {
                searchCriteria.ResponseGroup = searchCriteria.ResponseGroup & ~coreModel.SearchResponseGroup.WithCategories;
                searchCriteria.Skip = searchCriteria.Skip - categorySkip;
                searchCriteria.Take = searchCriteria.Take - categoryTake;
                var productsSearchResult = _searchService.Search(searchCriteria);

                var products = productsSearchResult.Products.Select(x => new webModel.ListEntryProduct(x.ToWebModel(_blobUrlResolver)));

                retVal.TotalCount += productsSearchResult.ProductsTotalCount;
                retVal.ListEntries.AddRange(products);
            }


            return Ok(retVal);
        }
Пример #16
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();
		}
Пример #17
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();
		}
		/// <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;
		}
Пример #19
0
		public coreModel.Catalog Create(coreModel.Catalog catalog)
        {
            var pkMap = new PrimaryKeyResolvingMap();
            var dbCatalog = catalog.ToDataModel(pkMap);
			coreModel.Catalog retVal = null;
			using (var repository = _catalogRepositoryFactory())
			{
				repository.Add(dbCatalog);
				CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
			retVal = GetById(dbCatalog.Id);
			return retVal;
		}
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.PropertyAttribute ToCoreModel(this dataModel.PropertyAttribute dbAttribute, coreModel.Property property)
		{
			if (property == null)
				throw new ArgumentNullException("dbProperty");

			var retVal = new coreModel.PropertyAttribute();
			retVal.InjectFrom(dbAttribute);

			retVal.Name = dbAttribute.PropertyAttributeName;
			retVal.Value = dbAttribute.PropertyAttributeValue;
			retVal.PropertyId = property.Id;
			retVal.Property = property;
			
			return retVal;
		}
        /// <summary>
        /// Converting to model type
        /// </summary>
        /// <param name="catalogBase"></param>
        /// <returns></returns>
        public static coreModel.PropertyDictionaryValue ToCoreModel(this dataModel.PropertyValue dbPropValue, coreModel.Property property)
        {
            if (property == null)
                throw new ArgumentNullException("property");

			var retVal = new coreModel.PropertyDictionaryValue();
			retVal.InjectFrom(dbPropValue);

			retVal.LanguageCode = dbPropValue.Locale;
			retVal.Value = dbPropValue.ToString();
			retVal.PropertyId = property.Id;
			retVal.Property = property;
          
            return retVal;
        }
		/// <summary>
		/// Converting to model type
		/// </summary>
		/// <param name="catalogBase"></param>
		/// <returns></returns>
		public static coreModel.ProductAssociation ToCoreModel(this dataModel.Association dbAssociation, coreModel.CatalogProduct associatedProduct)
		{
			if (dbAssociation == null)
				throw new ArgumentNullException("dbAssociation");

			var retVal = new coreModel.ProductAssociation
			{
				Name = dbAssociation.AssociationGroup.Name,
				Description = dbAssociation.AssociationGroup.Description,
				Priority = dbAssociation.Priority,
				AssociatedProductId = associatedProduct.Id,
                Type = dbAssociation.AssociationType,
				AssociatedProduct = associatedProduct
			};
			return retVal;
		}
Пример #23
0
 public coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup)
 {
     var retVal = new List<coreModel.Category>();
     using (var repository = _catalogRepositoryFactory())
     {
         var categories = repository.GetCategoriesByIds(categoryIds, responseGroup).Select(x => x.ToCoreModel()).ToArray();
         retVal.AddRange(categories);
         if ((responseGroup & coreModel.CategoryResponseGroup.WithSeo) == coreModel.CategoryResponseGroup.WithSeo)
         {
             _commerceService.LoadSeoForObjects(categories);
         }
     
     }
    
     return retVal.ToArray();
 }
        /// <summary>
        /// Converting to foundation type
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public static dataModel.PropertyValue ToDataModel(this coreModel.PropertyDictionaryValue propDictValue, coreModel.Property property)
        {
            var retVal = new dataModel.PropertyValue
            {
	            Locale = propDictValue.LanguageCode,
                PropertyId = property.Id
            };
			retVal.InjectFrom(propDictValue);

			if(propDictValue.Id != null)
			{
				retVal.Id = propDictValue.Id;
			}
            SetPropertyValue(retVal, property.ValueType, propDictValue.Value);

            return retVal;
        }
		private static void SetPropertyValue(dataModel.PropertyValueBase retVal, coreModel.PropertyValueType type, string value)
        {
            switch (type)
            {
				case coreModel.PropertyValueType.LongText:
                    retVal.LongTextValue = value;
                    break;
				case coreModel.PropertyValueType.ShortText:
                    retVal.ShortTextValue = value;
                    break;
				case coreModel.PropertyValueType.Number:
                    decimal parsedDecimal;
                    Decimal.TryParse(value, out parsedDecimal);
                    retVal.DecimalValue = parsedDecimal;
                    break;
            }
        }
Пример #26
0
        public moduleModel.SearchResult SearchItems(CatalogIndexedSearchCriteria criteria, moduleModel.ItemResponseGroup responseGroup)
        {
            CatalogItemSearchResults results;
            var items = Search(criteria, out results, responseGroup);

            var response = new moduleModel.SearchResult();

            response.Products.AddRange(items);
            response.ProductsTotalCount = results.TotalCount;

            // TODO need better way to find applied filter values
            var appliedFilters = criteria.CurrentFilters.SelectMany(x => x.GetValues()).Select(x => x.Id).ToArray();
            if (results.FacetGroups != null)
            {
                response.Aggregations = results.FacetGroups.Select(g => g.ToModuleModel(appliedFilters)).ToArray();
            }
            return response;
        }
Пример #27
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);
        }
Пример #28
0
        public ProductSearchResult SearchItems(CatalogIndexedSearchCriteria criteria, moduleModel.ItemResponseGroup responseGroup = moduleModel.ItemResponseGroup.ItemSmall)
        {
            CatalogItemSearchResults results;
            var items = Search(criteria, out results, responseGroup);
            var catalogItems = new List<Product>();

            // go through items
            foreach (var item in items)
            {
                var searchTags = results.Items[item.Id.ToLower()];

                var currentOutline = this.GetItemOutlineUsingContext(
                    searchTags[criteria.OutlineField].ToString(),
                    criteria.Catalog);
                var catalogItem = item.ToWebModel(_blobUrlResolver) as Product;
                catalogItem.Outline = this.StripCatalogFromOutline(currentOutline, criteria.Catalog);

                int reviewTotal;
                if (searchTags.ContainsKey(criteria.ReviewsTotalField)
                    && int.TryParse(searchTags[criteria.ReviewsTotalField].ToString(), out reviewTotal))
                {
                    catalogItem.ReviewsTotal = reviewTotal;
                }
                double reviewAvg;
                if (searchTags.ContainsKey(criteria.ReviewsAverageField)
                    && double.TryParse(searchTags[criteria.ReviewsAverageField].ToString(), out reviewAvg))
                {
                    catalogItem.Rating = reviewAvg;
                }

                catalogItems.Add(catalogItem);
            }

            var response = new ProductSearchResult();

            response.Items.AddRange(catalogItems);
            response.TotalCount = results.TotalCount;

            //TODO need better way to find applied filter values
            var appliedFilters = criteria.CurrentFilters.SelectMany(x => x.GetValues()).Select(x => x.Id).ToArray();
            response.Facets = results.FacetGroups == null ? null : results.FacetGroups.Select(g => g.ToWebModel(appliedFilters)).ToArray();
            return response;
        }
Пример #29
0
        public coreModel.CatalogProduct[] GetByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup)
        {
            var retVal = new List<coreModel.CatalogProduct>();
            using (var repository = _catalogRepositoryFactory())
            {
                var dbItems = repository.GetItemByIds(itemIds, respGroup);

                retVal.AddRange(dbItems.Select(x => x.ToCoreModel()));
                //Populate product seo
                if ((respGroup & coreModel.ItemResponseGroup.Seo) == coreModel.ItemResponseGroup.Seo)
                {
                    var expandedProducts = retVal.Concat(retVal.Where(x => x.Variations != null).SelectMany(x => x.Variations)).ToArray();
                    var allCategories = expandedProducts.Select(x => x.Category).ToArray();
                    var allSeoObjects = expandedProducts.OfType<ISeoSupport>().Concat(allCategories.OfType<ISeoSupport>()).ToArray();
                    _commerceService.LoadSeoForObjects(allSeoObjects);

                }
            }
            return retVal.ToArray();
        }
        public void Create(coreModel.Category[] categories)
        {
            if (categories == null)
                throw new ArgumentNullException("categories");

            var pkMap = new PrimaryKeyResolvingMap();
            var dbCategories = categories.Select(x => x.ToDataModel(pkMap));

            using (var repository = _catalogRepositoryFactory())
            {
                foreach (var dbCategory in dbCategories)
                {
                    repository.Add(dbCategory);
                }
                CommitChanges(repository);
                pkMap.ResolvePrimaryKeys();
            }
            //Need add seo separately
            _commerceService.UpsertSeoForObjects(categories);         
        }