Hi there,
I am trying to modify the ProductList property of a ProductListTemplateExtender by adding or removing products using some custom logic. Here's a quick example:
public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
{
string sql = "SELECT * FROM Ecomproducts WHERE ProductNumber = 'Test1234'";
ProductCollection productsToAdd = Product.getProductBySQL(sql);
foreach (Product item in productsToAdd)
{
ProductList.Add(item);
}
}
Although the code works fine and at the end of the ExtendTemplate method my ProductList property contains the new products, the changes are not reflected at the front-end. The same is true when I remove items, or when I call Clear on the ProductList.
Is Dynamicweb passing a copy of the internal list to the extender, and should I consider the ProductList to be read-only? If so, what other ways are there to change the products being displayed?
I also tried manually rendering the list using something like this:
new Renderer().RenderProducts(ProductList, template);
While this indeed outputs my own items, I also get the initial items, and the product- and page counts are off.
Any suggestions?
Thanks in advance.
Imar