Random featured products on Home page

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 13 ans
If you want to show random featured product it is easy way to do it.

Modify Nop_ProductLoadDisplayedOnHomePage stored procedure
find  
order by p.[name] in last line,

replace to order by newid()  

then execute query :)))


newid() returns random order it is new feature from sql 2005.
Il y a 13 ans
F.Y.I 1.80 now uses LINQ for this… So if you want to really control the featured products on the home page you will need to modify [NopSolutions.NopCommerce.BusinessLogic.Products]

My sample gets 6 random products for display on the home page.

    /// <summary>
        /// Gets all products displayed on the home page
        /// </summary>
        /// <returns>Product collection</returns>
        public static List<Product> GetAllProductsDisplayedOnHomePage()
        {
            bool showHidden = NopContext.Current.IsAdmin;

            int languageId = 0;
            if (NopContext.Current != null)
                languageId = NopContext.Current.WorkingLanguage.LanguageId;

            var context = ObjectContextHelper.CurrentObjectContext;
        
           //Modified code
            var query = (from p in context.Products
                         orderby Guid.NewGuid()
                         where (showHidden || p.Published) && !p.Deleted
                         select p).Take(6);

            var products = query.ToList();
            
            return products;

            //Old code
            //var query = from p in context.Products
            //            orderby p.Name
            //            where (showHidden || p.Published) &&
            //            !p.Deleted &&
            //            p.ShowOnHomePage
            //            select p;

        }
Reply Previous 1 2
Il y a 13 ans
Site using the above

https://www.bijoudiva.com/
Il y a 13 ans
Could you give us information about how did you change the design and come up with this page. How did you started?

how did you change the master page and the template ? Another question is  why is your website coming up so slow? is this the drawback of nopcommerce or the hosting company?
Il y a 13 ans
First the site is not slow.. (Based on performance test conducted using HP LoadRunner) not sure if you are using dialup or what but this thing is running on one of the new GoDaddy dedicated virtual servers, it’s as fast as it can be.

To answer your question there are some things you just have to know in general as to how nopcommerce actually works (Basic web development and Object Oriented Concepts in C#).

To start take a look at some of the available templates for nopcommerce and play around with them. Also be sure to download the source version of nopcommerce. Note: If you do not have C# programming and basic web development experience you might want to go take a class at your local community college.
Il y a 13 ans
You say this is on one of godaddys virtual server. Is the SQL on the sme server? IS it a full version or is it a experss?

Do you really sell enough product to make it worth while to run the site on one of there virtual servers
?
Il y a 12 ans
Is this possible on 2.1 and 2.2(upcoming)?
Il y a 12 ans
thrifty34 wrote:
Is this possible on 2.1 and 2.2(upcoming)?


For random featured products on the home page for 2.00-2.20, see the following topic:
https://www.nopcommerce.com/boards/t/12051/main-page-featured-products-question.aspx

.
Il y a 4 ans
I don't think this is the best answer but try to
edit
Views/Shared/Components/HomepageProducts/Default.cshtml


replace

@foreach (var item in Model

with

@foreach (var item in Model.OrderBy(x => Guid.NewGuid()).Take(8))
Il y a 4 ans
i suggest you this plugin, i already tested it and it's working very good.
it's also compatible with recent versions of nopcommerce.

https://github.com/nopCommerceBrasil/NopBrasil.Plugin.Misc.HomepageProductIndex
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.