/// <summary> /// Get category list /// </summary> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Category list</returns> protected virtual List <SelectListItem> GetCategoryList(bool showHidden = true) { var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.CategoriesListKey, showHidden); var listItems = _staticCacheManager.Get(cacheKey, () => { var categories = _categoryService.GetAllCategories(showHidden: showHidden); return(categories.Select(c => new SelectListItem { Text = _categoryService.GetFormattedBreadCrumb(c, categories), Value = c.Id.ToString() })); }); var result = new List <SelectListItem>(); //clone the list to ensure that "selected" property is not set foreach (var item in listItems) { result.Add(new SelectListItem { Text = item.Text, Value = item.Value }); } return(result); }
/// <summary> /// Gets product attribute mappings by product identifier /// </summary> /// <param name="productId">The product identifier</param> /// <returns>Product attribute mapping collection</returns> public virtual IList <ProductAttributeMapping> GetProductAttributeMappingsByProductId(int productId) { var allCacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopCatalogDefaults.ProductAttributeMappingsAllCacheKey, productId); var query = from pam in _productAttributeMappingRepository.Table join atb in _productAttributeRepository.Table on pam.ProductAttributeId equals atb.Id orderby pam.DisplayOrder, pam.Id where pam.ProductId == productId select new ProductAttributeMapping() { Id = pam.Id, DefaultValue = pam.DefaultValue, DisplayOrder = pam.DisplayOrder, IsRequired = pam.IsRequired, ProductId = pam.ProductId, TextPrompt = pam.TextPrompt, AttributeControlType = pam.AttributeControlType, ConditionAttributeXml = pam.ConditionAttributeXml, ProductAttributeId = pam.ProductAttributeId, ProductAttributeName = atb.Name, ValidationMaxLength = pam.ValidationMaxLength, ValidationMinLength = pam.ValidationMinLength, AttributeControlTypeId = pam.AttributeControlTypeId, ValidationFileAllowedExtensions = pam.ValidationFileAllowedExtensions, ValidationFileMaximumSize = pam.ValidationFileMaximumSize }; var attributes = query.ToCachedList(allCacheKey) ?? new List <ProductAttributeMapping>(); return(attributes); }
public string GetSynchronizationInfo() { var res = _staticCacheManager.Get(_cacheKeyService.PrepareKeyForDefaultCache(SendinBlueDefaults.SyncKeyCache), () => string.Empty); _staticCacheManager.Remove(SendinBlueDefaults.SyncKeyCache); return(res); }
public override IActionResult Categories() { //ensure that Avalara tax provider is active if (!_taxPluginManager.IsPluginActive(AvalaraTaxDefaults.SystemName)) { //if isn't active return base action result RouteData.Values["controller"] = "Tax"; return(base.Categories()); } if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedView()); } //prepare model var model = new Models.Tax.TaxCategorySearchModel(); var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(AvalaraTaxDefaults.TaxCodeTypesCacheKey); var taxCodeTypes = _cacheManager.Get(cacheKey, () => _avalaraTaxManager.GetTaxCodeTypes()); if (taxCodeTypes != null) { model.AvailableTypes = taxCodeTypes.Select(type => new SelectListItem(type.Value, type.Key)).ToList(); } model.SetGridPageSize(); //use overridden view return(View("~/Plugins/Tax.Avalara/Views/Tax/Categories.cshtml", model)); }
/// <summary> /// Gets all shipping methods /// </summary> /// <param name="filterByCountryId">The country identifier to filter by</param> /// <returns>Shipping methods</returns> public virtual IList <ShippingMethod> GetAllShippingMethods(int?filterByCountryId = null) { var key = _cacheKeyService.PrepareKeyForDefaultCache(SmiShippingDefaults.ShippingMethodsAllCacheKey, filterByCountryId); if (filterByCountryId.HasValue && filterByCountryId.Value > 0) { var query1 = from sm in _shippingMethodRepository.Table join smcm in _shippingMethodCountryMappingRepository.Table on sm.Id equals smcm.ShippingMethodId where smcm.CountryId == filterByCountryId.Value select sm.Id; query1 = query1.Distinct(); var query2 = from sm in _shippingMethodRepository.Table where !query1.Contains(sm.Id) orderby sm.DisplayOrder, sm.Id select sm; return(query2.ToCachedList(key)); } var query = from sm in _shippingMethodRepository.Table orderby sm.DisplayOrder, sm.Id select sm; return(query.ToCachedList(key)); }
/// <summary> /// Prepare the logo model /// </summary> /// <returns>Logo model</returns> public virtual LogoModel PrepareLogoModel() { var model = new LogoModel { StoreName = _localizationService.GetLocalized(_storeContext.CurrentStore, x => x.Name) }; var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.StoreLogoPath , _storeContext.CurrentStore, _themeContext.WorkingThemeName, _webHelper.IsCurrentConnectionSecured()); model.LogoPath = _staticCacheManager.Get(cacheKey, () => { var logo = string.Empty; var logoPictureId = _storeInformationSettings.LogoPictureId; if (logoPictureId > 0) { logo = _pictureService.GetPictureUrl(logoPictureId, showDefaultPicture: false); } if (string.IsNullOrEmpty(logo)) { //use default logo var pathBase = _httpContextAccessor.HttpContext.Request.PathBase.Value ?? string.Empty; var storeLocation = _mediaSettings.UseAbsoluteImagePath ? _webHelper.GetStoreLocation() : $"{pathBase}/"; logo = $"{storeLocation}Themes/{_themeContext.WorkingThemeName}/Content/images/logo.png"; } return(logo); }); return(model); }
/// <summary> /// Gets all cached localized properties /// </summary> /// <returns>Cached localized properties</returns> protected virtual IList <LocalizedProperty> GetAllLocalizedProperties() { var query = from lp in _localizedPropertyRepository.Table select lp; return(query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(BopLocalizationDefaults.LocalizedPropertyAllCacheKey))); }
/// <summary> /// Gets all checkout attributes /// </summary> /// <param name="storeId">Store identifier</param> /// <param name="excludeShippableAttributes">A value indicating whether we should exclude shippable attributes</param> /// <returns>Checkout attributes</returns> public virtual IList <CheckoutAttribute> GetAllCheckoutAttributes(int storeId = 0, bool excludeShippableAttributes = false) { var key = _cacheKeyService.PrepareKeyForDefaultCache(SmiOrderDefaults.CheckoutAttributesAllCacheKey, storeId, excludeShippableAttributes); return(_staticCacheManager.Get(key, () => { var query = from ca in _checkoutAttributeRepository.Table orderby ca.DisplayOrder, ca.Id select ca; var checkoutAttributes = query.ToList(); if (storeId > 0) { //store mapping checkoutAttributes = checkoutAttributes.Where(ca => _storeMappingService.Authorize(ca)).ToList(); } if (excludeShippableAttributes) { //remove attributes which require shippable products checkoutAttributes = checkoutAttributes.Where(x => !x.ShippableProductRequired).ToList(); } return checkoutAttributes; })); }
/// <summary> /// Gets message templates by the name /// </summary> /// <param name="messageTemplateName">Message template name</param> /// <param name="storeId">Store identifier; pass null to load all records</param> /// <returns>List of message templates</returns> public virtual IList <MessageTemplate> GetMessageTemplatesByName(string messageTemplateName, int?storeId = null) { if (string.IsNullOrWhiteSpace(messageTemplateName)) { throw new ArgumentException(nameof(messageTemplateName)); } var key = _cacheKeyService.PrepareKeyForDefaultCache(NopMessageDefaults.MessageTemplatesByNameCacheKey, messageTemplateName, storeId); return(_staticCacheManager.Get(key, () => { //get message templates with the passed name var templates = _messageTemplateRepository.Table .Where(messageTemplate => messageTemplate.Name.Equals(messageTemplateName)) .OrderBy(messageTemplate => messageTemplate.Id).ToList(); //filter by the store if (storeId.HasValue && storeId.Value > 0) { templates = templates.Where(messageTemplate => _storeMappingService.Authorize(messageTemplate, storeId.Value)).ToList(); } return templates; })); }
/// <summary> /// Gets all address attributes /// </summary> /// <returns>Address attributes</returns> public virtual IList <AddressAttribute> GetAllAddressAttributes() { var query = from aa in _addressAttributeRepository.Table orderby aa.DisplayOrder, aa.Id select aa; return(query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopCommonDefaults.AddressAttributesAllCacheKey))); }
/// <summary> /// Gets all return request actions /// </summary> /// <returns>Return request actions</returns> public virtual IList <ReturnRequestAction> GetAllReturnRequestActions() { var query = from rra in _returnRequestActionRepository.Table orderby rra.DisplayOrder, rra.Id select rra; return(query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopOrderDefaults.ReturnRequestActionAllCacheKey))); }
public IList <Category> GetAllCategories(bool showHidden = false) { var key = _cacheKeyService.PrepareKeyForDefaultCache(MotelCatalogDefaults.CategoriesAllCacheKey, showHidden); var categories = _staticCacheManager.Get(key, () => GetAllCategories(string.Empty, showHidden: showHidden).ToList()); return(categories); }
/// <summary> /// Gets specification attributes that have options /// </summary> /// <returns>Specification attributes that have available options</returns> public virtual IList <SpecificationAttribute> GetSpecificationAttributesWithOptions() { var query = from sa in _specificationAttributeRepository.Table where _specificationAttributeOptionRepository.Table.Any(o => o.SpecificationAttributeId == sa.Id) select sa; return(query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopCatalogDefaults.SpecAttributesWithOptionsCacheKey))); }
/// <summary> /// Gets all customer attributes /// </summary> /// <returns>Customer attributes</returns> public virtual IList <CustomerAttribute> GetAllCustomerAttributes() { var query = from ca in _customerAttributeRepository.Table orderby ca.DisplayOrder, ca.Id select ca; return(query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopCustomerServicesDefaults.CustomerAttributesAllCacheKey))); }
/// <summary> /// Get all delivery dates /// </summary> /// <returns>Delivery dates</returns> public virtual IList <DeliveryDate> GetAllDeliveryDates() { var query = from dd in _deliveryDateRepository.Table orderby dd.DisplayOrder, dd.Id select dd; var deliveryDates = query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopShippingDefaults.DeliveryDatesAllCacheKey)); return(deliveryDates); }
/// <summary> /// Gets all measure dimensions /// </summary> /// <returns>Measure dimensions</returns> public virtual IList <MeasureDimension> GetAllMeasureDimensions() { var query = from md in _measureDimensionRepository.Table orderby md.DisplayOrder, md.Id select md; var measureDimensions = query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopDirectoryDefaults.MeasureDimensionsAllCacheKey)); return(measureDimensions); }
/// <summary> /// Gets all discounts /// </summary> /// <param name="discountType">Discount type; pass null to load all records</param> /// <param name="couponCode">Coupon code to find (exact match); pass null or empty to load all records</param> /// <param name="discountName">Discount name; pass null or empty to load all records</param> /// <param name="showHidden">A value indicating whether to show expired and not started discounts</param> /// <param name="startDateUtc">Discount start date; pass null to load all records</param> /// <param name="endDateUtc">Discount end date; pass null to load all records</param> /// <returns>Discounts</returns> public virtual IList <Discount> GetAllDiscounts(DiscountType?discountType = null, string couponCode = null, string discountName = null, bool showHidden = false, DateTime?startDateUtc = null, DateTime?endDateUtc = null) { //we load all discounts, and filter them using "discountType" parameter later (in memory) //we do it because we know that this method is invoked several times per HTTP request with distinct "discountType" parameter //that's why let's access the database only once var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopDiscountDefaults.DiscountAllCacheKey , showHidden, couponCode ?? string.Empty, discountName ?? string.Empty); var query = _discountRepository.Table; if (!showHidden) { query = query.Where(discount => (!discount.StartDateUtc.HasValue || discount.StartDateUtc <= DateTime.UtcNow) && (!discount.EndDateUtc.HasValue || discount.EndDateUtc >= DateTime.UtcNow)); } //filter by coupon code if (!string.IsNullOrEmpty(couponCode)) { query = query.Where(discount => discount.CouponCode == couponCode); } //filter by name if (!string.IsNullOrEmpty(discountName)) { query = query.Where(discount => discount.Name.Contains(discountName)); } query = query.OrderBy(discount => discount.Name).ThenBy(discount => discount.Id); query = query.ToCachedList(cacheKey).AsQueryable(); //we know that this method is usually invoked multiple times //that's why we filter discounts by type and dates on the application layer if (discountType.HasValue) { query = query.Where(discount => discount.DiscountType == discountType.Value); } //filter by dates if (startDateUtc.HasValue) { query = query.Where(discount => !discount.StartDateUtc.HasValue || discount.StartDateUtc >= startDateUtc.Value); } if (endDateUtc.HasValue) { query = query.Where(discount => !discount.EndDateUtc.HasValue || discount.EndDateUtc <= endDateUtc.Value); } return(query.ToList()); }
/// <summary> /// Get permission records by customer role identifier /// </summary> /// <param name="userRoleId">Customer role identifier</param> /// <returns>Permissions</returns> protected virtual IList <Auth_Assign> GetPermissionRecordsByUserRoleId(int userRoleId, int objectType) { var key = _cacheKeyService.PrepareKeyForDefaultCache(MotelSecurityDefaults.PermissionsAllowedCacheKey, objectType, userRoleId); var query = from pa in _permissionAssign.Table where pa.ObjectID == userRoleId && pa.ObjectType == objectType select pa; return(query.ToCachedList(key)); }
public virtual Core.Domain.Customers.Customer GetCustomer(Guid id) { if (id == Guid.Empty) { return(null); } var key = _cacheKeyService.PrepareKeyForDefaultCache(NopCustomerDefaults.CustomerPublicCacheKey, id); return(_customerRepository.Table.Where(x => x.Id == id).ToCachedFirstOrDefault(key)); }
/// <summary> /// Gets product attribute mappings by product identifier /// </summary> /// <param name="productId">The product identifier</param> /// <returns>Product attribute mapping collection</returns> public virtual IList <ProductAttributeMapping> GetProductAttributeMappingsByProductId(int productId) { var allCacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopCatalogDefaults.ProductAttributeMappingsAllCacheKey, productId); var query = from pam in _productAttributeMappingRepository.Table orderby pam.DisplayOrder, pam.Id where pam.ProductId == productId select pam; var attributes = query.ToCachedList(allCacheKey) ?? new List <ProductAttributeMapping>(); return(attributes); }
/// <summary> /// Get permission records by customer role identifier /// </summary> /// <param name="customerRoleId">Customer role identifier</param> /// <returns>Permissions</returns> protected virtual IList<PermissionRecord> GetPermissionRecordsByCustomerRoleId(int customerRoleId) { var key = _cacheKeyService.PrepareKeyForDefaultCache(NopSecurityDefaults.PermissionsAllByCustomerRoleIdCacheKey, customerRoleId); var query = from pr in _permissionRecordRepository.Table join prcrm in _permissionRecordCustomerRoleMappingRepository.Table on pr.Id equals prcrm .PermissionRecordId where prcrm.CustomerRoleId == customerRoleId orderby pr.Id select pr; return query.ToCachedList(key); }
/// <summary> /// Gets all products displayed on the home page /// </summary> /// <returns>Products</returns> public virtual IList <Product> GetAllProductsDisplayedOnHomepage() { var query = from p in _productRepository.Table orderby p.DisplayOrder, p.Id where p.Published && !p.Deleted && p.ShowOnHomepage select p; var products = query.ToCachedList(_cacheKeyService.PrepareKeyForDefaultCache(NopCatalogDefaults.ProductsAllDisplayedOnHomepageCacheKey)); return(products); }
public IList <string> GetNameRoles(int userId) { var key = _cacheKeyService.PrepareKeyForDefaultCache(MotelSecurityDefaults.RolesAllowedCacheKey, userId); var query = from urm in _repositoryRolesUser.Table join ur in _repositoryRoles.Table on urm.RoleID equals ur.Id where urm.UserID == userId select ur.Name; //if(query.Count() == 0) // return null; //return _staticCache.Get(key,()=> query.ToList()); return(query.ToList()); }
/// <summary> /// Initiates an asynchronous operation to get a value indicating whether some file (thumb) already exists /// </summary> /// <param name="thumbFilePath">Thumb file path</param> /// <param name="thumbFileName">Thumb file name</param> /// <returns>Result</returns> protected virtual async Task <bool> GeneratedThumbExistsAsync(string thumbFilePath, string thumbFileName) { try { var key = _cacheKeyService.PrepareKeyForDefaultCache(NopMediaDefaults.ThumbExistsCacheKey, thumbFileName); return(await _staticCacheManager.GetAsync(key, async() => { using var client = CreateS3Client(); //var result = await _amazonS3Client.GetObjectAsync( // new GetObjectRequest // { // BucketName = _bucketName, // Key = thumbFileName, // ByteRange = new ByteRange("bytes=0-3") // }, // _httpContextAccessor.HttpContext.RequestAborted); var result = await client.GetObjectMetadataAsync( new GetObjectMetadataRequest { BucketName = _awsS3Settings.Bucket, Key = thumbFileName, }, _httpContextAccessor.HttpContext.RequestAborted); return result.HttpStatusCode != System.Net.HttpStatusCode.NotFound; })); }
/// <summary> /// Gets tax rate /// </summary> /// <param name="taxRateRequest">Tax rate request</param> /// <returns>Tax</returns> public TaxRateResult GetTaxRate(TaxRateRequest taxRateRequest) { var result = new TaxRateResult(); //the tax rate calculation by fixed rate if (!_countryStateZipSettings.CountryStateZipEnabled) { result.TaxRate = _settingService.GetSettingByKey <decimal>(string.Format(FixedOrByCountryStateZipDefaults.FixedRateSettingsKey, taxRateRequest.TaxCategoryId)); return(result); } //the tax rate calculation by country & state & zip if (taxRateRequest.Address == null) { result.Errors.Add("Address is not set"); return(result); } //first, load all tax rate records (cached) - loaded only once var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(ModelCacheEventConsumer.ALL_TAX_RATES_MODEL_KEY); var allTaxRates = _staticCacheManager.Get(cacheKey, () => _taxRateService.GetAllTaxRates().Select(taxRate => new TaxRate { Id = taxRate.Id, StoreId = taxRate.StoreId, TaxCategoryId = taxRate.TaxCategoryId, CountryId = taxRate.CountryId, StateProvinceId = taxRate.StateProvinceId, Zip = taxRate.Zip, Percentage = taxRate.Percentage }).ToList()); var storeId = taxRateRequest.CurrentStoreId; var taxCategoryId = taxRateRequest.TaxCategoryId; var countryId = taxRateRequest.Address.CountryId; var stateProvinceId = taxRateRequest.Address.StateProvinceId; var zip = taxRateRequest.Address.ZipPostalCode?.Trim() ?? string.Empty; var existingRates = allTaxRates.Where(taxRate => taxRate.CountryId == countryId && taxRate.TaxCategoryId == taxCategoryId); //filter by store var matchedByStore = existingRates.Where(taxRate => storeId == taxRate.StoreId || taxRate.StoreId == 0); //filter by state/province var matchedByStateProvince = matchedByStore.Where(taxRate => stateProvinceId == taxRate.StateProvinceId || taxRate.StateProvinceId == 0); //filter by zip var matchedByZip = matchedByStateProvince.Where(taxRate => string.IsNullOrWhiteSpace(taxRate.Zip) || taxRate.Zip.Equals(zip, StringComparison.InvariantCultureIgnoreCase)); //sort from particular to general, more particular cases will be the first var foundRecords = matchedByZip.OrderBy(r => r.StoreId == 0).ThenBy(r => r.StateProvinceId == 0).ThenBy(r => string.IsNullOrEmpty(r.Zip)); var foundRecord = foundRecords.FirstOrDefault(); if (foundRecord != null) { result.TaxRate = foundRecord.Percentage; } return(result); }
/// <summary> /// Prepare the home page news items model /// </summary> /// <returns>Home page news items model</returns> public virtual HomepageNewsItemsModel PrepareHomepageNewsItemsModel() { var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.HomepageNewsModelKey, _workContext.WorkingLanguage, _storeContext.CurrentStore); var cachedModel = _staticCacheManager.Get(cacheKey, () => { var newsItems = _newsService.GetAllNews(_workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id, 0, _newsSettings.MainPageNewsCount); return(new HomepageNewsItemsModel { WorkingLanguageId = _workContext.WorkingLanguage.Id, NewsItems = newsItems.Where(x => x.ShowOnHomePage) .Select(x => { var newsModel = new NewsItemModel(); PrepareNewsItemModel(newsModel, x, false); return newsModel; }).OrderBy(x => x.DisplayOrder).ToList() }); }); //"Comments" property of "NewsItemModel" object depends on the current customer. //Furthermore, we just don't need it for home page news. So let's reset it. //But first we need to clone the cached model (the updated one should not be cached) var model = (HomepageNewsItemsModel)cachedModel.Clone(); foreach (var newsItemModel in model.NewsItems) { newsItemModel.Comments.Clear(); } return(model); }
/// <summary> /// Gets all languages /// </summary> /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Languages</returns> public virtual IList <Language> GetAllLanguages(bool showHidden = false, int storeId = 0) { var query = _languageRepository.Table; if (!showHidden) { query = query.Where(l => l.Published); } query = query.OrderBy(l => l.DisplayOrder).ThenBy(l => l.Id); //cacheable copy var key = _cacheKeyService.PrepareKeyForDefaultCache(NopLocalizationDefaults.LanguagesAllCacheKey, storeId, showHidden); var languages = _staticCacheManager.Get(key, () => { var allLanguages = query.ToList(); //store mapping if (storeId > 0) { allLanguages = allLanguages .Where(l => _storeMappingService.Authorize(l, storeId)) .ToList(); } return(allLanguages); }); return(languages); }
/// <summary> /// Gets all currencies /// </summary> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <param name="storeId">Load records allowed only in a specified store; pass 0 to load all records</param> /// <returns>Currencies</returns> public virtual IList <Currency> GetAllCurrencies(bool showHidden = false, int storeId = 0) { var query = _currencyRepository.Table; if (!showHidden) { query = query.Where(c => c.Published); } query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Id); var key = _cacheKeyService.PrepareKeyForDefaultCache(NopDirectoryDefaults.CurrenciesAllCacheKey, showHidden); var currencies = query.ToCachedList(key); //store mapping if (storeId > 0) { currencies = currencies .Where(c => _storeMappingService.Authorize(c, storeId)) .ToList(); } return(currencies); }
public IViewComponentResult Invoke(int productId, int?productThumbPictureSize) { if (!_catalogSettings.ProductsAlsoPurchasedEnabled) { return(Content("")); } //load and cache report var productIds = _staticCacheManager.Get(_cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.ProductsAlsoPurchasedIdsKey, productId, _storeContext.CurrentStore), () => _orderReportService.GetAlsoPurchasedProductsIds(_storeContext.CurrentStore.Id, productId, _catalogSettings.ProductsAlsoPurchasedNumber) ); //load products var products = _productService.GetProductsByIds(productIds); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }
public IViewComponentResult Invoke(int?productThumbPictureSize) { if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0) { return(Content("")); } //load and cache report var report = _staticCacheManager.Get(_cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.HomepageBestsellersIdsKey, _storeContext.CurrentStore), () => _orderReportService.BestSellersReport( storeId: _storeContext.CurrentStore.Id, pageSize: _catalogSettings.NumberOfBestsellersOnHomepage) .ToList()); //load products var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray()); //ACL and store mapping products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); //availability dates products = products.Where(p => _productService.ProductIsAvailable(p)).ToList(); if (!products.Any()) { return(Content("")); } //prepare model var model = _productModelFactory.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList(); return(View(model)); }