-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path02.01.06.SqlDataProvider
207 lines (170 loc) · 7.39 KB
/
02.01.06.SqlDataProvider
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/************************************************************/
/***** SqlDataProvider *****/
/***** *****/
/***** *****/
/***** Note: To manually execute this script you must *****/
/***** perform a search and replace operation *****/
/***** for {databaseOwner} and {objectQualifier} *****/
/***** *****/
/***** *****/
/***** *****/
/************************************************************/
/************************************************************/
/***** TABLE Start *****/
/************************************************************/
/************************************************************/
/***** SPROC Start *****/
/************************************************************/
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}NEvoweb_NB_Store_Products_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}[{objectQualifier}NEvoweb_NB_Store_Products_GetList]
GO
/*
Author: DCL
Last Modified for NB_Store version: 02.01.06
*/
CREATE PROCEDURE {databaseOwner}[{objectQualifier}NEvoweb_NB_Store_Products_GetList]
@PortalID int,
@CategoryID int,
@Lang char(5),
@Filter nvarchar(50),
@GetArchived bit,
@FeaturedOnly bit,
@OrderBy nvarchar(50),
@OrderDESC bit,
@ReturnLimit nvarchar(5),
@PageIndex int,
@PageSize int,
@SearchDescription bit,
@IsDealer bit ,
@CategoryList nvarchar(1000),
@ExcludeFeatured bit
AS
begin
declare @SQL nvarchar(4000)
set @SQL = ' SELECT '
if @ReturnLimit > 0
begin
set @SQL = @SQL + ' top ' + @ReturnLimit
end
set @SQL = @SQL + ' row,ProductID,PortalID,TaxCategoryID,Featured,Archived,CreatedByUser,CreatedDate,IsDeleted,ProductRef,Lang,Summary,[Description],Manufacturer,FromPrice,QtyRemaining,QtyStockSet,ImageID,ImageURL,ImageDesc,ProductName,[XMLData],SEOName,TagWords,IsHidden '
set @SQL = @SQL + ' FROM '
set @SQL = @SQL + ' (select ROW_NUMBER() OVER ('
if @OrderBy='man'
begin
if @OrderDESC=1
set @SQL = @SQL + ' order by PL.Manufacturer DESC,P.ProductRef DESC'
else
set @SQL = @SQL + ' order by PL.Manufacturer,P.ProductRef'
end
if @OrderBy='ref'
begin
if @OrderDESC=1
set @SQL = @SQL + ' order by P.ProductRef DESC,PL.Manufacturer DESC'
else
set @SQL = @SQL + ' order by P.ProductRef,PL.Manufacturer'
end
if @OrderBy='name'
begin
if @OrderDESC=1
set @SQL = @SQL + ' order by PL.ProductName DESC,PL.Manufacturer DESC'
else
set @SQL = @SQL + ' order by PL.ProductName,PL.Manufacturer'
end
if @OrderBy='price'
begin
if @OrderDESC=1
set @SQL = @SQL + ' order by {databaseOwner}{objectQualifier}NEvoWeb_NB_Store_FGetProductBasePrice(P.ProductID) DESC,PL.Manufacturer DESC,P.ProductRef DESC'
else
set @SQL = @SQL + ' order by {databaseOwner}{objectQualifier}NEvoWeb_NB_Store_FGetProductBasePrice(P.ProductID),PL.Manufacturer,P.ProductRef'
end
if @OrderBy='cdate'
begin
if @OrderDESC=1
set @SQL = @SQL + ' order by P.CreatedDate DESC'
else
set @SQL = @SQL + ' order by P.CreatedDate'
end
if @OrderBy=''
begin
set @SQL = @SQL + ' order by PL.Manufacturer,P.ProductRef'
end
set @SQL = @SQL + ') AS row, '
set @SQL = @SQL + ' P.ProductID,'
set @SQL = @SQL + ' PortalID,'
set @SQL = @SQL + ' P.TaxCategoryID,'
set @SQL = @SQL + ' Featured,'
set @SQL = @SQL + ' Archived,'
set @SQL = @SQL + ' CreatedByUser,'
set @SQL = @SQL + ' CreatedDate,'
set @SQL = @SQL + ' ModifiedDate,'
set @SQL = @SQL + ' IsDeleted,'
set @SQL = @SQL + ' ProductRef,'
set @SQL = @SQL + ' Lang,'
set @SQL = @SQL + ' Summary,'
set @SQL = @SQL + ' Description,'
set @SQL = @SQL + ' Manufacturer,'
set @SQL = @SQL + ' {databaseOwner}{objectQualifier}NEvoWeb_NB_Store_FGetProductBasePrice(P.ProductID) as FromPrice,'
set @SQL = @SQL + ' isnull((select sum(QtyRemaining) from {databaseOwner}{objectQualifier}NB_Store_Model where productid = P.ProductID and qtyremaining != 0),0) as QtyRemaining,'
set @SQL = @SQL + ' isnull((select sum(QtyStockSet) from {databaseOwner}{objectQualifier}NB_Store_Model where productid = P.ProductID),0) as QtyStockSet,'
set @SQL = @SQL + ' (select top 1 ImageID from {databaseOwner}{objectQualifier}NB_Store_ProductImage AS I where productid = P.ProductID order by listorder) as ImageID,'
set @SQL = @SQL + ' (select top 1 ImageURL from {databaseOwner}{objectQualifier}NB_Store_ProductImage AS I where productid = P.ProductID order by listorder) as ImageURL,'
set @SQL = @SQL + ' (select top 1 ImageDesc from {databaseOwner}{objectQualifier}NB_Store_ProductImage AS I inner join {databaseOwner}{objectQualifier}NB_Store_ProductImageLang as IL on IL.ImageID = I.ImageID and IL.Lang = PL.Lang where productid = P.ProductID order by listorder) as ImageDesc,'
set @SQL = @SQL + ' PL.ProductName,'
set @SQL = @SQL + ' PL.[XMLData], SEOName, TagWords, IsHidden '
set @SQL = @SQL + ' from {databaseOwner}[{objectQualifier}NB_Store_Products] as P'
set @SQL = @SQL + ' inner join {databaseOwner}{objectQualifier}NB_Store_ProductLang as PL on P.ProductID = PL.ProductID and PL.Lang = ''' + @Lang + ''''
if (@CategoryID > 0 and @Filter = '')
begin
set @SQL = @SQL + ' inner join {databaseOwner}{objectQualifier}NB_Store_ProductCategory as PC on PC.ProductID = P.ProductID '
end
set @SQL = @SQL + ' where P.PortalID = ' + convert(nvarchar(5),@PortalID)
if @IsDealer=0
begin
set @SQL = @SQL + ' and P.ProductID in (select M.ProductID from {databaseOwner}{objectQualifier}NB_Store_Model as M where M.ProductID = P.ProductID and DealerOnly = 0) '
end
if @FeaturedOnly = 1
begin
set @SQL = @SQL + ' and P.Featured = 1 '
end
if @ExcludeFeatured = 1
begin
set @SQL = @SQL + ' and P.Featured != 1 '
end
if @GetArchived = 0
begin
set @SQL = @SQL + ' and not P.IsDeleted = 1 and not P.Archived = 1 and not P.IsHidden = 1'
end
if (@CategoryID >= 0 and @CategoryList = '' and @Filter = '')
begin
set @SQL = @SQL + ' and PC.CategoryID = ' + convert(nvarchar(5),@CategoryID)
end
if (@CategoryID >= 0 and @CategoryList != '' and @Filter = '')
begin
set @SQL = @SQL + ' and PC.CategoryID in (' + convert(nvarchar(1000),@CategoryList) + ')'
end
if @Filter != ''
begin
set @SQL = @SQL + ' and (PL.ProductName like ''%' + @Filter + '%'' or P.ProductRef like ''%' + @Filter + '%'' or PL.Summary like ''%' + @Filter + '%'' or PL.Manufacturer like ''%' + @Filter + '%'' or PL.TagWords like ''%' + @Filter + '%'' '
if @SearchDescription = 1
begin
set @SQL = @SQL + ' or PL.Description like ''%' + @Filter + '%'' '
end
set @SQL = @SQL + ')'
end
set @SQL = @SQL + ') AS NB_Store_ProductsPage '
if @PageSize > 0
begin
set @SQL = @SQL + ' WHERE Row between ((' + convert(nvarchar(5),(@PageIndex - 1)) + ' * ' + convert(nvarchar(5),@PageSize) + ') + 1) and ' + convert(nvarchar(5),(@PageIndex*@PageSize))
end
exec sp_executesql @SQL
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
/************************************************************/