Adding Shopping Cart Quantity in Header.cshtml

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

I am using Brooklyn theme and trying to add shopping cart quantity in Header.cshtml file under Themes\Brooklyn\Views\Shared folder. Below is the original code in the Header.cshtml for the Brooklyn theme:

@if (shoppingCartEnabled)
{
    <a href="@Url.RouteUrl("ShoppingCart")" class="ico-cart">
        <span class="cart-qty"></span>
    </a>
    @Html.Action("FlyoutShoppingCart", "ShoppingCart")
}

I updated file which included HeaderLinksModel and Nop.Web.Models.Common.

@model HeaderLinksModel
@using Nop.Web.Models.Common;

And also added quantity to the shopping cart, below is the updated code:

@if (shoppingCartEnabled)
{
    <a href="@Url.RouteUrl("ShoppingCart")" class="ico-cart">
        <span class="cart-qty">@T("ShoppingCart.HeaderQuantity", Model.ShoppingCartItems)</span>
    </a>
    @Html.Action("FlyoutShoppingCart", "ShoppingCart")
}

However, I got some error which seems that the application could not get Model.ShoppingCartItems. Can anybody help me on this?

Thank you!
7 years ago
htg wrote:
Hello,

I am using Brooklyn theme and trying to add shopping cart quantity in Header.cshtml file under Themes\Brooklyn\Views\Shared folder. Below is the original code in the Header.cshtml for the Brooklyn theme:

@if (shoppingCartEnabled)
{
    <a href="@Url.RouteUrl("ShoppingCart")" class="ico-cart">
        <span class="cart-qty"></span>
    </a>
    @Html.Action("FlyoutShoppingCart", "ShoppingCart")
}

I updated file which included HeaderLinksModel and Nop.Web.Models.Common.

@model HeaderLinksModel
@using Nop.Web.Models.Common;

And also added quantity to the shopping cart, below is the updated code:

@if (shoppingCartEnabled)
{
    <a href="@Url.RouteUrl("ShoppingCart")" class="ico-cart">
        <span class="cart-qty">@T("ShoppingCart.HeaderQuantity", Model.ShoppingCartItems)</span>
    </a>
    @Html.Action("FlyoutShoppingCart", "ShoppingCart")
}

However, I got some error which seems that the application could not get Model.ShoppingCartItems. Can anybody help me on this?

Thank you!


HeaderLinksModel is not support here.

You can do like bellow ==>

@using Nop.Core.Infrastructure;
@using Nop.Web.Framework.Themes;
@using Nop.Core;
@using Nop.Services.Localization;
@using Nop.Services.Orders;
@{
    var storeContext = EngineContext.Current.Resolve<Nop.Core.IStoreContext>();
    var customerCartItemNumber = EngineContext.Current.Resolve<Nop.Core.IWorkContext>().CurrentCustomer.ShoppingCartItems.Where(x => x.ShoppingCartType == Nop.Core.Domain.Orders.ShoppingCartType.ShoppingCart)
                    .LimitPerStore(storeContext.CurrentStore.Id)
                    .ToList()
                    .GetTotalProducts();
}


@if (customerCartItemNumber > 0)
                                    {
                                        <i class="cart-qty">
                                            @T("ShoppingCart.HeaderQuantity", customerCartItemNumber)

                                        </i>
                                    }
7 years ago
It works perfect!

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