1.5 - help with display price

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 anos atrás
Hi, in the main homepage, Featured Products grid. Could someone please show me how to display the price too? Right now by default it show the product name, and picture only.

also if possible, how do i also display the category that one belong too? reason why in the default.aspx file, i changed the template to use the OneColumn, so there's no left nav. on that one page.

Thank you very much,
14 anos atrás
Have a look at using the Modules/ProductBox# control to display more product details as it will save you some time. You can review the Category and Manufacturer templates for this (in Templates directory).

HTH
Ben
14 anos atrás
could you please give a sample codes? i moved the codes around from the ProductBox# control to the featured products grid, but it's showing the price as blank (i view the source, it show the div tag, but inside that tag is nothing)

i re-compiled, and there's no errors...
thank you much,


nopCommerce team | retroviz wrote:
Have a look at using the Modules/ProductBox# control to display more product details as it will save you some time. You can review the Category and Manufacturer templates for this (in Templates directory).

HTH
Ben
14 anos atrás
Hi,

Here is a very quick example of what you could, by using code from productbox.ascx.cs.

Paste the complete code into HomePageProducts.ascx.cs;


//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  https://www.nopcommerce.com/License.aspx.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
//
// Contributor(s): _______.
//------------------------------------------------------------------------------

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.Tax;
using NopSolutions.NopCommerce.BusinessLogic.Directory;

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

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

        protected void dlRelatedProducts_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)
                    {
                        ProductPictureCollection productPictures = product.ProductPictures;
                        if (productPictures.Count > 0)
                            hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
                        else
                            hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));

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

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

                    var lblPrice = e.Item.FindControl("lblPrice") as Label;
                    if (lblPrice != null)
                    {
                        var productVariantCollection = product.ProductVariants;

                        if (productVariantCollection.Count > 0)
                        {
                             if (!product.HasMultipleVariants)
                             {
                                  var productVariant = productVariantCollection[0];
                                  decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                  decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                  if (finalPriceWithoutDiscount == 0)
                                  {
                                      lblPrice.Visible = false;
                                  }

                                  lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);

                             }
                             else
                             {
                                var productVariant = product.MinimalPriceProductVariant;
                                if (productVariant != null)
                                {
                                    decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                    decimal fromPrice = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                    lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                                }

                              }
                            }
                            else
                            {
                                 lblPrice.Visible = false;
                            }
                        }
                    }
                }
            }
        }
    }


and then add the bold text to HomePageProducts.ascx;

<asp:HyperLink ID="hlImageLink" runat="server" />
                </div>
                <div class="price">
                   <asp:Label ID="lblPrice" runat="server" CssClass="productPrice" /></div>
               </div>

</ItemTemplate>

I even tested! V1.50 you will need to recompile and style price DIV.

Regarding other issue, I thought the breadcrumbs would highlight what category the user is in? could you expand on what you need.
14 anos atrás
thanks for the codes ... it works ...

about the breadcrumb link ... in my default.aspx, i changed the TwoColumn.master to OneColumn.master, so when i hit the main page, there's no left column (which had the categories) ... since this is the main page, there's no breadcrumb yet - so there's no way for me to see, or go to one of the categories ...
Right now i have some featured products, in each item box, i've the product's name, picture, and price (thanks again) ... under price, i also like to add a "buy now" button (if possible), and a link to the category that the product belongs to ... for example (last 2 lines), :


----------------------------------------------------------------
   etnies Men's Digit Sneaker
   [show picture show here]
   $17.56

   [Buy Now button here]
   View more in [ Apparel & Shoes  /  Shoes]
----------------------------------------------------------------


thank you thank you...
14 anos atrás
Hi,

What you could do is goto Admin > Catalog > Categories and then tick the show on home page and save, this will show all categories on home page.

Regarding the buy it now button, what I have done is used the ProductBox1.ascx and Implemented it into the HomePageProducts.ascx like so;

<%@ 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="home-page-product-grid">
    <div class="boxtitle">
        <%=GetLocaleResourceString("HomePage.FeaturedProducts")%>
    </div>
    <div class="clear">
    </div>
    <div class="">
    <asp:DataList ID="dlProducts" runat="server" RepeatColumns="2" RepeatDirection="Horizontal"
     RepeatLayout="Table" ItemStyle-CssClass="item-box">
      <ItemTemplate>
         <nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>' runat="server" />
      </ItemTemplate>
   </asp:DataList>
    </div>
</div>

HomePageProducts.ascx.cs;

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.Tax;
using NopSolutions.NopCommerce.BusinessLogic.Directory;

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

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


You will need to restyle.. the css

Hope this helps, if you need more assistance let me know..
14 anos atrás
hi - sorry for bugging you again ... i'm new to this :-)
i copied your code and used it as suggested, re-compiled, but nothing changed, no errors, no warnings ... what did i miss?

current working code without the buy now button...

homepageProducts.ascx.cs:
//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  https://www.nopcommerce.com/License.aspx.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
//
// Contributor(s): _______.
//------------------------------------------------------------------------------

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.Tax;
using NopSolutions.NopCommerce.BusinessLogic.Directory;

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

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

        protected void dlRelatedProducts_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)
                    {
                        ProductPictureCollection productPictures = product.ProductPictures;
                        if (productPictures.Count > 0)
                            hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
                        else
                            hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));

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

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

                    var lblPrice = e.Item.FindControl("lblPrice") as Label;
                    if (lblPrice != null)
                    {
                        var productVariantCollection = product.ProductVariants;

                        if (productVariantCollection.Count > 0)
                        {
                            if (!product.HasMultipleVariants)
                            {
                                var productVariant = productVariantCollection[0];
                                decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                if (finalPriceWithoutDiscount == 0)
                                {
                                    lblPrice.Visible = false;
                                }

                                lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);

                            }
                            else
                            {
                                var productVariant = product.MinimalPriceProductVariant;
                                if (productVariant != null)
                                {
                                    decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                    decimal fromPrice = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                    lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                                }

                            }
                        }
                        else
                        {
                            lblPrice.Visible = false;
                        }
                    }
                }
            }
        }
    }
}



homePageProducts.ascx:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.HomePageProductsControl"
    CodeBehind="HomePageProducts.ascx.cs" %>
<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="dlRelatedProducts_ItemDataBound" ItemStyle-CssClass="item-box">
        <ItemTemplate>
            <div class="masterdiv">
                <div class="columnfirst">
                    <div class="picture"><asp:HyperLink ID="hlImageLink" runat="server" /></div>
                </div>
                <div class="columnsecond">  
                    <div class="product-title" style="border-bottom:1px dotted lightGrey;height:50px;"><asp:HyperLink ID="hlProduct" runat="server" /></div>
                    <div class="price" style="padding-top:5px;font-weight:bold;color:green;font-size:15px"><asp:Label ID="lblPrice" runat="server" CssClass="productPrice" /></div>
                </div>
            </div>
        </ItemTemplate>
    </asp:DataList>
</div>
14 anos atrás
Did you try the code as suggested in my previous post? That should work, I tested it in 1.5 and it works for me?
14 anos atrás
i just tried and it shows error : "Object reference not set to an instance of an object." - i copied/paste the first part of your codes and put it into homepageproducts.ascx, the second part into homepageproducts.ascx.cs ... Did I do that wrong? :-)

But that's ok ... i don't think i have to put the Buy Now button there (for now), no one is going to click it to buy w/out seeing the details first.  
But I'm not gonna give it up on this :-) I will mess around w/ it just in case I need to put it there ...

Thanks again for your help, and patient :-)
14 anos atrás
I'm using 1.4 right now, but I'm sure this applies to 1.5 as well.

I didn't see in the user guide how to show a 'call for price' button. I want someone to be able to purchase and then when they get to the PayPal payment page to fill in the quoted price.

Since these are services, the site owner can then verify that they paid the correct amount.

Also, can I set prices as recurring subscription instead of one time buy?


Thanks.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.