Home page products including price (Nopcomrece 1.9)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
I did the show price  on the home page products but could not.
can you help me?

thank you.
13 年 前
Go to NopcommerceStore -> Modules:

On the Homepageproducts.ascx.cs file

The ascx page should have the following:

<%@ Control Language="C#" AutoEventWireup="true"
    Inherits= "NopSolutions.NopCommerce.Web.Modules.HomePageProductsControl" Codebehind="HomePageProducts.ascx.cs" %>
<%@ Register TagPrefix="nopCommerce" TagName="ProductBox1" Src="~/Modules/ProductBox1.ascx" %>
  
<div class="HomePageProductGrid">
    <asp:DataList ID="dlCatalog" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
        RepeatLayout="Table" OnItemDataBound="dlCatalog_ItemDataBound" ItemStyle-CssClass="ItemBox">
        <ItemTemplate>
            <nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>' runat="server" />
       </ItemTemplate>
    </asp:DataList>
</div>


The code behind should have the following:

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Categories;
using NopSolutions.NopCommerce.BusinessLogic.Media;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.Infrastructure;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class HomePageProductsControl: BaseNopFrontendUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            var products = this.ProductService.GetAllProductsDisplayedOnHomePage();
            if (products.Count > 0)
            {
                dlCatalog.DataSource = products;
                dlCatalog.DataBind();
            }
            else
            {
                this.Visible = false;
            }
        }


        protected void dlCatalog_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var product = e.Item.DataItem as Product;
                if (product != null)
                {
                    string productURL = SEOHelper.GetProductUrl(product);

                    var hlImageLink = e.Item.FindControl("hlImageLink") as HyperLink;
                    if (hlImageLink != null)
                    {
                        var picture = product.DefaultPicture;
                        if (picture != null)
                            hlImageLink.ImageUrl = this.PictureService.GetPictureUrl(picture, this.SettingManager.GetSettingValueInteger( "Media.Product.ThumbnailImageSize", 125), true);
                        else
                            hlImageLink.ImageUrl = this.PictureService.GetDefaultPictureUrl(this.SettingManager.GetSettingValueInteger( "Media.Product.ThumbnailImageSize", 125));

                        hlImageLink.NavigateUrl = productURL;
                        hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                        hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    }

                    var hlProduct = e.Item.FindControl("hlProduct") as HyperLink;
                    if (hlProduct != null)
                    {
                        hlProduct.NavigateUrl = productURL;
                        hlProduct.Text = Server.HtmlEncode(product.LocalizedName);
                    }
                }

              

            }
        }
    }
}


That's it, it will have the buy now and info, price, picture and description.
12 年 前
how do you add it without the description field
12 年 前
Hi,

Is there anyway of doing this for the home page categories.
12 年 前
[email protected] wrote:
how do you add it without the description field


To remove the description field:

Open up ProductBox1.ascx file under the Modules folder.

Remove the description from the front end and comment out all references to it in the code behind.

Like:

FROM:

<div class="product-item">
    <h2 class="product-title">
        <asp:HyperLink ID="hlProduct" runat="server" />
    </h2>
    <div class="picture">
        <asp:HyperLink ID="hlImageLink" runat="server" />
    </div>
    <div class="description">
        <asp:Literal runat="server" ID="lShortDescription"></asp:Literal>
    </div>
    <div class="add-info">
        <div class="prices">
            <asp:Label ID="lblOldPrice" runat="server" CssClass="oldproductPrice" Visible="false"/>
            <br />
            <asp:Label ID="lblPrice" runat="server" CssClass="productPrice" /></div>
        <div class="buttons">
            <asp:Button runat="server" ID="btnProductDetails" OnCommand="btnProductDetails_Click"
                Text="" BorderWidth="0" BorderStyle="None" ValidationGroup="ProductDetails"
                CommandArgument='<%# Eval("ProductId") %>' CssClass="productgridproductdetailbutton" /><br />
            <asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text=""
                ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductId") %>' BorderWidth="0" BorderStyle="None" CssClass="productgridaddtocartbutton" />
        </div>
    </div>
</div>


TO

<div class="product-item">
    <h2 class="product-title">
        <asp:HyperLink ID="hlProduct" runat="server" />
    </h2>
    <div class="picture">
        <asp:HyperLink ID="hlImageLink" runat="server" />
    </div>
    <div class="add-info">
        <div class="prices">
            <asp:Label ID="lblOldPrice" runat="server" CssClass="oldproductPrice" Visible="false"/>
            <br />
            <asp:Label ID="lblPrice" runat="server" CssClass="productPrice" /></div>
        <div class="buttons">
            <asp:Button runat="server" ID="btnProductDetails" OnCommand="btnProductDetails_Click"
                Text="" BorderWidth="0" BorderStyle="None" ValidationGroup="ProductDetails"
                CommandArgument='<%# Eval("ProductId") %>' CssClass="productgridproductdetailbutton" /><br />
            <asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text=""
                ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductId") %>' BorderWidth="0" BorderStyle="None" CssClass="productgridaddtocartbutton" />
        </div>
    </div>
</div>


Then just comment out all references to lShortDescription in the code behind.
12 年 前
garrie007 wrote:
Hi,

Is there anyway of doing this for the home page categories.


Sorry, can you explain what you mean?
12 年 前
Hi

Is it possible to add the price on the featured products products without modifying any other part of the website, thanks
12 年 前
[email protected] wrote:
Hi

Is it possible to add the price on the featured products products without modifying any other part of the website, thanks


Yep no problem.

At the moment, it's set to product box 1.  Copy and paste product box 1 and all related files (ascx, code behind, designer).  Make that product box 3.

Do your changes in product box3 and reference that on the featured products.
12 年 前
cool. Thanks very much
12 年 前
Dear Team,

Can anyone tell me how do i achieve the same thing in 2.20 version? I am in real urgnt need for the same.


Thanks and Best Regards,
Amit Shah
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.