Nopcommerce 4.2 - How to recover all the products?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi everyone, I have a problem I'm trying to recover all the products with the following function but I am returning a null value. Can anyone tell me how to do it?


using Nop.Services.Catalog;

public partial class TopicController : BasePublicController
{
            private readonly IProductService _productService;
            public virtual IActionResult ListProd(int topicId)
        {
            var categoryIds = new List<int>();
            categoryIds.Add(1); //categoryId - ID of the desired category
            var products = _productService.SearchProducts(categoryIds: categoryIds);

            ViewBag.MyList = products;
            return products;
        }
}
4 years ago
If you want to return a json array of product then try this.

return Json(products);
4 years ago
Hi,
If you checking with default nopCommerce database then Category with Id-1 does not have any products. You can try with another category which have mapped product or direct map few products with category -1 and check.

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