Rotating Top Sellers

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Rotating Top Sellers

Post by Brewhaus » Mon Jul 06, 2009 7:29 pm

Is there a way to have the "Top Sellers" pull from a larger list of top selling items and show them randomly? Because of the nature of our business, the top three items are not going to change very often, if at all, so we would like to expand the list that the Top Sellers display pulls from to bring a bit of variety. We would still like to show only about three items, but pull from maybe the top dozen or so.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Rotating Top Sellers

Post by jmestep » Tue Jul 07, 2009 3:36 am

I think you would use the MaxItems parameter - set it to 12 instead of 3. But leave your columns set at 3.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Rotating Top Sellers

Post by mazhar » Tue Jul 07, 2009 4:50 am

Here is a workaround. The trick is to first load 100 top products and then pick specified number of products(MaxItems) randomly through those 100 top products.

Edit your ConLib/PopularProductsDialog.ascx.cs file and locate following code line

Code: Select all

List<Product> products = ProductDataSource.GetPopularProducts(this.MaxItems, prefferedCategoryId);
and replace code line with following code block

Code: Select all

//List<Product> products = ProductDataSource.GetPopularProducts(this.MaxItems, prefferedCategoryId);
        List<Product> products = ProductDataSource.GetPopularProducts(100, prefferedCategoryId);
        List<Product> randomProducts = new List<Product>();
        Random random = new Random();
        int count = 0;
        if (products.Count > 0)
        {
            if (MaxItems > products.Count)
                MaxItems = products.Count;
            while (count < MaxItems)
            {
                int index = random.Next(0, products.Count);
                Product product = products[index];
                if (!randomProducts.Contains(product))
                {
                    randomProducts.Add(product);
                    count++;
                }
            }
        }
        products = randomProducts;
Save the file and try again, it will pick random products.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Rotating Top Sellers

Post by Brewhaus » Tue Jul 07, 2009 6:37 am

Judy- I had tried what you suggest before posting, and it expanded the list of Top Sellers to that quantity. That is where I became lost and decided to ask for help. :?

Mazhar- your code change worked perfectly- thank you. The great thing is that a person can control how much of a rolling list of items there will be by changing the number of products to pull from.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Rotating Top Sellers

Post by mazhar » Tue Jul 07, 2009 6:47 am

Brewhaus wrote:Judy- I had tried what you suggest before posting, and it expanded the list of Top Sellers to that quantity. That is where I became lost and decided to ask for help. :?

Mazhar- your code change worked perfectly- thank you. The great thing is that a person can control how much of a rolling list of items there will be by changing the number of products to pull from.
I just updated the code. There was bug in previous code so please use the updated code from above post.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Rotating Top Sellers

Post by Brewhaus » Tue Jul 07, 2009 6:52 am

Thank you again, Mazhar. I have pulled the new code above.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Rotating Top Sellers

Post by rhuffman » Sun Sep 05, 2010 12:10 pm

Mazahr:

Uploaded the above code and it works pretty well, except it is showing hidden items.
Anyway you can correct.

Thanks you Mazhar

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Rotating Top Sellers

Post by mazhar » Sun Sep 05, 2010 9:40 pm

rhuffman wrote:Mazahr:

Uploaded the above code and it works pretty well, except it is showing hidden items.
Anyway you can correct.

Thanks you Mazhar
In above code try replacing

Code: Select all

List<Product> products = ProductDataSource.GetPopularProducts(100, prefferedCategoryId);
with

Code: Select all

List<Product> products = ProductDataSource.GetPopularProducts(100, prefferedCategoryId);
        List<Product> tempProducts = new List<Product>();
        foreach (Product product in products)
        {
            if (product.Visibility == CatalogVisibility.Public)
                tempProducts.Add(product);
        }
        products.Clear();
        products.AddRange(tempProducts);

Post Reply