Exclude Products from Recently Added Products?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Does anyone know how I can exclude products from Recently Added Products? There are a couple of categories I do not want included in there.

Thanks,
Brennan
13 years ago
you would probably have to do it manually in the code or change the query to exclude any products in certain categories.
13 years ago
That's what I've been thinking but I didn't know if there was an easier way that I was overlooking. If I come across a good solution I'll post it here.
13 years ago
Okay here is a very ugly way to do it but works. It's not one hundred percent fool proof. I know there are easier ways but here you go if anyone wants it.

List<Product> valuesToDelete = new List<Product>();
            int CatToBeExcluded = 7;

            foreach (Product product in products)
            {
                if (product.ProductCategories.Count > 0)
                {
                    if (product.ProductCategories[0].Category.CategoryId == CatToBeExcluded)
                    {
                        valuesToDelete.Add(product);
                    }
                  
                }
            }

            foreach (Product product in valuesToDelete)
            {
                products.Remove(product);
            }
            // Now we need to add as many products back that were removed.
            int totalRecords = 0;
            var productsToAdd = this.ProductService.GetAllProducts(0,
                0, 0, null, null, null, 0, string.Empty, false, number,
                1, null, NopContext.Current.WorkingLanguage.LanguageId,
                ProductSortingEnum.CreatedOn, out totalRecords);

            int iter = valuesToDelete.Count;
            foreach (Product product in valuesToDelete)
            {
                if(iter >= 0)
                    products.Add(productsToAdd[iter]);
                iter--;
            }
13 years ago
Another simple way would do a products query on each category you would like included. Combine them together and then resort them by date created. Might be a little more simple.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.