Page 1 of 1
Rotating Top Sellers
Posted: Mon Jul 06, 2009 7:29 pm
by Brewhaus
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.
Re: Rotating Top Sellers
Posted: Tue Jul 07, 2009 3:36 am
by jmestep
I think you would use the MaxItems parameter - set it to 12 instead of 3. But leave your columns set at 3.
Re: Rotating Top Sellers
Posted: Tue Jul 07, 2009 4:50 am
by mazhar
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.
Re: Rotating Top Sellers
Posted: Tue Jul 07, 2009 6:37 am
by Brewhaus
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.
Re: Rotating Top Sellers
Posted: Tue Jul 07, 2009 6:47 am
by mazhar
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.
Re: Rotating Top Sellers
Posted: Tue Jul 07, 2009 6:52 am
by Brewhaus
Thank you again, Mazhar. I have pulled the new code above.
Re: Rotating Top Sellers
Posted: Sun Sep 05, 2010 12:10 pm
by rhuffman
Mazahr:
Uploaded the above code and it works pretty well, except it is showing hidden items.
Anyway you can correct.
Thanks you Mazhar
Re: Rotating Top Sellers
Posted: Sun Sep 05, 2010 9:40 pm
by mazhar
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);