+
+ --show hidden
+ IF @ShowHidden = 0
+ BEGIN
+ SET @sql = @sql + '
+ AND p.Deleted = 0
+ AND (getutcdate() BETWEEN ISNULL(p.AvailableStartDateTimeUtc, ''1/1/1900'') and ISNULL(p.AvailableEndDateTimeUtc, ''1/1/2999''))'
+ END
+
+ --min price
+ IF @PriceMin is not null
+ BEGIN
+ SET @sql = @sql + '
+ AND (
+ (
+ --special price (specified price and valid date range)
+ (p.SpecialPrice IS NOT NULL AND (getutcdate() BETWEEN isnull(p.SpecialPriceStartDateTimeUtc, ''1/1/1900'') AND isnull(p.SpecialPriceEndDateTimeUtc, ''1/1/2999'')))
+ AND
+ (p.SpecialPrice >= ' + CAST(@PriceMin AS nvarchar(max)) + ')
+ )
+ OR
+ (
+ --regular price (price isnt specified or date range isnt valid)
+ (p.SpecialPrice IS NULL OR (getutcdate() NOT BETWEEN isnull(p.SpecialPriceStartDateTimeUtc, ''1/1/1900'') AND isnull(p.SpecialPriceEndDateTimeUtc, ''1/1/2999'')))
+ AND
+ (p.Price >= ' + CAST(@PriceMin AS nvarchar(max)) + ')
+ )
+ )'
+ END
+
+ --max price
+ IF @PriceMax is not null
+ BEGIN
+ SET @sql = @sql + '
+ AND (
+ (
+ --special price (specified price and valid date range)
+ (p.SpecialPrice IS NOT NULL AND (getutcdate() BETWEEN isnull(p.SpecialPriceStartDateTimeUtc, ''1/1/1900'') AND isnull(p.SpecialPriceEndDateTimeUtc, ''1/1/2999'')))
+ AND
+ (p.SpecialPrice <= ' + CAST(@PriceMax AS nvarchar(max)) + ')
+ )
+ OR
+ (
+ --regular price (price isnt specified or date range isnt valid)
+ (p.SpecialPrice IS NULL OR (getutcdate() NOT BETWEEN isnull(p.SpecialPriceStartDateTimeUtc, ''1/1/1900'') AND isnull(p.SpecialPriceEndDateTimeUtc, ''1/1/2999'')))
+ AND
+ (p.Price <= ' + CAST(@PriceMax AS nvarchar(max)) + ')
+ )
+ )'
+ END
+
+ --show hidden and ACL
+ IF @ShowHidden = 0
+ BEGIN
+ SET @sql = @sql + '
+ AND (p.SubjectToAcl = 0 OR EXISTS (
+ SELECT 1 FROM #FilteredCustomerRoleIds [fcr]
+ WHERE
+ [fcr].CustomerRoleId IN (
+ SELECT [acl].CustomerRoleId
+ FROM [AclRecord] acl with (NOLOCK)
+ WHERE [acl].EntityId = p.Id AND [acl].EntityName = ''Product''
+ )
+ ))'
+ END
+
+ --show hidden and filter by store
+ IF @StoreId > 0
+ BEGIN
+ SET @sql = @sql + '
+ AND (p.LimitedToStores = 0 OR EXISTS (
+ SELECT 1 FROM [StoreMapping] sm with (NOLOCK)
+ WHERE [sm].EntityId = p.Id AND [sm].EntityName = ''Product'' and [sm].StoreId=' + CAST(@StoreId AS nvarchar(max)) + '
+ ))'
+ END
+
+ --filter by specification attribution options
+ SET @FilteredSpecs = isnull(@FilteredSpecs, '')
+ CREATE TABLE #FilteredSpecs
+ (
+ SpecificationAttributeOptionId int not null
+ )
+ INSERT INTO #FilteredSpecs (SpecificationAttributeOptionId)
+ SELECT CAST(data as int) FROM [nop_splitstring_to_table](@FilteredSpecs, ',')
+ DECLARE @SpecAttributesCount int
+ SET @SpecAttributesCount = (SELECT COUNT(1) FROM #FilteredSpecs)
+ IF @SpecAttributesCount > 0
+ BEGIN
+ --do it for each specified specification option
+ DECLARE @SpecificationAttributeOptionId int
+ DECLARE cur_SpecificationAttributeOption CURSOR FOR
+ SELECT [SpecificationAttributeOptionId]
+ FROM [#FilteredSpecs]
+ OPEN cur_SpecificationAttributeOption
+ FETCH NEXT FROM cur_SpecificationAttributeOption INTO @SpecificationAttributeOptionId
+ WHILE @@FETCH_STATUS = 0
+ BEGIN
+ SET @sql = @sql + '
+ AND p.Id in (select psam.ProductId from [Product_SpecificationAttribute_Mapping] psam with (NOLOCK) where psam.AllowFiltering = 1 and psam.SpecificationAttributeOptionId = ' + CAST(@SpecificationAttributeOptionId AS nvarchar(max)) + ')'
+ --fetch next identifier
+ FETCH NEXT FROM cur_SpecificationAttributeOption INTO @SpecificationAttributeOptionId
+ END
+ CLOSE cur_SpecificationAttributeOption
+ DEALLOCATE cur_SpecificationAttributeOption
+ END
2
اگر پاسخ سوالی برای شما مفید بود، به آن رای مثبت دهید تا به دیگران در پیدا کردن پاسخ مناسب کمک کنید
*******************************************************************************************
Be Who You Always Wanted To Be
*******************************************************************************************
Be Who You Always Wanted To Be