Skip to content

Commit 0ccbbab

Browse files
committed
v4.0.1.2 - Allow optional activation of 404 when product missing
1 parent 285ba29 commit 0ccbbab

File tree

6 files changed

+270
-288
lines changed

6 files changed

+270
-288
lines changed

App_LocalResources/Settings.ascx.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,4 +519,10 @@
519519
<data name="cartmessages.Text" xml:space="preserve">
520520
<value>Cart Messages</value>
521521
</data>
522+
<data name="activate404.Text" xml:space="preserve">
523+
<value>Activate product 404</value>
524+
</data>
525+
<data name="activate404msg.Text" xml:space="preserve">
526+
<value>Activate a 404 status respsone for any product url which is no longer found in the system. </value>
527+
</data>
522528
</root>
-886 Bytes
Binary file not shown.

ProductAjaxView.ascx.cs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,10 @@ public partial class ProductAjaxView : NBrightBuyFrontOfficeBase
4646
private String _print = "";
4747
private String _printtemplate = "";
4848
private String _guidkey = "";
49-
private Boolean _404code = false;
5049
private string _controlPath = "";
5150

5251
#region Event Handlers
5352

54-
protected override void Render(HtmlTextWriter writer)
55-
{
56-
base.Render(writer);
57-
if (_404code)
58-
{
59-
// Commented out becuase this can give a page not found error page on IIS, depending on settings.
60-
// Response.StatusCode = 404;
61-
}
62-
}
63-
6453
override protected void OnInit(EventArgs e)
6554
{
6655
_eid = Utils.RequestQueryStringParam(Context, "eid");
@@ -159,7 +148,7 @@ override protected void OnInit(EventArgs e)
159148
{
160149
// remove any cookie which might store SQL in error.
161150
_navigationdata.Delete();
162-
DisplayProductError(exc.ToString());
151+
DisplayProductError(null, exc.ToString());
163152
}
164153

165154
}
@@ -276,28 +265,25 @@ private void RazorDisplayDataEntry(String entryId)
276265
}
277266
else
278267
{
279-
_404code = true;
280-
var strOut = NBrightBuyUtils.RazorTemplRender("ProductNotFound.cshtml", ModuleId, "", productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
281-
var lit = new Literal();
282-
lit.Text = strOut;
283-
phData.Controls.Add(lit);
284-
268+
DisplayProductError(productData, "");
285269
}
286270

287271
}
288272

289-
private void DisplayProductError(String msg)
273+
private void DisplayProductError(ProductData productData,String msg)
290274
{
291-
//display the error if superuser (don;t want to log it.)
292-
var errmsg = ModCtrl.GetTemplateData(ModSettings, "productunavailable.html", Utils.GetCurrentCulture(), DebugMode);
293-
if (UserInfo.IsSuperUser) errmsg += msg;
294-
var obj = new NBrightInfo(true);
295-
var razorTemplateKey = "NBrightBuyRazorKey*productunavailable" + PortalId.ToString() + "*" + Utils.GetCurrentCulture();
296-
errmsg = RazorUtils.RazorRender(obj, errmsg, razorTemplateKey, StoreSettings.Current.DebugMode);
297-
var l = new Literal();
298-
l.Text = errmsg;
299-
phData.Controls.Add(l);
300-
//Response.StatusCode = 404; //causes 404 page on live site???
275+
var strOut = msg;
276+
if (productData != null)
277+
{
278+
strOut = NBrightBuyUtils.RazorTemplRender("ProductNotFound.cshtml", ModuleId, "", productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
279+
}
280+
var lit = new Literal();
281+
lit.Text = strOut;
282+
phData.Controls.Add(lit);
283+
if (StoreSettings.Current.SettingsInfo.GetXmlPropertyBool("genxml/checkbox/activate404"))
284+
{
285+
Response.StatusCode = 404;
286+
}
301287
}
302288

303289
#endregion

ProductRazorView.ascx.cs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,10 @@ public partial class ProductRazorView : NBrightBuyFrontOfficeBase
6262
private String _print = "";
6363
private String _printtemplate = "";
6464
private String _guidkey = "";
65-
private Boolean _404code = false;
6665
private string _controlPath = "";
6766

6867
#region Event Handlers
6968

70-
protected override void Render(HtmlTextWriter writer)
71-
{
72-
base.Render(writer);
73-
if (_404code)
74-
{
75-
// Commented out becuase this can give a page not found error page on IIS, depending on settings.
76-
// Response.StatusCode = 404;
77-
}
78-
}
79-
8069
override protected void OnInit(EventArgs e)
8170
{
8271
_eid = Utils.RequestQueryStringParam(Context, "eid");
@@ -185,7 +174,7 @@ override protected void OnInit(EventArgs e)
185174
{
186175
// remove any cookie which might store SQL in error.
187176
_navigationdata.Delete();
188-
DisplayProductError(exc.ToString());
177+
DisplayProductError(null, exc.ToString());
189178
}
190179

191180
}
@@ -687,32 +676,25 @@ private void RazorDisplayDataEntry(String entryId)
687676
}
688677
else
689678
{
690-
_404code = true;
691-
692-
// insert page header text
693-
NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, "ProductNotFound_head.cshtml", _controlPath, ModSettings.ThemeFolder, ModSettings.Settings(), productData);
694-
695-
var strOut = NBrightBuyUtils.RazorTemplRender("ProductNotFound.cshtml", ModuleId, "", productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
696-
var lit = new Literal();
697-
lit.Text = strOut;
698-
phData.Controls.Add(lit);
699-
679+
DisplayProductError(productData, "");
700680
}
701681

702682
}
703683

704-
private void DisplayProductError(String msg)
684+
private void DisplayProductError(ProductData productData, String msg)
705685
{
706-
//display the error if superuser (don;t want to log it.)
707-
var errmsg = ModCtrl.GetTemplateData(ModSettings, "productunavailable.html", Utils.GetCurrentCulture(), DebugMode);
708-
if (UserInfo.IsSuperUser) errmsg += msg;
709-
var obj = new NBrightInfo(true);
710-
var razorTemplateKey = "NBrightBuyRazorKey*productunavailable" + PortalId.ToString() + "*" + Utils.GetCurrentCulture();
711-
errmsg = RazorUtils.RazorRender(obj, errmsg, razorTemplateKey, StoreSettings.Current.DebugMode);
712-
var l = new Literal();
713-
l.Text = errmsg;
714-
phData.Controls.Add(l);
715-
//Response.StatusCode = 404; //causes 404 page on live site???
686+
var strOut = msg;
687+
if (productData != null)
688+
{
689+
strOut = NBrightBuyUtils.RazorTemplRender("ProductNotFound.cshtml", ModuleId, "", productData, _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
690+
}
691+
var lit = new Literal();
692+
lit.Text = strOut;
693+
phData.Controls.Add(lit);
694+
if (StoreSettings.Current.SettingsInfo.GetXmlPropertyBool("genxml/checkbox/activate404"))
695+
{
696+
Response.StatusCode = 404;
697+
}
716698
}
717699

718700
#endregion

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("4.0.1.1")]
36-
[assembly: AssemblyFileVersion("4.0.1.1")]
35+
[assembly: AssemblyVersion("4.0.1.2")]
36+
[assembly: AssemblyFileVersion("4.0.1.2")]

0 commit comments

Comments
 (0)