Get all products for a store

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 yıl önce
Hello.

I'm working on a widget and I need to get a pull X number of random products from the entire catalog for a particular store. Can someone recommend the best way to do this? Would it be a LINQ query?

Thanks
10 yıl önce
Ah, I think I've found it, should I be using the SearchProducts method?
10 yıl önce
You could, but how would you deal with the "random"?  (Getting "all" products and doing random on the client side [controller] could be expensive if you have a lot of products)
10 yıl önce
Yeah it doesn't feel right. Could you recommend an alternative?
10 yıl önce
See this https://www.nopcommerce.com/boards/t/15517/obtaining-a-given-number-of-random-products-homepageproductscshtml.aspx
(and Google site:nopcommerce.com home page random)

If you need to only randomize products having ShowOnHomePage set, it's probably OK.  But it does not deal with problem/performance of getting all products.
The Product table has an index on ShowOnHomePage column.  Depending on how often you need to randomize, maybe you could have a background process change which products have it set.
10 yıl önce
Thanks.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.