Price on front page?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Hello

How do i get the price added on products on the front page?

On the six products there?

ref: cene.dk
13 年 前
The following will display the price, old price, and discounted price for the lowest priced product variant for a product for home page products (code is adapted from the ProductPrice1 control) for nopCommerce 1.90. It just needs some style rules defined.

Screenshot (note the game has a value for old price and a discount applied to it):
home page products with prices

Modified Files:
HomePageProducts.ascx
HomePageProducts.ascx.cs

Edit file: Modules\HomePageProducts.ascx and add the following in the ItemTemplate:
<span class="price">
    <asp:PlaceHolder runat="server" ID="phOldPrice">
        <%=GetLocaleResourceString("Products.OldPrice")%>&nbsp;
        <asp:Label ID="lblOldPrice" runat="server" CssClass="oldProductPrice" />
    </asp:PlaceHolder>
    <br />                    
    <asp:Label ID="lblPrice" runat="server" Visible="false" />
    <asp:Label ID="lblPriceValue" runat="server" CssClass="productPrice" />
    <asp:PlaceHolder runat="server" ID="phDiscount">
        <br />
        <%=GetLocaleResourceString("Products.FinalPriceWithDiscount")%>&nbsp;&nbsp;
        <asp:Label ID="lblFinalPriceWithDiscount" runat="server" CssClass="productPrice" />
    </asp:PlaceHolder>
</span>

Edit  file: Modules\HomePageProducts.ascx.cs and add the following after line 87:
var phOldPrice = e.Item.FindControl("phOldPrice") as PlaceHolder;
var lblOldPrice = e.Item.FindControl("lblOldPrice") as Label;
var lblPrice = e.Item.FindControl("lblPrice") as Label;
var lblPriceValue = e.Item.FindControl("lblPriceValue") as Label;
var phDiscount = e.Item.FindControl("phDiscount") as PlaceHolder;
var lblFinalPriceWithDiscount = e.Item.FindControl("lblFinalPriceWithDiscount") as Label;

if (phOldPrice != null && lblOldPrice != null && lblPrice != null && lblPriceValue != null && phDiscount != null && lblFinalPriceWithDiscount != null)
{
    var productVariant = product.MinimalPriceProductVariant;
    if (productVariant != null)
    {
        if (!this.SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                (NopContext.Current.User != null &&
                !NopContext.Current.User.IsGuest))
        {
            if (productVariant.CustomerEntersPrice)
            {                                    
                phOldPrice.Visible = false;
                lblPrice.Visible = false;
                lblPriceValue.Visible = false;
                phDiscount.Visible = false;
            }
            else
            {
                if (productVariant.CallForPrice)
                {                                        
                    lblPriceValue.Text = GetLocaleResourceString("Products.CallForPrice");
                    phOldPrice.Visible = false;
                    phDiscount.Visible = false;
                }
                else
                {
                    decimal taxRate = decimal.Zero;
                    decimal oldPriceBase = this.TaxService.GetPrice(productVariant, productVariant.OldPrice, out taxRate);
                    decimal finalPriceWithoutDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                    decimal finalPriceWithDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true), out taxRate);

                    decimal oldPrice = this.CurrencyService.ConvertCurrency(oldPriceBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    decimal finalPriceWithoutDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithoutDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    decimal finalPriceWithDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                    {
                        lblOldPrice.Text = PriceHelper.FormatPrice(oldPrice);
                        lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                        phOldPrice.Visible = true;
                    }
                    else
                    {
                        lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                        phOldPrice.Visible = false;
                    }

                    if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                    {
                        lblFinalPriceWithDiscount.Text = PriceHelper.FormatPrice(finalPriceWithDiscount);
                        phDiscount.Visible = true;
                    }
                    else
                    {
                        phDiscount.Visible = false;
                    }

                    if (phDiscount.Visible)
                    {
                        lblPriceValue.CssClass = string.Empty;
                    }
                    else
                    {
                        lblPriceValue.CssClass = "productPrice";
                    }

                    if (phDiscount.Visible || phOldPrice.Visible)
                    {
                        lblPrice.Text = GetLocaleResourceString("Products.FinalPriceWithoutDiscount");
                    }                                    
                }
            }
        }
        else
        {                                
            phOldPrice.Visible = false;
            lblOldPrice.Visible = false;
            lblPrice.Visible = false;
            lblPriceValue.Visible = false;
            phDiscount.Visible = false;
            lblFinalPriceWithDiscount.Visible = false;
        }
    }                      
}

This is for version 1.90 and you will need to recompile the solution.

.
13 年 前
Thanks!

How do i add Stock Availablity on the front also?
13 年 前
The following will display the stock availability for the lowest priced product variant for a product for home page products (code is adapted from the OneVariant.ascx product template control) for nopCommerce 1.90. It will also need some style rules defined.

To see the stock availability message, ensure that "Manage Stock:" is set to 'track inventory' and that "Display stock availability:" is checked in product variant details.

Edit file: Modules\HomePageProducts.ascx and add the following in the ItemTemplate:
<asp:Panel ID="pnlStockAvailablity" runat="server" class="stock">
    <asp:Label ID="lblStockAvailablity" runat="server" />
</asp:Panel>

Edit  file: Modules\HomePageProducts.ascx.cs and add the following at the same block level as the code from my previous post in this topic:
var pnlStockAvailablity = e.Item.FindControl("pnlStockAvailablity") as Panel;
var lblStockAvailablity = e.Item.FindControl("lblStockAvailablity") as Label;

if (pnlStockAvailablity != null && lblStockAvailablity != null)
{
    var productVariant = product.MinimalPriceProductVariant;
    string stockMessage = productVariant.FormatStockMessage();
    if (!String.IsNullOrEmpty(stockMessage))
    {
        lblStockAvailablity.Text = stockMessage;
    }
    else
    {
        pnlStockAvailablity.Visible = false;
    }
}

This is for version 1.90 and you will need to recompile the solution.

.
13 年 前
Now a very stupid question!

Now I've just changed the files and made some changes, and not in solution are there any clever way I can add this without having to start over?
13 年 前
cene wrote:
Now I've just changed the files and made some changes, and not in solution are there any clever way I can add this without having to start over?

I'm not sure I understand your question. Are you referring to integrating the in stock change to the prices change for home page products?

.
13 年 前
I did all that you mentioned and recompiled it also, but price isnt showing up..

http://lanos.co.in.carnation.arvixe.com/default.aspx
Please help..
13 年 前
Awesome post.  How coudl I add the Short description
13 年 前
[email protected] wrote:
Awesome post.  How coudl I add the Short description

To add the short description to the home page products, make the following changes.

Add the following to Modules\HomePageProducts.ascx (within the <ItemTemplate>):
<asp:Label ID="lblShortDescription" runat="server"></asp:Label>

And add the following to Modules\HomePageProducts.ascx.cs (within the "if (product != null)" code block):
var lblShortDescription = e.Item.FindControl("lblShortDescription") as Label;
if (lblShortDescription != null)
{
    lblShortDescription.Text = product.ShortDescription;
}

You will need to recompile the NopCommerceStore project.

Additionally, you may want to adjust the style rules for the product-item div (line #1928 in darkOrange styles.css) to remove the height setting so that the short description text doesn't overflow.

.
13 年 前
mb wrote:
The following will display the price, old price, and discounted price for the lowest priced product variant for a product for home page products (code is adapted from the ProductPrice1 control) for nopCommerce 1.90. It just needs some style rules defined.

Screenshot (note the game has a value for old price and a discount applied to it):
home page products with prices

Modified Files:
HomePageProducts.ascx
HomePageProducts.ascx.cs

Edit file: Modules\HomePageProducts.ascx and add the following in the ItemTemplate:
<span class="price">
    <asp:PlaceHolder runat="server" ID="phOldPrice">
        <%=GetLocaleResourceString("Products.OldPrice")%>&nbsp;
        <asp:Label ID="lblOldPrice" runat="server" CssClass="oldProductPrice" />
    </asp:PlaceHolder>
    <br />                    
    <asp:Label ID="lblPrice" runat="server" Visible="false" />
    <asp:Label ID="lblPriceValue" runat="server" CssClass="productPrice" />
    <asp:PlaceHolder runat="server" ID="phDiscount">
        <br />
        <%=GetLocaleResourceString("Products.FinalPriceWithDiscount")%>&nbsp;&nbsp;
        <asp:Label ID="lblFinalPriceWithDiscount" runat="server" CssClass="productPrice" />
    </asp:PlaceHolder>
</span>

Edit  file: Modules\HomePageProducts.ascx.cs and add the following after line 87:
var phOldPrice = e.Item.FindControl("phOldPrice") as PlaceHolder;
var lblOldPrice = e.Item.FindControl("lblOldPrice") as Label;
var lblPrice = e.Item.FindControl("lblPrice") as Label;
var lblPriceValue = e.Item.FindControl("lblPriceValue") as Label;
var phDiscount = e.Item.FindControl("phDiscount") as PlaceHolder;
var lblFinalPriceWithDiscount = e.Item.FindControl("lblFinalPriceWithDiscount") as Label;

if (phOldPrice != null && lblOldPrice != null && lblPrice != null && lblPriceValue != null && phDiscount != null && lblFinalPriceWithDiscount != null)
{
    var productVariant = product.MinimalPriceProductVariant;
    if (productVariant != null)
    {
        if (!this.SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                (NopContext.Current.User != null &&
                !NopContext.Current.User.IsGuest))
        {
            if (productVariant.CustomerEntersPrice)
            {                                    
                phOldPrice.Visible = false;
                lblPrice.Visible = false;
                lblPriceValue.Visible = false;
                phDiscount.Visible = false;
            }
            else
            {
                if (productVariant.CallForPrice)
                {                                        
                    lblPriceValue.Text = GetLocaleResourceString("Products.CallForPrice");
                    phOldPrice.Visible = false;
                    phDiscount.Visible = false;
                }
                else
                {
                    decimal taxRate = decimal.Zero;
                    decimal oldPriceBase = this.TaxService.GetPrice(productVariant, productVariant.OldPrice, out taxRate);
                    decimal finalPriceWithoutDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                    decimal finalPriceWithDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, true), out taxRate);

                    decimal oldPrice = this.CurrencyService.ConvertCurrency(oldPriceBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    decimal finalPriceWithoutDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithoutDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    decimal finalPriceWithDiscount = this.CurrencyService.ConvertCurrency(finalPriceWithDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                    {
                        lblOldPrice.Text = PriceHelper.FormatPrice(oldPrice);
                        lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                        phOldPrice.Visible = true;
                    }
                    else
                    {
                        lblPriceValue.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                        phOldPrice.Visible = false;
                    }

                    if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                    {
                        lblFinalPriceWithDiscount.Text = PriceHelper.FormatPrice(finalPriceWithDiscount);
                        phDiscount.Visible = true;
                    }
                    else
                    {
                        phDiscount.Visible = false;
                    }

                    if (phDiscount.Visible)
                    {
                        lblPriceValue.CssClass = string.Empty;
                    }
                    else
                    {
                        lblPriceValue.CssClass = "productPrice";
                    }

                    if (phDiscount.Visible || phOldPrice.Visible)
                    {
                        lblPrice.Text = GetLocaleResourceString("Products.FinalPriceWithoutDiscount");
                    }                                    
                }
            }
        }
        else
        {                                
            phOldPrice.Visible = false;
            lblOldPrice.Visible = false;
            lblPrice.Visible = false;
            lblPriceValue.Visible = false;
            phDiscount.Visible = false;
            lblFinalPriceWithDiscount.Visible = false;
        }
    }                      
}

This is for version 1.90 and you will need to recompile the solution.

.


I've add and replaced the 2x new files via the download and I can now see the label's against the product's on the featured product page, problem is there are no prices displaying, I've checked and amended the product price for the featured products but the code is not pulling through the prices, I'm running 1.90

Any Idea's before I pull the plug and reverse the changes, I'm not having much luck make changes at the moment to the basecode lol

H.E.L.P Someone lol > Someone once told me that too much "C" makes U "C" Sick, never understood him until now :0)

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