Resolved: Moving/displaying the star ratings on other page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Ok, after hours of trying this I can not get the star rating to display on another page. I am trying to include the star rating in the ProductBox2.ascx layout which is part of the ProductsInLine1.ascx, as in ProductBox2.ascx is called as a module from ProductsInLine1.ascx.

I have included the following in the page ProductBox2.ascx;

    <%@ Register TagPrefix="nopCommerce" TagName="ProductRating" Src="~/Modules/ProductRating.ascx" %>

and set up a new div in the page to call the control;

    <div class="ratings">
            <nopCommerce:ProductRating ID="ctrlProductRating" runat="server" />
    </div>

The project compiles without errors, but the star rating is not displayed.

Thanks,

James.
13 年 前
Hi,

I *THINK* you need to pass the product or variant ID to the user control in the aspx/ascx container so it knows which product the rating is for.

So onload or prerender needs something like UserControl.ProductID = product.ProductID where product is the product that the page is showing.

HTH.
13 年 前
Thanks for your reply. What you have suggested is the road I have been trying to go down, but I am not very good at programming and can't seem to get it to work. I am looking at the OneVariant.ascx.cs. It seems that the code below is part of what sets up the rating system, but I get stuck with multiple errors when I recompile if I try to "copy" this code across to the ProductBox2.ascx.cs file.

        protected void BindData()
        {
            var product = ProductManager.GetProductById(this.ProductId);
            if(product == null || product.ProductVariants.Count == 0)
            {
                Response.Redirect(CommonHelper.GetStoreLocation());
            }
            ctrlProductRating.Visible = product.AllowCustomerRatings;
            BindProductVariantInfo(ProductVariant);
            BindProductInfo(product);
        }

It seems you need to have the following to get the product id;

public int ProductId
        {
            get
            {
                return CommonHelper.QueryStringInt("ProductId");
            }
        }

Anyone any further suggestions?

Thanks,

James.
13 年 前
As you noticed, you need to pass the ProductId to the ProductRating control. This can be done using a viewstate value with the following changes:

1. Change the ProductId property in the ProductRating control (fie: Modules\ProductRating.ascx.cs) from:
public int ProductId
{
    get
    {
        return CommonHelper.QueryStringInt("ProductId");
    }
}

to the following:
public int ProductId
{
    get
    {
        int productId = 0;
        productId = CommonHelper.QueryStringInt("ProductId");

        if (productId == 0 && this.ViewState["ProductId"] != null)
        {                    
            productId = (Int32)this.ViewState["ProductId"];
        }
        return productId;
    }
    set
    {
        this.ViewState["ProductId"] = value;
    }
}

2. Add the ProductId to the ProductRating tag you already added to ProductBox2 (new code underlined).
<div class="ratings">
  <nopCommerce:ProductRating ID="ctrlProductRating" runat="server" ProductId='<%# Eval("ProductId") %>' />
</div>

3. Add a script manager to the ProudctsInLines1 (Templates\Categories\ProductsInLines1.ascx) category template and the Search (Modules\Search.ascx) control (Search uses ProductBox2 to display results).
<ajaxToolkit:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
    EnableScriptLocalization="true" ID="sm1" ScriptMode="Release" CompositeScript-ScriptMode="Release" />

4. Recompile the project.

.
13 年 前
Thanks you so much!!! That worked a treat :) I had been looking at this for hours.

Cheers,

James.
13 年 前
Do this trick work in Detail Page , too?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.