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
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--;
}