Product Rating without review

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
dappy2
Commander (CMDR)
Commander (CMDR)
Posts: 114
Joined: Wed Jan 18, 2006 5:53 pm
Contact:

Product Rating without review

Post by dappy2 » Thu Sep 16, 2010 1:11 pm

Is it possible to create a control that could just let people rate the products? I know most of the code looks for a review profile, but I think it would be good to allow people to rate products quickly without submitting a review.

I went through the ProductReviewForm and copied/pasted the parts that seemed relevant but I'm getting Object reference not set errors on the button click. The page loads and displays fine.

The display code is just the copied drop-down list from the ReviewForm.

This is what I have in code-behind:

Code: Select all

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 CommerceBuilder.Common;
using CommerceBuilder.Products;
using CommerceBuilder.Stores;
using CommerceBuilder.Users;
using CommerceBuilder.Utility;
public partial class ConLib_Custom_OnlyProductRating : System.Web.UI.UserControl
{
     public event EventHandler ReviewCancelled;
     public event EventHandler ReviewSubmitted;
     private int _ProductId;
     private int _ProductReviewId;
     private ProductReview _ProductReview;
     private Product _Product;

     protected bool FormInitialized
     {
          get { return AlwaysConvert.ToBool(ViewState["FormInitialized"], false); }
          set { ViewState["FormInitialized"] = value; }
     }

    protected void Page_Load(object sender, EventArgs e)
    {
         _ProductReviewId = AlwaysConvert.ToInt(Request.QueryString["ReviewId"]);
         _ProductReview = ProductReviewDataSource.Load(_ProductReviewId);

         if (_ProductReview != null) _ProductId = _ProductReview.ProductId;
         else _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
         _Product = ProductDataSource.Load(_ProductId);

         //if (!Page.IsPostBack) InitializeForm();

         //INIT ReviewBody COUNTDOWN
         //PageHelper.SetMaxLengthCountDown(ReviewBody, ReviewMessageCharCount);
         //ReviewMessageCharCount.Text = ((int)(ReviewBody.MaxLength - ReviewBody.Text.Length)).ToString();
    }
    protected void ratingBTN_Click(object sender, EventArgs e)
    {
         if (Page.IsValid)
         {
               HandleSubmitedReview();
         }
    }

    private void HandleSubmitedReview()
    {
         if (SaveReview())
         {
                   //THE REVIEW WILL APPEAR ON PAGE, NO NEED TO HAVE CONFIRMATION MESSAGE
                   this.FormInitialized = false;
                   if (ReviewSubmitted != null) ReviewSubmitted(this, new EventArgs());
         }
    }

    private bool SaveReview()
    {
              if (_ProductReview == null) _ProductReview = new ProductReview();
             // _ProductReview.ReviewerProfileId = _Profile.ReviewerProfileId;
              _ProductReview.ProductId = _ProductId;
              //_ProductReview.ReviewDate = LocaleHelper.LocalNow;
              _ProductReview.Rating = AlwaysConvert.ToByte(Rating.SelectedValue);
             // _ProductReview.ReviewTitle = StringHelper.StripHtml(ReviewTitle.Text, true);
             // _ProductReview.ReviewBody = StringHelper.StripHtml(ReviewBody.Text, true);
              _ProductReview.Save(Token.Instance.User, true, true);
              return true;
    }
}

Post Reply