public ActionResult ProductAddPopup(int manufacturerId) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var ctx = new ProductSearchContext(); ctx.LanguageId = _workContext.WorkingLanguage.Id; ctx.OrderBy = ProductSortingEnum.Position; ctx.PageSize = _adminAreaSettings.GridPageSize; ctx.ShowHidden = true; var products = _productService.SearchProducts(ctx); var model = new ManufacturerModel.AddManufacturerProductModel(); model.Products = new GridModel <ProductModel> { Data = products.Select(x => { var productModel = x.ToModel(); productModel.ProductTypeName = x.GetProductTypeLabel(_localizationService); return(productModel); }), Total = products.TotalCount }; //categories var allCategories = _categoryService.GetAllCategories(showHidden: true); var mappedCategories = allCategories.ToDictionary(x => x.Id); foreach (var c in allCategories) { model.AvailableCategories.Add(new SelectListItem() { Text = c.GetCategoryNameWithPrefix(_categoryService, mappedCategories), Value = c.Id.ToString() }); } //manufacturers foreach (var m in _manufacturerService.GetAllManufacturers(true)) { model.AvailableManufacturers.Add(new SelectListItem() { Text = m.Name, Value = m.Id.ToString() }); } //product types model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList(); model.AvailableProductTypes.Insert(0, new SelectListItem() { Text = _localizationService.GetResource("Admin.Common.All"), Value = "0" }); return(View(model)); }
public ActionResult Sitemap() { if (!_commonSettings.SitemapEnabled) { return(RedirectToRoute("HomePage")); } var model = new SitemapModel(); if (_commonSettings.SitemapIncludeCategories) { var categories = _categoryService.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page IList <int> filterableSpecificationAttributeOptionIds = null; var productSearchContext = new ProductSearchContext(); productSearchContext.OrderBy = ProductSortingEnum.Position; productSearchContext.PageSize = 200; productSearchContext.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds; productSearchContext.StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode; productSearchContext.VisibleIndividuallyOnly = true; var products = _productService.SearchProducts(productSearchContext); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name).EmptyNull(), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.SitemapIncludeTopics) { var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(View(model)); }
private void WriteProducts(UrlHelper urlHelper) { var protocol = _securitySettings.ForceSslForAllPages ? "https" : "http"; var ctx = new ProductSearchContext { OrderBy = ProductSortingEnum.CreatedOn, PageSize = 500, StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; for (ctx.PageIndex = 0; ctx.PageIndex < 9999999; ++ctx.PageIndex) { var products = _productService.SearchProducts(ctx); foreach (var product in products) { var url = urlHelper.RouteUrl("Product", new { SeName = product.GetSeName() }, protocol); var updateFrequency = UpdateFrequency.Weekly; var updateTime = product.UpdatedOnUtc; WriteUrlLocation(url, updateFrequency, updateTime); } if (!products.HasNextPage) { break; } } }
public virtual GridModel <GoogleProductModel> GetGridModel(GridCommand command, string searchProductName = null) { var searchContext = new ProductSearchContext() { Keywords = searchProductName, PageIndex = command.Page - 1, PageSize = command.PageSize, ShowHidden = true }; var products = _productService.SearchProducts(searchContext); var data = products.Select(x => { var gModel = new GoogleProductModel() { ProductId = x.Id, ProductName = x.Name }; var googleProduct = GetByProductId(x.Id); if (googleProduct != null) { gModel.GoogleCategory = googleProduct.Taxonomy; gModel.Gender = googleProduct.Gender; gModel.AgeGroup = googleProduct.AgeGroup; gModel.Color = googleProduct.Color; gModel.GoogleSize = googleProduct.Size; if (gModel.Gender.HasValue()) { gModel.GenderLocalize = Helper.Resource("Gender" + CultureInfo.InvariantCulture.TextInfo.ToTitleCase(gModel.Gender)); } if (gModel.AgeGroup.HasValue()) { gModel.AgeGroupLocalize = Helper.Resource("AgeGroup" + CultureInfo.InvariantCulture.TextInfo.ToTitleCase(gModel.AgeGroup)); } } return(gModel); }) .ToList(); var model = new GridModel <GoogleProductModel>() { Data = data, Total = products.TotalCount }; return(model); }
private IQueryable <Product> AllProducts(List <int> categoryIds) { if (_products == null) { var searchContext = new ProductSearchContext() { CategoryIds = categoryIds, FeaturedProducts = IncludeFeatured, StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; _products = _productService.PrepareProductSearchQuery(searchContext); } return(_products); }
private IQueryable <Product> AllProducts(List <int> categoryIds) { if (_products == null) { var searchContext = new ProductSearchContext() { FeaturedProducts = (_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false), StoreId = _commonServices.StoreContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; if (categoryIds != null && categoryIds.Count > 1) { _products = _productService.PrepareProductSearchQuery(searchContext); var distinctIds = ( from p in _productRepository.TableUntracked join pc in _productCategoryRepository.TableUntracked on p.Id equals pc.ProductId where categoryIds.Contains(pc.CategoryId) select p.Id).Distinct(); _products = from p in _products join x in distinctIds on p.Id equals x select p; } else { searchContext.CategoryIds = categoryIds; _products = _productService.PrepareProductSearchQuery(searchContext); } //string.Join(", ", distinctIds.ToList()).Dump(); //_products // .Select(x => new { x.Id, x.Name }) // .ToList() // .ForEach(x => { // "{0} {1}".FormatWith(x.Id, x.Name).Dump(); // }); //_products.ToString().Dump(true); } return(_products); }
private void WriteProducts(UrlHelper urlHelper) { var ctx = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; var products = _productService.SearchProducts(ctx); foreach (var product in products) { var url = urlHelper.RouteUrl("Product", new { SeName = product.GetSeName() }, "http"); var updateFrequency = UpdateFrequency.Weekly; var updateTime = product.UpdatedOnUtc; WriteUrlLocation(url, updateFrequency, updateTime); } }
public ActionResult ProductAddPopupList(GridCommand command, ManufacturerModel.AddManufacturerProductModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var gridModel = new GridModel(); var ctx = new ProductSearchContext(); if (model.SearchCategoryId > 0) { ctx.CategoryIds.Add(model.SearchCategoryId); } ctx.ManufacturerId = model.SearchManufacturerId; ctx.Keywords = model.SearchProductName; ctx.LanguageId = _workContext.WorkingLanguage.Id; ctx.OrderBy = ProductSortingEnum.Position; ctx.PageIndex = command.Page - 1; ctx.PageSize = command.PageSize; ctx.ShowHidden = true; ctx.ProductType = model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null; var products = _productService.SearchProducts(ctx); gridModel.Data = products.Select(x => { var productModel = x.ToModel(); productModel.ProductTypeName = x.GetProductTypeLabel(_localizationService); return(productModel); }); gridModel.Total = products.TotalCount; return(new JsonResult { Data = gridModel }); }
// actions private decimal?CalculatePrice(int key, bool lowestPrice) { string requiredProperties = "TierPrices, AppliedDiscounts, ProductBundleItems"; var entity = GetExpandedEntity(key, requiredProperties); decimal?result = null; this.ProcessEntity(() => { if (lowestPrice) { if (entity.ProductType == ProductType.GroupedProduct) { var searchContext = new ProductSearchContext { OrderBy = ProductSortingEnum.Position, Query = this.GetExpandedEntitySet(requiredProperties), ParentGroupedProductId = entity.Id, PageSize = int.MaxValue, VisibleIndividuallyOnly = false }; Product lowestPriceProduct; var associatedProducts = Service.PrepareProductSearchQuery(searchContext); result = _priceCalculationService.Value.GetLowestPrice(entity, null, associatedProducts, out lowestPriceProduct); } else { bool displayFromMessage; result = _priceCalculationService.Value.GetLowestPrice(entity, null, out displayFromMessage); } } else { result = _priceCalculationService.Value.GetPreselectedPrice(entity, null); } return(null); }); return(result); }
// actions private decimal?CalculatePrice(int key, bool lowestPrice) { string requiredProperties = "TierPrices, AppliedDiscounts, ProductBundleItems"; var entity = GetExpandedEntity(key, requiredProperties); decimal?result = null; this.ProcessEntity(() => { if (lowestPrice) { if (entity.ProductType == ProductType.GroupedProduct) { var searchContext = new ProductSearchContext() { Query = this.GetExpandedEntitySet(requiredProperties), ParentGroupedProductId = entity.Id, VisibleIndividuallyOnly = false }; Product lowestPriceProduct; var associatedProducts = Service.PrepareProductSearchQuery(searchContext); result = _priceCalculationService.Value.GetLowestPrice(entity, associatedProducts, out lowestPriceProduct); } else { bool displayFromMessage; result = _priceCalculationService.Value.GetLowestPrice(entity, out displayFromMessage); } } else { result = _priceCalculationService.Value.GetFinalPrice(entity, null, _workContext.Value.CurrentCustomer, decimal.Zero, true, 1); } return(null); }); return(result); }
private void WriteProducts() { string location = _webHelper.GetStoreLocation(false); var ctx = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = _storeContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; var products = _productService.SearchProducts(ctx); foreach (var product in products) { //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) var url = string.Format("{0}{1}", location, product.GetSeName()); var updateFrequency = UpdateFrequency.Weekly; var updateTime = product.UpdatedOnUtc; WriteUrlLocation(url, updateFrequency, updateTime); } }
public List <Product> QualifiedProductsByProduct(IProductService productService, Product product, Store store) { var lst = new List <Product>(); if (product.ProductType == ProductType.SimpleProduct || product.ProductType == ProductType.BundledProduct) { lst.Add(product); } else if (product.ProductType == ProductType.GroupedProduct) { var associatedSearchContext = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = store.Id, VisibleIndividuallyOnly = false, ParentGroupedProductId = product.Id }; lst.AddRange(productService.SearchProducts(associatedSearchContext)); } return(lst); }
public void GetQualifiedProductsByProduct(Product product, Store store, List <Product> result) { result.Clear(); if (product.ProductType == ProductType.SimpleProduct || product.ProductType == ProductType.BundledProduct) { result.Add(product); } else if (product.ProductType == ProductType.GroupedProduct) { var associatedSearchContext = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = store.Id, VisibleIndividuallyOnly = false, ParentGroupedProductId = product.Id }; var productService = ProductService; result.AddRange(productService.SearchProducts(associatedSearchContext)); } }
private IQueryable <Product> AllProducts(List <int> categoryIds) { if (_products == null) { var searchContext = new ProductSearchContext { Query = _productRepository.TableUntracked, FeaturedProducts = (_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false), StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode, VisibleIndividuallyOnly = true }; if (categoryIds != null && categoryIds.Count > 1) { _products = _productService.PrepareProductSearchQuery(searchContext); var distinctIds = ( from p in _productRepository.TableUntracked join pc in _productCategoryRepository.TableUntracked on p.Id equals pc.ProductId where categoryIds.Contains(pc.CategoryId) select p.Id).Distinct(); _products = from p in _products join x in distinctIds on p.Id equals x select p; } else { searchContext.CategoryIds = categoryIds; _products = _productService.PrepareProductSearchQuery(searchContext); } } return(_products); }
private void CreateFeed(FeedFileCreationContext fileCreation, TaskExecutionContext taskContext) { var xmlSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, CheckCharacters = false }; using (var writer = XmlWriter.Create(fileCreation.Stream, xmlSettings)) { try { fileCreation.Logger.Information("Log file - Google Merchant Center feed."); var searchContext = new ProductSearchContext { OrderBy = ProductSortingEnum.CreatedOn, PageSize = Settings.PageSize, StoreId = fileCreation.Store.Id, VisibleIndividuallyOnly = true }; var currency = Helper.GetUsedCurrency(Settings.CurrencyId); var measureWeightSystemKey = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).SystemKeyword; writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "g", null, _googleNamespace); writer.WriteStartElement("channel"); writer.WriteElementString("title", "{0} - Feed for Google Merchant Center".FormatWith(fileCreation.Store.Name)); writer.WriteElementString("link", "http://base.google.com/base/"); writer.WriteElementString("description", "Information about products"); for (int i = 0; i < 9999999; ++i) { searchContext.PageIndex = i; // Perf _dbContext.DetachAll(); var products = _productService.SearchProducts(searchContext); if (fileCreation.TotalRecords == 0) { fileCreation.TotalRecords = products.TotalCount * fileCreation.StoreCount; // approx } foreach (var product in products) { fileCreation.Report(); if (product.ProductType == ProductType.SimpleProduct || product.ProductType == ProductType.BundledProduct) { WriteItem(fileCreation, writer, product, currency, measureWeightSystemKey); } else if (product.ProductType == ProductType.GroupedProduct) { var associatedSearchContext = new ProductSearchContext { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = fileCreation.Store.Id, VisibleIndividuallyOnly = false, ParentGroupedProductId = product.Id }; foreach (var associatedProduct in _productService.SearchProducts(associatedSearchContext)) { WriteItem(fileCreation, writer, associatedProduct, currency, measureWeightSystemKey); } } if (taskContext.CancellationToken.IsCancellationRequested) { fileCreation.Logger.Warning("A cancellation has been requested"); break; } } if (!products.HasNextPage || taskContext.CancellationToken.IsCancellationRequested) { break; } } writer.WriteEndElement(); // channel writer.WriteEndElement(); // rss writer.WriteEndDocument(); if (fileCreation.ErrorMessage.HasValue()) { fileCreation.Logger.Error(fileCreation.ErrorMessage); } } catch (Exception exc) { fileCreation.Logger.Error(exc.Message, exc); } } }
public virtual void CreateFeed(Stream stream, Store store) { string breakingError = null; var xmlSettings = new XmlWriterSettings { Encoding = Encoding.UTF8 }; using (var writer = XmlWriter.Create(stream, xmlSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "g", null, _googleNamespace); writer.WriteStartElement("channel"); writer.WriteElementString("title", "{0} - Feed for Google Merchant Center".FormatWith(store.Name)); writer.WriteElementString("link", "http://base.google.com/base/"); writer.WriteElementString("description", "Information about products"); var currency = Helper.GetUsedCurrency(Settings.CurrencyId); var searchContext = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = store.Id, VisibleIndividuallyOnly = true }; var products = _productService.SearchProducts(searchContext); foreach (var product in products) { var qualifiedProducts = Helper.QualifiedProductsByProduct(_productService, product, store); foreach (var qualifiedProduct in qualifiedProducts) { writer.WriteStartElement("item"); try { breakingError = WriteItem(writer, store, qualifiedProduct, currency); } catch (Exception exc) { exc.Dump(); } writer.WriteEndElement(); // item } if (breakingError.HasValue()) { break; } } writer.WriteEndElement(); // channel writer.WriteEndElement(); // rss writer.WriteEndDocument(); } if (breakingError.HasValue()) { throw new SmartException(breakingError); } }
private void CreateFeed(FeedFileCreationContext fileCreation, TaskExecutionContext taskContext) { var xmlSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, CheckCharacters = false }; using (var writer = XmlWriter.Create(fileCreation.Stream, xmlSettings)) { try { fileCreation.Logger.Information("Log file - Google Merchant Center feed."); var searchContext = new ProductSearchContext() { OrderBy = ProductSortingEnum.CreatedOn, PageSize = int.MaxValue, StoreId = fileCreation.Store.Id, VisibleIndividuallyOnly = true }; string breakingError = null; var qualifiedProducts = new List <Product>(); var currency = Helper.GetUsedCurrency(Settings.CurrencyId); var products = _productService.SearchProducts(searchContext); var measureWeightSystemKey = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).SystemKeyword; if (fileCreation.TotalRecords == 0) { fileCreation.TotalRecords = products.Count * fileCreation.StoreCount; } writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "g", null, _googleNamespace); writer.WriteStartElement("channel"); writer.WriteElementString("title", "{0} - Feed for Google Merchant Center".FormatWith(fileCreation.Store.Name)); writer.WriteElementString("link", "http://base.google.com/base/"); writer.WriteElementString("description", "Information about products"); foreach (var product in products) { fileCreation.Report(); Helper.GetQualifiedProductsByProduct(product, fileCreation.Store, qualifiedProducts); foreach (var qualifiedProduct in qualifiedProducts) { writer.WriteStartElement("item"); try { breakingError = WriteItem(writer, fileCreation.Store, qualifiedProduct, currency, measureWeightSystemKey); } catch (Exception exc) { fileCreation.Logger.Error(exc.Message, exc); } writer.WriteEndElement(); // item } if (breakingError.HasValue()) { fileCreation.Logger.Error(breakingError); break; } if (taskContext.CancellationToken.IsCancellationRequested) { fileCreation.Logger.Warning("A cancellation has been requested"); break; } } writer.WriteEndElement(); // channel writer.WriteEndElement(); // rss writer.WriteEndDocument(); if (breakingError.HasValue()) { throw new SmartException(breakingError); } } catch (Exception exc) { fileCreation.Logger.Error(exc.Message, exc); } } }
public ActionResult Sitemap() { if (!_commonSettings.Value.SitemapEnabled) { return(HttpNotFound()); } var roleIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(x => x.Active).Select(x => x.Id).ToList(); string cacheKey = ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY.FormatInvariant(_services.WorkContext.WorkingLanguage.Id, string.Join(",", roleIds), _services.StoreContext.CurrentStore.Id); var result = _services.Cache.Get(cacheKey, () => { var model = new SitemapModel(); if (_commonSettings.Value.SitemapIncludeCategories) { var categories = _categoryService.Value.GetAllCategories(); model.Categories = categories.Select(x => x.ToModel()).ToList(); } if (_commonSettings.Value.SitemapIncludeManufacturers) { var manufacturers = _manufacturerService.Value.GetAllManufacturers(); model.Manufacturers = manufacturers.Select(x => x.ToModel()).ToList(); } if (_commonSettings.Value.SitemapIncludeProducts) { //limit product to 200 until paging is supported on this page IList <int> filterableSpecificationAttributeOptionIds = null; var productSearchContext = new ProductSearchContext(); productSearchContext.OrderBy = ProductSortingEnum.Position; productSearchContext.PageSize = 200; productSearchContext.FilterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIds; productSearchContext.StoreId = _services.StoreContext.CurrentStoreIdIfMultiStoreMode; productSearchContext.VisibleIndividuallyOnly = true; var products = _productService.Value.SearchProducts(productSearchContext); model.Products = products.Select(product => new ProductOverviewModel() { Id = product.Id, Name = product.GetLocalized(x => x.Name).EmptyNull(), ShortDescription = product.GetLocalized(x => x.ShortDescription), FullDescription = product.GetLocalized(x => x.FullDescription), SeName = product.GetSeName(), }).ToList(); } if (_commonSettings.Value.SitemapIncludeTopics) { var topics = _topicService.Value.GetAllTopics(_services.StoreContext.CurrentStore.Id) .ToList() .FindAll(t => t.IncludeInSitemap); model.Topics = topics.Select(topic => new TopicModel() { Id = topic.Id, SystemName = topic.SystemName, IncludeInSitemap = topic.IncludeInSitemap, IsPasswordProtected = topic.IsPasswordProtected, Title = topic.GetLocalized(x => x.Title), }) .ToList(); } return(model); }); return(View(result)); }