public coreModel.CatalogProduct[] GetByIds(string[] itemIds, coreModel.ItemResponseGroup respGroup, string catalogId = null) { coreModel.CatalogProduct[] result; using (var repository = _catalogRepositoryFactory()) { result = repository.GetItemByIds(itemIds, respGroup) .Select(x => x.ToCoreModel()) .ToArray(); } // Fill outlines for products if (respGroup.HasFlag(coreModel.ItemResponseGroup.Outlines)) { _outlineService.FillOutlinesForObjects(result, catalogId); } // Fill SEO info for products, variations and outline items if ((respGroup & coreModel.ItemResponseGroup.Seo) == coreModel.ItemResponseGroup.Seo) { var objectsWithSeo = new List <ISeoSupport>(result); var variations = result.Where(p => p.Variations != null) .SelectMany(p => p.Variations); objectsWithSeo.AddRange(variations); var outlineItems = result.Where(p => p.Outlines != null) .SelectMany(p => p.Outlines.SelectMany(o => o.Items)); objectsWithSeo.AddRange(outlineItems); _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray()); } return(result); }
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); }
protected virtual Dictionary <string, Category> PreloadCategories(string catalogId) { return(_cacheManager.Get($"AllCategories-{catalogId}", CatalogConstants.CacheRegion, () => { CategoryEntity[] entities; using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); entities = repository.GetCategoriesByIds(repository.Categories.Select(x => x.Id).ToArray(), CategoryResponseGroup.Full); } var result = entities.Select(x => x.ToModel(AbstractTypeFactory <Category> .TryCreateInstance())).ToDictionary(x => x.Id, StringComparer.OrdinalIgnoreCase); LoadDependencies(result.Values, result); ApplyInheritanceRules(result.Values); // Fill outlines for categories _outlineService.FillOutlinesForObjects(result.Values, catalogId); var objectsWithSeo = new List <ISeoSupport>(result.Values); var outlineItems = result.Values.Where(c => c.Outlines != null).SelectMany(c => c.Outlines.SelectMany(o => o.Items)); objectsWithSeo.AddRange(outlineItems); _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray()); return result; })); }
public coreModel.Store[] GetByIds(string[] ids) { var retVal = new List <coreModel.Store>(); using (var repository = _repositoryFactory()) { var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); var dbStores = repository.GetStoresByIds(ids); foreach (var dbStore in dbStores) { //Load original typed shipping method and populate it personalized information from db var store = dbStore.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders()); store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId); store.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId); //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store"); _settingManager.LoadEntitySettingsValues(store); _dynamicPropertyService.LoadDynamicPropertyValues(store); retVal.Add(store); } } _commerceService.LoadSeoForObjects(retVal.ToArray()); return(retVal.ToArray()); }
protected virtual Dictionary <string, Category> PreloadCategories(string catalogId) { var cacheKey = CacheKey.With(GetType(), "PreloadCategories", catalogId); return(_memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) => { cacheEntry.AddExpirationToken(CatalogCacheRegion.CreateChangeToken()); CategoryEntity[] entities; using (var repository = _repositoryFactory()) { repository.DisableChangesTracking(); entities = repository.GetCategoriesByIds(repository.Categories.Select(x => x.Id).ToArray()); } var result = entities.Select(x => x.ToModel(AbstractTypeFactory <Category> .TryCreateInstance())).ToDictionary(x => x.Id, StringComparer.OrdinalIgnoreCase); LoadDependencies(result.Values, result); ApplyInheritanceRules(result.Values.OrderBy(x => x.Level)); // Fill outlines for categories _outlineService.FillOutlinesForObjects(result.Values, catalogId); var objectsWithSeo = new List <ISeoSupport>(result.Values); var outlineItems = result.Values.Where(c => c.Outlines != null).SelectMany(c => c.Outlines.SelectMany(o => o.Items)); objectsWithSeo.AddRange(outlineItems); _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray()); return result; })); }
public Store[] GetByIds(string[] ids) { var stores = new List <Store>(); using (var repository = _repositoryFactory()) { var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); var dbStores = repository.GetStoresByIds(ids); foreach (var dbStore in dbStores) { var store = AbstractTypeFactory <Store> .TryCreateInstance(); dbStore.ToModel(store); //Return all registered methods with store settings store.PaymentMethods = _paymentService.GetAllPaymentMethods(); foreach (var paymentMethod in store.PaymentMethods) { var dbStoredPaymentMethod = dbStore.PaymentMethods.FirstOrDefault(x => x.Code.EqualsInvariant(paymentMethod.Code)); if (dbStoredPaymentMethod != null) { dbStoredPaymentMethod.ToModel(paymentMethod); } } store.ShippingMethods = _shippingService.GetAllShippingMethods(); foreach (var shippingMethod in store.ShippingMethods) { var dbStoredShippingMethod = dbStore.ShippingMethods.FirstOrDefault(x => x.Code.EqualsInvariant(shippingMethod.Code)); if (dbStoredShippingMethod != null) { dbStoredShippingMethod.ToModel(shippingMethod); } } store.TaxProviders = _taxService.GetAllTaxProviders(); foreach (var taxProvider in store.TaxProviders) { var dbStoredTaxProvider = dbStore.TaxProviders.FirstOrDefault(x => x.Code.EqualsInvariant(taxProvider.Code)); if (dbStoredTaxProvider != null) { dbStoredTaxProvider.ToModel(taxProvider); } } store.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.ReturnsFulfillmentCenterId); store.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == dbStore.FulfillmentCenterId); //Set default settings for store it can be override by store instance setting in LoadEntitySettingsValues store.Settings = _settingManager.GetModuleSettings("VirtoCommerce.Store"); _settingManager.LoadEntitySettingsValues(store); stores.Add(store); } } var result = stores.ToArray(); _dynamicPropertyService.LoadDynamicPropertyValues(result); _commerceService.LoadSeoForObjects(result); return(result); }
public virtual CatalogProduct[] GetByIds(string[] itemIds, ItemResponseGroup respGroup, string catalogId = null) { var result = Array.Empty <CatalogProduct>(); if (!itemIds.IsNullOrEmpty()) { using (var repository = _repositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); result = repository.GetItemByIds(itemIds, respGroup) .Select(x => x.ToModel(AbstractTypeFactory <CatalogProduct> .TryCreateInstance())) .ToArray(); } if (result.Any()) { LoadDependencies(result); ApplyInheritanceRules(result); var productsWithVariationsList = result.Concat(result.Where(p => p.Variations != null) .SelectMany(p => p.Variations)); // Fill outlines for products and variations if (respGroup.HasFlag(ItemResponseGroup.Outlines)) { _outlineService.FillOutlinesForObjects(productsWithVariationsList, catalogId); } // Fill SEO info for products, variations and outline items if ((respGroup & ItemResponseGroup.Seo) == ItemResponseGroup.Seo) { var objectsWithSeo = productsWithVariationsList.OfType <ISeoSupport>().ToList(); //Load SEO information for all Outline.Items var outlineItems = productsWithVariationsList.Where(p => p.Outlines != null) .SelectMany(p => p.Outlines.SelectMany(o => o.Items)); objectsWithSeo.AddRange(outlineItems); _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray()); } //Reduce details according to response group foreach (var product in productsWithVariationsList) { ReduceDetails(product, respGroup); } } } return(result); }
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()); }
public virtual coreModel.Category[] GetByIds(string[] categoryIds, coreModel.CategoryResponseGroup responseGroup, string catalogId = null) { coreModel.Category[] result; using (var repository = base.CatalogRepositoryFactory()) { result = repository.GetCategoriesByIds(categoryIds, responseGroup) .Select(c => c.ToCoreModel(base.AllCachedCatalogs, base.AllCachedCategories)) .ToArray(); } // Fill outlines for products if (responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithOutlines)) { _outlineService.FillOutlinesForObjects(result, catalogId); } 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()); } //Cleanup result model considered requested response group foreach (var category in result) { if (!responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithParents)) { category.Parents = null; } if (!responseGroup.HasFlag(coreModel.CategoryResponseGroup.WithProperties)) { category.Properties = null; } } return(result); }
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 coreModel.Store GetById(string id) { coreModel.Store retVal = null; using (var repository = _repositoryFactory()) { var entity = repository.GetStoreById(id); if (entity != null) { //Load original typed shipping method and populate it personalized information from db retVal = entity.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods(), _taxService.GetAllTaxProviders()); var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); retVal.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.ReturnsFulfillmentCenterId); retVal.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.FulfillmentCenterId); _commerceService.LoadSeoForObjects(new[] { retVal }); _settingManager.LoadEntitySettingsValues(retVal); _dynamicPropertyService.LoadDynamicPropertyValues(retVal); } } return(retVal); }
public virtual CatalogProduct[] GetByIds(string[] itemIds, ItemResponseGroup respGroup, string catalogId = null) { CatalogProduct[] result; using (var repository = _repositoryFactory()) { //Optimize performance and CPU usage repository.DisableChangesTracking(); result = repository.GetItemByIds(itemIds, respGroup) .Select(x => x.ToModel(AbstractTypeFactory <CatalogProduct> .TryCreateInstance())) .ToArray(); } LoadDependencies(result); ApplyInheritanceRules(result); // Fill outlines for products if (respGroup.HasFlag(ItemResponseGroup.Outlines)) { _outlineService.FillOutlinesForObjects(result, catalogId); } // Fill SEO info for products, variations and outline items if ((respGroup & ItemResponseGroup.Seo) == ItemResponseGroup.Seo) { var objectsWithSeo = new List <ISeoSupport>(result); var variations = result.Where(p => p.Variations != null) .SelectMany(p => p.Variations); objectsWithSeo.AddRange(variations); var outlineItems = result.Where(p => p.Outlines != null) .SelectMany(p => p.Outlines.SelectMany(o => o.Items)); objectsWithSeo.AddRange(outlineItems); _commerceService.LoadSeoForObjects(objectsWithSeo.ToArray()); } //Reduce details according to response group foreach (var product in result) { if (!respGroup.HasFlag(ItemResponseGroup.ItemAssets)) { product.Assets = null; } if (!respGroup.HasFlag(ItemResponseGroup.ItemAssociations)) { product.Associations = null; } if (!respGroup.HasFlag(ItemResponseGroup.ReferencedAssociations)) { product.ReferencedAssociations = null; } if (!respGroup.HasFlag(ItemResponseGroup.ItemEditorialReviews)) { product.Reviews = null; } if (!respGroup.HasFlag(ItemResponseGroup.Inventory)) { product.Inventories = null; } if (!respGroup.HasFlag(ItemResponseGroup.ItemProperties)) { product.Properties = null; } if (!respGroup.HasFlag(ItemResponseGroup.Links)) { product.Links = null; } if (!respGroup.HasFlag(ItemResponseGroup.Outlines)) { product.Outlines = null; } if (!respGroup.HasFlag(ItemResponseGroup.Seo)) { product.SeoInfos = null; } if (!respGroup.HasFlag(ItemResponseGroup.Variations)) { product.Variations = null; } } return(result); }
public void LoadSeoForObjects(ISeoSupport[] seoSupportObjects) { _commerceService.LoadSeoForObjects(seoSupportObjects); }