Obtaining a given number of random products, HomepageProducts.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Greetings:

I am currently using the following to obtain 30 random products to display on the home page.  From HomepageProducts.cshtml:

var products = Model.Products.OrderBy(x => Guid.NewGuid()).Take(30);

It works fine, however, it only provides a selection of random products that have been designated as "Show on Home Page" in the Admin tool.  I would prefer to obtain a number of random products regardless if they are designated as "Show on Home Page" or not.

Is it possible to obtain 30 random products without concern of whether or not they are "Show on Home Page"?

I suspect the change I need to make is not to HomepageProducts.cshtml, but rather to ProductModel.cs.  Unfortunately for me, I do not know what change I might need to make.

Any advice would be greatly appreciated.

Thanks in advance.

Josh
12 years ago
I found my answer.  I am posting it here so that it might help someone else later.

All I had to do was edit CatalogController.cs.

[ChildActionOnly]
        public ActionResult HomepageProducts(int? productThumbPictureSize)
        {
            var model = new HomePageProductsModel()
            {
                UseSmallProductBox = _catalogSettings.UseSmallProductBoxOnHomePage
            };
            model.Products = _productService.GetAllProductsDisplayedOnHomePage()
                .Select(x => PrepareProductOverviewModel(x, !_catalogSettings.UseSmallProductBoxOnHomePage, true, 125))
                .ToList();

            return PartialView(model);
        }

to this:

[ChildActionOnly]
        public ActionResult HomepageProducts(int? productThumbPictureSize)
        {
            var model = new HomePageProductsModel()
            {
                UseSmallProductBox = _catalogSettings.UseSmallProductBoxOnHomePage
            };
            model.Products = _productService.GetAllProducts()
                .Select(x => PrepareProductOverviewModel(x, !_catalogSettings.UseSmallProductBoxOnHomePage, true, 125))
                .ToList();

            return PartialView(model);
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.