How to show the new products in Home page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Hi All,

can anyone help me to how to show the new products in home page..

Thankyou..
6 years ago
usadananda wrote:
Hi All,

can anyone help me to how to show the new products in home page..

Thankyou..


Try ==>
Index.cshtml

@Html.Action("NewProducts", "Product")


NewProducts.cshtml

@model IList<ProductOverviewModel>
@using Nop.Web.Models.Catalog;
@{
    //-------Show new product in on home page-------------//
    var controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();
    var actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString();
    var isHome = false;
    if (controllerName == "Home" && actionName == "Index")
    {
        isHome = true;
    Layout = null;
    }
    else
    {
        isHome = false;
        Layout = "~/Views/Shared/_ColumnsTwo.cshtml";
        //title
        Html.AddTitleParts(T("PageTitle.NewProducts").Text);
        //page class
        Html.AppendPageCssClassParts("html-recently-added-products-page");
    }
}

@if (Model.Count > 0)
{
    if (isHome)
    {

        <div class="product-grid">
            <h1 class="title">@T("Products.NewProducts")</h1>
           <div class="item-grid">
                @foreach (var product in Model)
                    {
                    <div class="item-box">
                        @Html.Partial("_ProductBox", product)
                    </div>
                }
            </div>
        </div>
        
    }
    else
    {
        <div class="page recently-added-products-page">
            <div class="page-title">
                <a href="@Url.RouteUrl("NewProductsRSS")" class="link-rss" title="@T("Products.NewProducts.RSS.Hint")">@T("Products.NewProducts.RSS")</a>
                <h1>@T("Products.NewProducts")</h1>
            </div>
            <div class="page-body">
                <div class="product-grid">
                    <div class="item-grid">
                        @foreach (var product in Model)
                        {
                            <div class="item-box">
                                @Html.Partial("_ProductBox", product)
                            </div>
                        }
                    </div>
                </div>

            </div>
        </div>
    }

}
6 years ago
GO To Admin-> Product-> Edit Product -> Checked the check box "Show on the home Page".
6 years ago
[email protected] wrote:
GO To Admin-> Product-> Edit Product -> Checked the check box "Show on the home Page".


I tried this.  This does not make products show up under New Products.

You need to check the Mark as new checkbox.

Thanks,
Tony
4 years ago
sohel wrote:
Hi All,

can anyone help me to how to show the new products in home page..

Thankyou..

Try ==>
Index.cshtml

@Html.Action("NewProducts", "Product")


NewProducts.cshtml

@model IList<ProductOverviewModel>
@using Nop.Web.Models.Catalog;
@{
    //-------Show new product in on home page-------------//
    var controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();
    var actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString();
    var isHome = false;
    if (controllerName == "Home" && actionName == "Index")
    {
        isHome = true;
    Layout = null;
    }
    else
    {
        isHome = false;
        Layout = "~/Views/Shared/_ColumnsTwo.cshtml";
        //title
        Html.AddTitleParts(T("PageTitle.NewProducts").Text);
        //page class
        Html.AppendPageCssClassParts("html-recently-added-products-page");
    }
}

@if (Model.Count > 0)
{
    if (isHome)
    {

        <div class="product-grid">
            <h1 class="title">@T("Products.NewProducts")</h1>
           <div class="item-grid">
                @foreach (var product in Model)
                    {
                    <div class="item-box">
                        @Html.Partial("_ProductBox", product)
                    </div>
                }
            </div>
        </div>
        
    }
    else
    {
        <div class="page recently-added-products-page">
            <div class="page-title">
                <a href="@Url.RouteUrl("NewProductsRSS")" class="link-rss" title="@T("Products.NewProducts.RSS.Hint")">@T("Products.NewProducts.RSS")</a>
                <h1>@T("Products.NewProducts")</h1>
            </div>
            <div class="page-body">
                <div class="product-grid">
                    <div class="item-grid">
                        @foreach (var product in Model)
                        {
                            <div class="item-box">
                                @Html.Partial("_ProductBox", product)
                            </div>
                        }
                    </div>
                </div>

            </div>
        </div>
    }

}


Hello.I'm using version 4.20. how can I do that? Can you help ?
4 years ago
sohel wrote:
Hi All,

can anyone help me to how to show the new products in home page..

Thankyou..

Try ==>
Index.cshtml

@Html.Action("NewProducts", "Product")


NewProducts.cshtml

@model IList<ProductOverviewModel>
@using Nop.Web.Models.Catalog;
@{
    //-------Show new product in on home page-------------//
    var controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();
    var actionName = HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString();
    var isHome = false;
    if (controllerName == "Home" && actionName == "Index")
    {
        isHome = true;
    Layout = null;
    }
    else
    {
        isHome = false;
        Layout = "~/Views/Shared/_ColumnsTwo.cshtml";
        //title
        Html.AddTitleParts(T("PageTitle.NewProducts").Text);
        //page class
        Html.AppendPageCssClassParts("html-recently-added-products-page");
    }
}

@if (Model.Count > 0)
{
    if (isHome)
    {

        <div class="product-grid">
            <h1 class="title">@T("Products.NewProducts")</h1>
           <div class="item-grid">
                @foreach (var product in Model)
                    {
                    <div class="item-box">
                        @Html.Partial("_ProductBox", product)
                    </div>
                }
            </div>
        </div>
        
    }
    else
    {
        <div class="page recently-added-products-page">
            <div class="page-title">
                <a href="@Url.RouteUrl("NewProductsRSS")" class="link-rss" title="@T("Products.NewProducts.RSS.Hint")">@T("Products.NewProducts.RSS")</a>
                <h1>@T("Products.NewProducts")</h1>
            </div>
            <div class="page-body">
                <div class="product-grid">
                    <div class="item-grid">
                        @foreach (var product in Model)
                        {
                            <div class="item-box">
                                @Html.Partial("_ProductBox", product)
                            </div>
                        }
                    </div>
                </div>

            </div>
        </div>
    }

}


Hello.I'm using version 4.20. how can I do that? Can you help ?
4 years ago
1. Copy HomepageProductsViewComponent.cs file and paste it in same directory.
2. Rename the file and its class name as NewProductsViewComponent.
3. Modify line no. 31 as below.
var products = _productService.SearchProducts(markedAsNewOnly: true).ToList();

4. Copy /Views/Shared/Components/HomepageProducts folder and paste it in same directory.
5. Rename the folder as NewProducts.
4 years ago
mhsjaber wrote:
1. Copy HomepageProductsViewComponent.cs file and paste it in same directory.
2. Rename the file and its class name as NewProductsViewComponent.
3. Modify line no. 31 as below.
var products = _productService.SearchProducts(markedAsNewOnly: true).ToList();

4. Copy /Views/Shared/Components/HomepageProducts folder and paste it in same directory.
5. Rename the folder as NewProducts.


??The directory is also HomepageProductsViewComponent.the cs Folder is not located.??

I'm a beginner can you help me ?
4 years ago
It's not directory, but a C# file. It's in Nop.Web > Components directory.
4 years ago
mhsjaber wrote:
It's not directory, but a C# file. It's in Nop.Web > Components directory.


Unfortunately, it didn't. I don't understand where I'm making a mistake. :(

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