v1.9 need to add small product image to Recently Viewed Products

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
v1.9 need to add small product image to Recently Viewed Products

Any help will be appreciated.

I see this is how it is getting the Product Name.

RecentlyViewedProductsBox.ascx line:18

<asp:HyperLink ID="hlProduct" runat="server" Text='<%#Server.HtmlEncode(Eval("LocalizedName").ToString()) %>' />

Please help. Thanks
12 лет назад
Hi vasa

here is the code

in RecentlyViewedProductsBox.ascx add

<asp:Image ID="imProductImage" runat="server"/>


like so

<%@ Control Language="C#" AutoEventWireup="true"
    Inherits="NopSolutions.NopCommerce.Web.Modules.RecentlyViewedProductsBoxControl" Codebehind="RecentlyViewedProductsBox.ascx.cs" %>
<div class="block block-recently-viewed-products">
    <div class="title">
        <%=GetLocaleResourceString("Products.RecentlyViewedProducts")%>
    </div>
    <div class="clear">
    </div>
    <div class="listbox">
        <asp:ListView ID="lvRecentlyViewedProducts" runat="server" OnItemDataBound="lvRecentlyViewedProducts_ItemDataBound" EnableViewState="false">
            <LayoutTemplate>
                <ul>
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                </ul>
            </LayoutTemplate>
            <ItemTemplate>
                <li>
                    <asp:Image ID="imProductImage" runat="server"/>
                    <asp:HyperLink ID="hlProduct" runat="server" Text='<%#Server.HtmlEncode(Eval("LocalizedName").ToString()) %>' />
                </li>
            </ItemTemplate>
            <ItemSeparatorTemplate>
                <li class="separator">
                    &nbsp;
                </li>
            </ItemSeparatorTemplate>
        </asp:ListView>
    </div>
</div>


in the code behind file RecentlyViewedProductsBox.ascx.cs add the following code in lvRecentlyViewedProducts_ItemDataBound

// DMB 19/04/2012 added picture thumb  
Image imProductImage = dataItem.FindControl("imProductImage") as Image;
if (imProductImage != null)
{
    var picture = product.DefaultPicture;
    if (picture != null)
    {
         imProductImage.ImageUrl = this.PictureService.GetPictureUrl(picture, 70, true);
         imProductImage.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
     }
     else
     {
           imProductImage.ImageUrl = this.PictureService.GetDefaultPictureUrl(70);
           imProductImage.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
      }
}


like this

protected void lvRecentlyViewedProducts_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                var dataItem = e.Item as ListViewDataItem;
                if (dataItem != null)
                {
                    var product = dataItem.DataItem as Product;
                    if (product != null)
                    {
                        var hlProduct = dataItem.FindControl("hlProduct") as HyperLink;
                        hlProduct.NavigateUrl = SEOHelper.GetProductUrl(product);

                        // DMB 19/04/2012 added picture thumb  
                        Image imProductImage = dataItem.FindControl("imProductImage") as Image;
                        if (imProductImage != null)
                        {
                            var picture = product.DefaultPicture;
                            if (picture != null)
                            {
                                imProductImage.ImageUrl = this.PictureService.GetPictureUrl(picture, 70, true);
                                imProductImage.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                            }
                            else
                            {
                                imProductImage.ImageUrl = this.PictureService.GetDefaultPictureUrl(70);
                                imProductImage.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                            }
                        }
                    }
                }
            }
        }


HTH

Dave
12 лет назад
thank you.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.