forked from openstore-ecommerce/OpenStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductAjaxView.ascx.cs
295 lines (247 loc) · 11.8 KB
/
ProductAjaxView.ascx.cs
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// --- Copyright (c) notice NevoWeb ---
// Copyright (c) 2014 SARL NevoWeb. www.nevoweb.com. The MIT License (MIT).
// Author: D.C.Lee
// ------------------------------------------------------------------------
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// ------------------------------------------------------------------------
// This copyright notice may NOT be removed, obscured or modified without written consent from the author.
// --- End copyright notice ---
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using NBrightCore.common;
using NBrightDNN;
using NBrightDNN.render;
using Nevoweb.DNN.NBrightBuy.Base;
using Nevoweb.DNN.NBrightBuy.Components;
using Nevoweb.DNN.NBrightBuy.Components.Products;
namespace Nevoweb.DNN.NBrightBuy
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNBrightGen class displays the content
/// </summary>
/// -----------------------------------------------------------------------------
public partial class ProductAjaxView : NBrightBuyFrontOfficeBase
{
private String _eid = "";
private String _ename = "";
private String _catid = "";
private String _modkey = "";
private Boolean _displayentrypage = false;
private NavigationData _navigationdata;
public String EntityTypeCode = "PRD";
public String EntityTypeCodeLang = "PRDLANG";
private String _itemListName = "";
private String _print = "";
private String _printtemplate = "";
private String _guidkey = "";
private string _controlPath = "";
#region Event Handlers
override protected void OnInit(EventArgs e)
{
_eid = Utils.RequestQueryStringParam(Context, "eid");
_print = Utils.RequestParam(Context, "print");
_printtemplate = Utils.RequestParam(Context, "template");
_controlPath = ControlPath;
//SK this tells basepage not to inject the pager
EnablePaging = false;
base.OnInit(e);
// check if we're using a typcode for the data.
if (ModSettings != null)
{
// check if we're using a typcode for the data.
var modentitytypecode = ModSettings.Get("entitytypecode");
if (modentitytypecode != "")
{
EntityTypeCode = modentitytypecode;
EntityTypeCodeLang = modentitytypecode + "LANG";
}
// check if we're using a provider _controlPath for the templates.
var provider_controlPath = ModSettings.Get("provider_controlPath");
if (provider_controlPath != "")
{
_controlPath = "/DesktopModules/NBright/" + provider_controlPath + "/";
}
}
// if guidkey entered instead of eid, find it using the guid and assign to _eid
_guidkey = Utils.RequestQueryStringParam(Context, "guidkey");
if (_guidkey == "") _guidkey = Utils.RequestQueryStringParam(Context, "ref");
if (_eid== "" && _guidkey != "")
{
var guidData = ModCtrl.GetByGuidKey(PortalId, -1, EntityTypeCode, _guidkey);
if (guidData != null)
_eid = guidData.ItemID.ToString("D");
else
_eid = "0";
}
// if we want to print we need to open the browser with a startup script, this points to a Printview.aspx. (Must go after the ModSettings has been init.)
if (_print != "") Page.ClientScript.RegisterStartupScript(this.GetType(), "printproduct", "window.open('" + StoreSettings.NBrightBuyPath() + "/PrintView.aspx?itemid=" + _eid + "&printcode=" + _print + "&template=" + _printtemplate + "&theme=" + ModSettings.Get("themefolder") + "','_blank');", true);
if (ModuleKey == "") // if we don't have module setting jump out
{
var lit = new Literal();
lit.Text = "NO MODULE SETTINGS";
phData.Controls.Add(lit);
return;
}
_navigationdata = new NavigationData(PortalId, ModuleKey);
// Pass in a template specifying the token to create a friendly url for paging.
// (NOTE: we need this in NBS becuase the edit product from list return url will copy the page number and hence paging will not work after editing if we don;t do this)
//CtrlPaging.HrefLinkTemplate = "[<tag type='valueof' databind='PreText' />][<tag type='if' databind='Text' testvalue='' display='{OFF}' />][<tag type='hrefpagelink' moduleid='" + ModuleId.ToString("") + "' />][<tag type='endif' />][<tag type='valueof' databind='PostText' />]";
//CtrlPaging.UseListDisplay = true;
try
{
_catid = Utils.RequestQueryStringParam(Context, "catid");
#region "set templates based on entry id (eid) from url"
_ename = Utils.RequestQueryStringParam(Context, "entry");
_modkey = Utils.RequestQueryStringParam(Context, "modkey");
// see if we need to display the entry page.
if ((_modkey == ModuleKey | _modkey == "") && (_eid != "" | _ename != "")) _displayentrypage = true;
// if we have entry detail display, but no catd, get the default one.
if (_displayentrypage && _catid == "" && Utils.IsNumeric(_eid))
{
var prdData = ProductUtils.GetProductData(Convert.ToInt32(_eid),Utils.GetCurrentCulture(), true, EntityTypeCode);
var defcat = prdData.GetDefaultCategory();
if (defcat != null) _catid = defcat.categoryid.ToString("");
}
if (ModSettings.Get("listonly").ToLower() == "true") _displayentrypage = false;
// get template codes
if (_displayentrypage)
{
RazorTemplate = ModSettings.Get("razordetailtemplate");
}
else
{
RazorTemplate = ModSettings.Get("razortemplate");
}
#endregion
}
catch (Exception exc)
{
// remove any cookie which might store SQL in error.
_navigationdata.Delete();
DisplayProductError(null, exc.ToString());
}
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (Page.IsPostBack == false)
{
// do razor code
RazorPageLoad();
}
}
catch (Exception exc) //Module failed to load
{
//display the error on the template (don;t want to log it here, prefer to deal with errors directly.)
var l = new Literal();
l.Text = exc.ToString();
phData.Controls.Add(l);
// remove any nav data which might store SQL in error.
_navigationdata.Delete();
}
}
private void RazorPageLoad()
{
NBrightInfo objCat = null;
if (RazorTemplate.Trim() != "") // if we don;t have a template, don't do anything
{
if (_displayentrypage)
{
// get correct itemid, based on eid given
_eid = GetEntryIdFromName(_eid);
RazorDisplayDataEntry(_eid);
}
else
{
// load base template which should call ajax and load the list.
var strOut = NBrightBuyUtils.RazorTemplRender(RazorTemplate, ModuleId, "productdetailrazor" + ModuleId, new NBrightInfo(true), _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
}
}
}
#endregion
#region "Methods"
private String GetEntryIdFromName(String entryId)
{
// get correct itemid, based on eid given
if (_ename != "")
{
var o = ModCtrl.GetByGuidKey(PortalId, ModuleId, EntityTypeCodeLang, _ename);
if (o == null)
{
o = ModCtrl.GetByGuidKey(PortalId, ModuleId, EntityTypeCode, _ename);
if (o != null)
{
entryId = o.ItemID.ToString("");
}
}
else
{
entryId = o.ParentItemId.ToString("");
}
}
return entryId;
}
private void RazorDisplayDataEntry(String entryId)
{
var productData = new ProductData();
if (Utils.IsNumeric(entryId))
{
productData = ProductUtils.GetProductData(Convert.ToInt32(entryId), Utils.GetCurrentCulture(), true, EntityTypeCode);
}
if (productData.Exists)
{
if (PortalSettings.HomeTabId == TabId)
PageIncludes.IncludeCanonicalLink(Page, Globals.AddHTTP(PortalSettings.PortalAlias.HTTPAlias)); //home page always default of site.
else
PageIncludes.IncludeCanonicalLink(Page, NBrightBuyUtils.GetEntryUrl(PortalId, _eid, "", productData.SEOName, TabId.ToString("")));
// overwrite SEO data
if (productData.SEOName != "")
BasePage.Title = productData.SEOTitle;
else
BasePage.Title = productData.ProductName;
if (productData.SEODescription != "") BasePage.Description = productData.SEODescription;
// if debug , output the xml used.
if (DebugMode) productData.Info.XMLDoc.Save(PortalSettings.HomeDirectoryMapPath + "debug_entry.xml");
#region "do razor template"
var strOut = NBrightBuyUtils.RazorTemplRender(RazorTemplate, ModuleId, "productdetailrazor" + ModuleId.ToString() + "*" + entryId, productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
#endregion
}
else
{
DisplayProductError(productData, "");
}
}
private void DisplayProductError(ProductData productData,String msg)
{
var strOut = msg;
if (productData != null)
{
strOut = NBrightBuyUtils.RazorTemplRender("ProductNotFound.cshtml", ModuleId, "", productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
}
var lit = new Literal();
lit.Text = strOut;
phData.Controls.Add(lit);
if (StoreSettings.Current.SettingsInfo.GetXmlPropertyBool("genxml/checkbox/activate404"))
{
Response.StatusCode = 404;
}
}
#endregion
}
}