Display product price on HomepageProducts template

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi,
Need help with customization of HomePageProducts.cshtml on nopcommerce v.2.0
I tried use @item.ProductPrice.Price, but it`s not display.
How to get price and display on template?

Thanks
12 years ago
nopworks wrote:
I tried use @item.ProductPrice.Price, but it`s not display.

1. Open F:\Own\NopCommerce\Sources\src\Presentation\Nop.Web\Controllers\CatalogController.cs file
2. Find HomepageProducts() method
3. Replace
var model = _productService.GetAllProductsDisplayedOnHomePage()
                .Select(x => PrepareProductOverviewModel(x, false, true))
                .ToList();

with
var model = _productService.GetAllProductsDisplayedOnHomePage()
                .Select(x => PrepareProductOverviewModel(x, true, true))
                .ToList();

4. Now use @item.ProductPrice.Price in the view

P.S. It's just a performance optimization (don't calculate prices for home page products if it's not required)
12 years ago
Thanks Andrei, it`s work fine.
Is there any way display products on homepage like on category grid or simple add add to cart button?

Thank you for help,
nopCommerce best e-commerce solution

P.S Many websites use price and add to cart buttons on homepage products template http://www.templatemonster.com/category.php?tid=-+Any+-&search_words=store&from_=-+Any+-&to=-+Any+-&type=&cat=&style=&author=
11 years ago
Hi
i am using nop 2.50 and homepage action code look like this . So how can i change to show price

model.Products = _productService.GetAllProductsDisplayedOnHomePage()
                .Select(x => PrepareProductOverviewModel(x, !_catalogSettings.UseSmallProductBoxOnHomePage, true, productThumbPictureSize))
                .ToList();

please help on this ASAP. thanks
11 years ago
https://www.nopcommerce.com/boards/t/12783/how-to-enable-price-on-featured-product-homepage-.aspx
11 years ago
Hi
U can fallowing code

file name location presentation\nop.web\views\catalog\_productsmallbox.cshtml

under the page u can add fallowing code

<div class="prices">
        @Html.Partial("_ProductPrice", Model.ProductPrice)
    </div>


Thanks & Regards
Kumar
11 years ago
Hi,

I am using NC version 2.65. I need to display price in small box on homepage. I was able to display detail and add to cart button but price is not shown. Even I have place the code as follows:

<div class="add-info">
        <div class="prices">
        
            @if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
            {
                <div class="old-product-price">
                   Was &nbsp; <span class="price"> @Model.ProductPrice.OldPrice</span>
                </div>
            }
            <div class="product-price">
                <span class="price">@Model.ProductPrice.Price</span>
            </div>
        </div>
        <div class="buttons">
            <input type="button" value="@T("Products.Details")" class="button-1 product-box-detail-button" onclick="setLocation('@Url.RouteUrl("Product", new { productId = Model.Id, SeName = Model.SeName })')" />
            @if (!Model.ProductPrice.DisableBuyButton)
            {
                <br />
                <input type="button" value="@(Model.ProductPrice.AvailableForPreOrder ? T("ShoppingCart.PreOrder") : T("ShoppingCart.AddToCart"))" class="button-2 product-box-add-to-cart-button" onclick="AjaxCart.addproducttocart('@addtocartlink');return false;" />
            }
        </div>
        @Html.Widget("productbox_add_info")
    </div>

Price is hidden somewhere. It is not showing on the page.

Can anybody help me.

Thanks.
11 years ago
In order to see the price on home page, I feel like there may be something need to be done in the following code where it says hid price. Can anybody help me how to show the product price in small box on home page.



if (_permissionService.Authorize(StandardPermissionProvider.DisplayPrices))
                                {
                                    //calculate for the maximum quantity (in case if we have tier prices)
                                    decimal? minimalPrice = null;
                                    var productVariant = _priceCalculationService.GetProductVariantWithMinimalPrice(productVariants, _workContext.CurrentCustomer, true, int.MaxValue, out minimalPrice);

                                    if (!productVariant.CustomerEntersPrice)
                                    {
                                        if (productVariant.CallForPrice)
                                        {
                                            priceModel.OldPrice = null;
                                            priceModel.Price = _localizationService.GetResource("Products.CallForPrice");
                                        }
                                        else if (minimalPrice.HasValue)
                                        {
                                            //calculate prices
                                            decimal taxRate = decimal.Zero;
                                            decimal oldPriceBase = _taxService.GetProductPrice(productVariant, productVariant.OldPrice, out taxRate);
                                            decimal finalPriceBase = _taxService.GetProductPrice(productVariant, minimalPrice.Value, out taxRate);

                                            decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, _workContext.WorkingCurrency);
                                            decimal finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, _workContext.WorkingCurrency);

                                            //do we have tier prices configured?
                                            var tierPrices = new List<TierPrice>();
                                            if (productVariant.HasTierPrices)
                                            {
                                                tierPrices.AddRange(productVariant.TierPrices
                                                    .OrderBy(tp => tp.Quantity)
                                                    .ToList()
                                                    .FilterForCustomer(_workContext.CurrentCustomer)
                                                    .RemoveDuplicatedQuantities());
                                            }
                                            bool displayFromMessage =
                                                //When there is just one tier (with  qty 1), there are no actual savings in the list.
                                                (tierPrices.Count > 0 && !(tierPrices.Count == 1 && tierPrices[0].Quantity <= 1)) ||
                                                //we have more than one variant
                                                (productVariants.Count > 1);
                                            if (displayFromMessage)
                                            {
                                                priceModel.OldPrice = null;
                                                priceModel.Price = String.Format(_localizationService.GetResource("Products.PriceRangeFrom"), _priceFormatter.FormatPrice(finalPrice));
                                            }
                                            else
                                            {
                                                if (finalPriceBase != oldPriceBase && oldPriceBase != decimal.Zero)
                                                {
                                                    priceModel.OldPrice = _priceFormatter.FormatPrice(oldPrice);
                                                    priceModel.Price = _priceFormatter.FormatPrice(finalPrice);
                                                }
                                                else
                                                {
                                                    priceModel.OldPrice = null;
                                                    priceModel.Price = _priceFormatter.FormatPrice(finalPrice);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //Actually it's not possible (we presume that minimalPrice always has a value)
                                            //We never should get here
                                            Debug.WriteLine(string.Format("Cannot calculate minPrice for product variant #{0}", productVariant.Id));
                                        }
                                    }
                                }
                                else
                                {
                                    //hide prices
                                    priceModel.OldPrice = null;
                                    priceModel.Price = null;
                                }
6 years ago
For showing the price you can access productprice model property oldPrice,price in .cshtml i.e. @(Model.ProductPrice.Price)

And If you want to show price off in percentage, have to update price model & factory.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.