Get comparison list count in headerlinks.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 5 años
Hi, I am using NopCommerce version 3.90.

I have added an <li> item to the headerlinks.cshtml file for the comparison list. i would like to include the number of items in the comparison list next to the text. e.g. "Comparison List (12)".

Has anyone figured out a way to do this?

Thanks
Hace 5 años
The following is a way of doing it.

@{
    var count = EngineContext.Current.Resolve<ICompareProductsService>.GetComparedProducts().Count;
}

<li>
<a href="@Url.RouteUrl("CompareProducts")"> Comparison List (@count) </a>
</li>

Hace 5 años
RoastedBytes wrote:
The following is a way of doing it.

@{
    var count = EngineContext.Current.Resolve<ICompareProductsService>.GetComparedProducts().Count;
}

<li>
<a href="@Url.RouteUrl("CompareProducts")"> Comparison List (@count) </a>
</li>



Hi RoastedBytes,

is this for version 3.90?

This doesn't work for me, it throws an error when i run it.

Thanks
Hace 5 años
What error are you getting?
Hace 5 años
This is the error that i get:
Compiler Error Message: CS0103: The name 'EngineContext' does not exist in the current context

thanks
Hace 5 años
Add the following lines at the top of the page

@using Nop.Core.Infrastructure
@using Nop.Services.Catalog
Hace 5 años
Hi,
Thanks for that, i still have an error.

In visual studio it says 'IEngine.Resolve<T>()' is a method, which is not valid in the given context
Hace 5 años
That's weird. Can you share the entire view file?
Hace 5 años
Sorry, but forgot to put brackets there

@{
    var count = EngineContext.Current.Resolve<ICompareProductsService>().GetComparedProducts().Count;
}


This should work.

Regards,
Anshul
Hace 3 años
This code works for me, But count refreshing only after reload page, while adding product to compare list from products home page
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.