/// <summary>
        /// Get product count for each of existing product tag
        /// </summary>
        /// <param name="storeId">Store identifier</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Dictionary of "product tag ID : product count"</returns>
        public Dictionary <Guid, int> GetProductCount(Guid storeId, bool showHidden)
        {
            var allowedCustomerRolesIds = string.Empty;

            if (!showHidden && !_catalogSettings.IgnoreAcl)
            {
                //Access control list. Allowed customer roles
                //pass customer role identifiers as comma-delimited string
                allowedCustomerRolesIds = string.Join(",", _customerService.GetCustomerRoleIds(_workContext.CurrentCustomer));
            }

            var key = _cacheKeyService.PrepareKeyForDefaultCache(NopCatalogDefaults.ProductTagCountCacheKey, storeId,
                                                                 _customerService.GetCustomerRoleIds(_workContext.CurrentCustomer),
                                                                 showHidden);

            return(_staticCacheManager.Get(key, () =>
            {
                //prepare input parameters
                var pStoreId = SqlParameterHelper.GetGuidParameter("StoreId", storeId);
                var pAllowedCustomerRoleIds = SqlParameterHelper.GetStringParameter("AllowedCustomerRoleIds", allowedCustomerRolesIds);

                //invoke stored procedure
                return _dataProvider.QueryProc <ProductTagWithCount>("ProductTagCountLoadAll",
                                                                     pStoreId,
                                                                     pAllowedCustomerRoleIds)
                .ToDictionary(item => item.ProductTagId, item => item.ProductCount);
            }));
        }
示例#2
0
        /// <summary>
        /// Search products
        /// </summary>
        /// <param name="filterableSpecificationAttributeOptionIds">The specification attribute option identifiers applied to loaded products (all pages)</param>
        /// <param name="loadFilterableSpecificationAttributeOptionIds">A value indicating whether we should load the specification attribute option identifiers applied to loaded products (all pages)</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="categoryIds">Category identifiers</param>
        /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param>
        /// <param name="storeId">Store identifier; 0 to load all records</param>
        /// <param name="vendorId">Vendor identifier; 0 to load all records</param>
        /// <param name="warehouseId">Warehouse identifier; 0 to load all records</param>
        /// <param name="productType">Product type; 0 to load all records</param>
        /// <param name="visibleIndividuallyOnly">A values indicating whether to load only products marked as "visible individually"; "false" to load all records; "true" to load "visible individually" only</param>
        /// <param name="markedAsNewOnly">A values indicating whether to load only products marked as "new"; "false" to load all records; "true" to load "marked as new" only</param>
        /// <param name="featuredProducts">A value indicating whether loaded products are marked as featured (relates only to categories and manufacturers). 0 to load featured products only, 1 to load not featured products only, null to load all products</param>
        /// <param name="priceMin">Minimum price; null to load all records</param>
        /// <param name="priceMax">Maximum price; null to load all records</param>
        /// <param name="productTagId">Product tag identifier; 0 to load all records</param>
        /// <param name="keywords">Keywords</param>
        /// <param name="searchDescriptions">A value indicating whether to search by a specified "keyword" in product descriptions</param>
        /// <param name="searchManufacturerPartNumber">A value indicating whether to search by a specified "keyword" in manufacturer part number</param>
        /// <param name="searchSku">A value indicating whether to search by a specified "keyword" in product SKU</param>
        /// <param name="searchProductTags">A value indicating whether to search by a specified "keyword" in product tags</param>
        /// <param name="languageId">Language identifier (search for text searching)</param>
        /// <param name="filteredSpecs">Filtered product specification identifiers</param>
        /// <param name="orderBy">Order by</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <param name="overridePublished">
        /// null - process "Published" property according to "showHidden" parameter
        /// true - load only "Published" products
        /// false - load only "Unpublished" products
        /// </param>
        /// <returns>Products</returns>
        public virtual IPagedList <Product> SearchProducts(
            out IList <int> filterableSpecificationAttributeOptionIds,
            bool loadFilterableSpecificationAttributeOptionIds = false,
            int pageIndex                     = 0,
            int pageSize                      = int.MaxValue,
            IList <Guid> categoryIds          = null,
            Guid manufacturerId               = default,
            Guid storeId                      = default,
            Guid vendorId                     = default,
            Guid warehouseId                  = default,
            ProductType?productType           = null,
            bool visibleIndividuallyOnly      = false,
            bool markedAsNewOnly              = false,
            bool?featuredProducts             = null,
            decimal?priceMin                  = null,
            decimal?priceMax                  = null,
            int productTagId                  = 0,
            string keywords                   = null,
            bool searchDescriptions           = false,
            bool searchManufacturerPartNumber = true,
            bool searchSku                    = true,
            bool searchProductTags            = false,
            Guid languageId                   = default,
            IList <int> filteredSpecs         = null,
            ProductSortingEnum orderBy        = ProductSortingEnum.Position,
            bool showHidden                   = false,
            bool?overridePublished            = null)
        {
            filterableSpecificationAttributeOptionIds = new List <int>();

            //validate "categoryIds" parameter
            if (categoryIds != null && categoryIds.Contains(Guid.Empty))
            {
                categoryIds.Remove(Guid.Empty);
            }

            //pass category identifiers as comma-delimited string
            var commaSeparatedCategoryIds = categoryIds == null ? string.Empty : string.Join(",", categoryIds);

            //pass specification identifiers as comma-delimited string
            var commaSeparatedSpecIds = string.Empty;

            if (filteredSpecs != null)
            {
                ((List <int>)filteredSpecs).Sort();
                commaSeparatedSpecIds = string.Join(",", filteredSpecs);
            }

            //some databases don't support int.MaxValue
            if (pageSize == int.MaxValue)
            {
                pageSize = int.MaxValue - 1;
            }

            //prepare input parameters
            var pCategoryIds                  = SqlParameterHelper.GetStringParameter("CategoryIds", commaSeparatedCategoryIds);
            var pManufacturerId               = SqlParameterHelper.GetGuidParameter("ManufacturerId", manufacturerId);
            var pStoreId                      = SqlParameterHelper.GetGuidParameter("StoreId", storeId);
            var pVendorId                     = SqlParameterHelper.GetGuidParameter("VendorId", vendorId);
            var pWarehouseId                  = SqlParameterHelper.GetGuidParameter("WarehouseId", warehouseId);
            var pProductTypeId                = SqlParameterHelper.GetInt32Parameter("ProductTypeId", (int?)productType);
            var pVisibleIndividuallyOnly      = SqlParameterHelper.GetBooleanParameter("VisibleIndividuallyOnly", visibleIndividuallyOnly);
            var pMarkedAsNewOnly              = SqlParameterHelper.GetBooleanParameter("MarkedAsNewOnly", markedAsNewOnly);
            var pProductTagId                 = SqlParameterHelper.GetInt32Parameter("ProductTagId", productTagId);
            var pFeaturedProducts             = SqlParameterHelper.GetBooleanParameter("FeaturedProducts", featuredProducts);
            var pPriceMin                     = SqlParameterHelper.GetDecimalParameter("PriceMin", priceMin);
            var pPriceMax                     = SqlParameterHelper.GetDecimalParameter("PriceMax", priceMax);
            var pKeywords                     = SqlParameterHelper.GetStringParameter("Keywords", keywords);
            var pSearchDescriptions           = SqlParameterHelper.GetBooleanParameter("SearchDescriptions", searchDescriptions);
            var pSearchManufacturerPartNumber = SqlParameterHelper.GetBooleanParameter("SearchManufacturerPartNumber", searchManufacturerPartNumber);
            var pSearchSku                    = SqlParameterHelper.GetBooleanParameter("SearchSku", searchSku);
            var pSearchProductTags            = SqlParameterHelper.GetBooleanParameter("SearchProductTags", searchProductTags);
            var pUseFullTextSearch            = SqlParameterHelper.GetBooleanParameter("UseFullTextSearch", _commonSettings.UseFullTextSearch);
            var pFullTextMode                 = SqlParameterHelper.GetInt32Parameter("FullTextMode", (int)_commonSettings.FullTextMode);
            var pFilteredSpecs                = SqlParameterHelper.GetStringParameter("FilteredSpecs", commaSeparatedSpecIds);
            var pLanguageId                   = SqlParameterHelper.GetGuidParameter("LanguageId", languageId);
            var pOrderBy                      = SqlParameterHelper.GetInt32Parameter("OrderBy", (int)orderBy);
            var pAllowedCustomerRoleIds       = SqlParameterHelper.GetStringParameter("AllowedCustomerRoleIds", string.Empty);
            var pPageIndex                    = SqlParameterHelper.GetInt32Parameter("PageIndex", pageIndex);
            var pPageSize                     = SqlParameterHelper.GetInt32Parameter("PageSize", pageSize);
            var pShowHidden                   = SqlParameterHelper.GetBooleanParameter("ShowHidden", showHidden);
            var pOverridePublished            = SqlParameterHelper.GetBooleanParameter("OverridePublished", overridePublished);
            var pLoadFilterableSpecificationAttributeOptionIds = SqlParameterHelper.GetBooleanParameter("LoadFilterableSpecificationAttributeOptionIds", loadFilterableSpecificationAttributeOptionIds);

            //prepare output parameters
            var pFilterableSpecificationAttributeOptionIds = SqlParameterHelper.GetOutputStringParameter("FilterableSpecificationAttributeOptionIds");

            pFilterableSpecificationAttributeOptionIds.Size = int.MaxValue - 1;
            var pTotalRecords = SqlParameterHelper.GetOutputInt32Parameter("TotalRecords");

            //invoke stored procedure
            var products = _productRepository.EntityFromSql("ProductLoadAllPaged",
                                                            pCategoryIds,
                                                            pManufacturerId,
                                                            pStoreId,
                                                            pVendorId,
                                                            pWarehouseId,
                                                            pProductTypeId,
                                                            pVisibleIndividuallyOnly,
                                                            pMarkedAsNewOnly,
                                                            pProductTagId,
                                                            pFeaturedProducts,
                                                            pPriceMin,
                                                            pPriceMax,
                                                            pKeywords,
                                                            pSearchDescriptions,
                                                            pSearchManufacturerPartNumber,
                                                            pSearchSku,
                                                            pSearchProductTags,
                                                            pUseFullTextSearch,
                                                            pFullTextMode,
                                                            pFilteredSpecs,
                                                            pLanguageId,
                                                            pOrderBy,
                                                            pAllowedCustomerRoleIds,
                                                            pPageIndex,
                                                            pPageSize,
                                                            pShowHidden,
                                                            pOverridePublished,
                                                            pLoadFilterableSpecificationAttributeOptionIds,
                                                            pFilterableSpecificationAttributeOptionIds,
                                                            pTotalRecords).ToList();

            //get filterable specification attribute option identifier
            var filterableSpecificationAttributeOptionIdsStr =
                pFilterableSpecificationAttributeOptionIds.Value != DBNull.Value
                    ? (string)pFilterableSpecificationAttributeOptionIds.Value
                    : string.Empty;

            if (loadFilterableSpecificationAttributeOptionIds &&
                !string.IsNullOrWhiteSpace(filterableSpecificationAttributeOptionIdsStr))
            {
                filterableSpecificationAttributeOptionIds = filterableSpecificationAttributeOptionIdsStr
                                                            .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                                            .Select(x => Convert.ToInt32(x.Trim()))
                                                            .ToList();
            }
            //return products
            var totalRecords = pTotalRecords.Value != DBNull.Value ? Convert.ToInt32(pTotalRecords.Value) : 0;

            return(new PagedList <Product>(products, pageIndex, pageSize, totalRecords));
        }