Price on front page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
I have the same problem but I reverted back. The words are showing up but the values are not pulling. I was hoping to get a script to show the starting from price with add to the car or see details button for the featured items.
12 years ago
Hi All,

I have done with below Easy and simple solution. Feedback is highly appreciated  :)

1. Create a New User-control Call 'FeaturedBox.ascx' in Modules folder
2. Copy below code and paste in newly created FeaturedBox.ascx
================================================================================
<%@ Register TagPrefix="nopCommerce" TagName="ProductPrice2" Src="~/Modules/ProductPrice2.ascx" %>
<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="prices-wrapper">
        <%--<div class="prices">
            <nopCommerce:ProductPrice2 ID="ctrlProductPrice" runat="server" ProductID='<%#Eval("ProductId") %>' />
        </div>--%>
        <div class="buttons">
            <asp:Button runat="server" ID="btnProductDetails" OnCommand="btnProductDetails_Click"
                Text="<% $NopResources:Products.ProductDetails %>" ValidationGroup="ProductDetails"
                CommandArgument='<%# Eval("ProductId") %>' CssClass="productlistproductdetailbutton" />
            <br />
            <asp:Button runat="server" ID="btnAddToCart" OnCommand="btnAddToCart_Click" Text="<% $NopResources:Products.AddToCart %>"
                ValidationGroup="ProductDetails" CommandArgument='<%# Eval("ProductId") %>' CssClass="productlistaddtocartbutton" />
        </div>
    </div>
</div>
==================================================================================

3. Copy below code and paste in newly created FeaturedBox.ascx.cs
==================================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Text;
using System.Threading;
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.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.Directory;
using NopSolutions.NopCommerce.BusinessLogic.Localization;
using NopSolutions.NopCommerce.BusinessLogic.Media;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Tax;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.BusinessLogic.Infrastructure;

namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class FeaturedBox : BaseNopFrontendUserControl
    {
        Product product = null;

        public override void DataBind()
        {
            base.DataBind();
            this.BindData();
        }

        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product);

                hlProduct.NavigateUrl = productURL;
                hlProduct.Text = Server.HtmlEncode(product.LocalizedName);

                var picture = product.DefaultPicture;
                if (picture != null)
                {
                    hlImageLink.ImageUrl = this.PictureService.GetPictureUrl(picture, this.ProductImageSize, true);
                    hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                    hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                }
                else
                {
                    hlImageLink.ImageUrl = this.PictureService.GetDefaultPictureUrl(this.ProductImageSize);
                    hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                    hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                }

                hlImageLink.NavigateUrl = productURL;
                lShortDescription.Text = product.LocalizedShortDescription;

                var productVariantCollection = product.ProductVariants;
                if (productVariantCollection.Count > 0)
                {
                    if (!product.HasMultipleVariants)
                    {
                        var productVariant = productVariantCollection[0];
                        btnAddToCart.Visible = (!productVariant.DisableBuyButton);
                        if (!this.SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                            (NopContext.Current.User != null &&
                            !NopContext.Current.User.IsGuest))
                        {
                            //nothing
                        }
                        else
                        {
                            btnAddToCart.Visible = false;
                        }
                    }
                    else
                    {
                        btnAddToCart.Visible = false;
                    }
                }
                else
                {
                    btnAddToCart.Visible = false;
                }
            }
        }

        protected void btnProductDetails_Click(object sender, CommandEventArgs e)
        {
            int productId = Convert.ToInt32(e.CommandArgument);
            string productURL = SEOHelper.GetProductUrl(productId);
            Response.Redirect(productURL);
        }

        protected void btnAddToCart_Click(object sender, CommandEventArgs e)
        {
            int productId = Convert.ToInt32(e.CommandArgument);
            int productVariantId = 0;
            if (this.ProductService.DirectAddToCartAllowed(productId, out productVariantId))
            {
                var addToCartWarnings = this.ShoppingCartService.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                    productVariantId, string.Empty, decimal.Zero, 1);
                if (addToCartWarnings.Count == 0)
                {
                    bool displayCart = true;
                    if (this.RedirectCartAfterAddingProduct.HasValue)
                        displayCart = this.RedirectCartAfterAddingProduct.Value;
                    else
                        displayCart = this.SettingManager.GetSettingValueBoolean("Display.Products.DisplayCartAfterAddingProduct");

                    if (displayCart)
                    {
                        //redirect to shopping cart page
                        Response.Redirect(SEOHelper.GetShoppingCartUrl());
                    }
                    else
                    {
                        //display notification message
                        this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenAddedToTheCart"));
                    }
                }
                else
                {
                    string productURL = SEOHelper.GetProductUrl(productId);
                    Response.Redirect(productURL);
                }
            }
            else
            {
                string productURL = SEOHelper.GetProductUrl(productId);
                Response.Redirect(productURL);
            }
        }

        public Product Product
        {
            get
            {
                return product;
            }
            set
            {
                product = value;
            }
        }

        public int ProductImageSize
        {
            get
            {
                if (ViewState["ProductImageSize"] == null)
                    return this.SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125);
                else
                    return (int)ViewState["ProductImageSize"];
            }
            set
            {
                ViewState["ProductImageSize"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value whether we redirects a customer to shopping cart page after adding a product to the cart (overrides "Display.Products.DisplayCartAfterAddingProduct" settings)
        /// </summary>
        public bool? RedirectCartAfterAddingProduct
        {
            get
            {
                if (ViewState["RedirectCartAfterAddingProduct"] == null)
                    return null;
                else
                    return (bool)ViewState["RedirectCartAfterAddingProduct"];
            }
            set
            {
                ViewState["RedirectCartAfterAddingProduct"] = value;
            }
        }
    }
}
======================================================================================

4. Finaly in HomePageProducts.ascx User-control (located in Modules Directory)  replace below code and build the solution (remember replace :) )
======================================================================================
<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.HomePageProductsControl" CodeBehind="HomePageProducts.ascx.cs" %>
<%@ Register TagPrefix="nopCommerce" TagName="FeaturedBox" Src="~/Modules/FeaturedBox.ascx" %>
<div class="home-page-product-grid">
    <div class="boxtitle">
        <%=GetLocaleResourceString("HomePage.FeaturedProducts")%>
    </div>
    <div class="clear">
    </div>
    <asp:DataList ID="dlCatalog" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
        RepeatLayout="Table" OnItemDataBound="dlCatalog_ItemDataBound" ItemStyle-CssClass="item-box" EnableViewState="false">
        <ItemTemplate>
        <nopCommerce:FeaturedBox ID="ctrlFeaturedBox" Product='<%# Container.DataItem %>' runat="server" />
        </ItemTemplate>
    </asp:DataList>
</div>
=======================================================================================
12 years ago
Hi everyone,  
  how recompile the solution ? Because i try everything; it's show up only  price, old price tag.

thanx.
12 years ago
amuhaimin wrote:
Hi everyone,  
  how recompile the solution ? Because i try everything; it's show up only  price, old price tag.

thanx.

This option is aleady included in versions 2.20. Check:
https://www.nopcommerce.com/releasenotes.aspx
12 years ago
eadameg wrote:
Hi everyone,  
  how recompile the solution ? Because i try everything; it's show up only  price, old price tag.

thanx.
This option is aleady included in versions 2.20. Check:
https://www.nopcommerce.com/releasenotes.aspx


Hi,

i'm using  ver:1.90 ; any idea?

thanx
12 years ago
eadameg wrote:
Hi everyone,  
  how recompile the solution ? Because i try everything; it's show up only  price, old price tag.

thanx.
This option is aleady included in versions 2.20. Check:
https://www.nopcommerce.com/releasenotes.aspx


Hi,

i'm using  ver:1.90 ; any idea?

thanx
12 years ago
Hi

I am using 2.2 and cant find this option, please advise..

Sorry to bother, i got it, i made 'catalogsettings.usesmallproductboxonhomepage' to flase and it worked, but one suggestion, this could have been smaller to accomodate three products in a row when using three colomn templete
12 years ago
kakoli wrote:
I am using 2.2 and cant find this option, please advise..

https://www.nopcommerce.com/boards/t/12783/how-to-enable-price-on-featured-product-homepage-.aspx
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.