No source...no worries
You can do this with a custom extension class in the App_Code directory and a couple small changes to the xmlpackage and web.config file.
App_Code/CustomExtensions.cs
Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using AspDotNetStorefrontCore;
/// <summary>
/// Summary description for CustomExtensions
/// </summary>
///
namespace mycustomextensions
{
public class CustomExtensions
{
public string EntityPageRatings(String sProductID)
{
InputValidator IV = new InputValidator("EntityPageRatings");
int ProductID = IV.ValidateInt("ProductID", sProductID);
StringBuilder RatingHTML = new StringBuilder();
// Make sure there are ratings to display
int NumberOfRatings = DB.GetSqlN("select count(*) as N from Rating where IsFilthy = 0 and ProductID = " + ProductID.ToString());
if (NumberOfRatings > 0)
{
//We have ratings, so lets build the html
int RatingSum = DB.GetSqlN("select SUM(rating) as N from Rating where IsFilthy = 0 and ProductID =" + ProductID.ToString());
int i = 1;
decimal AvgRating = 0.00M;
//Calculate the Average rating here, as SQL AVG function handles data types inconsistently
if (RatingSum > 0)
{
//DON'T DIVIDE BY ZERO!
AvgRating = (Convert.ToDecimal(RatingSum) / Convert.ToDecimal(NumberOfRatings));
}
//First build the "whole" stars
while (i <= AvgRating)
{
RatingHTML.Append("<img src=\"./images/starf.gif\" />");
i++;
}
//Now add a partial star in case the average is something like 3.5
if (AvgRating > (i - 1))
{
RatingHTML.Append("<img src=\"./images/starh.gif\" />");
i++;
}
//Add the "empty" stars
while (i <= 5)
{
RatingHTML.Append("<img src=\"./images/stare.gif\" />");
i++;
}
//Finally, represent the rating with text as well
RatingHTML.Append("<br/><span class=\"AvgRatingText\">Average Customer Rating:<br/>" + AvgRating.ToString() + " out of 5</span>");
}
else
{
//Just display a message stating that the product has not been reviewed
RatingHTML.Append("<span class=\"NoRatingsText\">No Reviews</span>");
}
return RatingHTML.ToString();
}
}
}
web.config (new code is red code)
Code:
<!-- Add your own custom XSLTExtensionObjects here -->
<xsltobjects defaultExtension="">
<extensions>
<clear />
<add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code"></add>
<add name="customextensions" type="mycustomextensions.CustomExtensions" namespace="urn:CustomExtensions" />
</extensions>
</xsltobjects>
entity.grid.xml.config (new code is red code)
Code:
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aspdnsf="urn:aspdnsf"
xmlns:CustomExtensions="urn:CustomExtensions"
exclude-result-prefixes="aspdnsf CustomExtensions">
Code:
<xsl:if test="aspdnsf:AppConfigBool('RatingsEnabled') = 'true'">
<tr>
<td height="45" align="center" valign="top">
<xsl:value-of select="CustomExtensions:EntityPageRatings(ProductID)" disable-output-escaping="yes" />
</td>
</tr>
</xsl:if>