Пример #1
0
        public coreModel.Store GetById(string id)
        {
            var cacheKey = CacheKey.Create("StoreModule", "GetById", id);

            return(_cacheManager.Get(cacheKey, () =>
            {
                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());

                        var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList();
                        retVal.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.ReturnsFulfillmentCenterId);
                        retVal.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.FulfillmentCenterId);
                        retVal.SeoInfos = _commerceService.GetObjectsSeo(new[] { id }).ToList();

                        LoadObjectSettings(_settingManager, retVal);
                    }
                }
                return retVal;
            }));
        }
Пример #2
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());
        }
Пример #3
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());
        }
Пример #4
0
 public void Delete(string[] catalogIds)
 {
     using (var repository = _catalogRepositoryFactory())
     {
         var seoInfos = _commerceService.GetObjectsSeo(catalogIds);
         _commerceService.DeleteSeo(seoInfos.Select(x => x.Id).ToArray());
         repository.RemoveCatalogs(catalogIds);
         CommitChanges(repository);
     }
 }
Пример #5
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);
        }