Read the data in the association table productCategory - nopcommerce 3.80

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi. I need to make the link between the category table and the product table in my code with linq to sql. I have a lot of difficulty doing it on nop. Here is my problem:
How can we recover all products that belong to the same category. For example, Retrieve all products belonging to the Computer category.

Thanks for your help.
5 years ago
Most of the time when trying to understand nop you need to look at an existing page that does something similar to what you want to do and then work out how it works by looking at the code
The function you want to do is the same as the Category page which exists i.e. Clicking on a category in the top menu
Its best to reuse existing code where ever possible rather than make new code that does the same thing

The category page calls the CatalogController to setup the model
In there it needs to find all products for the category selected
So it calls the Product Service and does a search of the products using the category (and other filters)

            var products = _productService.SearchProducts(out filterableSpecificationAttributeOptionIds,
                true,
                categoryIds: categoryIds,
                storeId: _storeContext.CurrentStore.Id,
                visibleIndividuallyOnly: true,
                featuredProducts:_catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false,
                priceMin:minPriceConverted,
                priceMax:maxPriceConverted,
                filteredSpecs: alreadyFilteredSpecOptionIds,
                orderBy: (ProductSortingEnum)command.OrderBy,
                pageIndex: command.PageNumber - 1,
                pageSize: command.PageSize);
            model.Products = PrepareProductOverviewModels(products).ToList();

You can either use this routine or look inside and see what it does and copy and paste to make a new routine to do what you want specifically
5 years ago
Thanks for the remark. I will try your method and see the result.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.