Posted on 29/09/2016 15:30:21
Hi Nicolai,
Keld is not available right now, so maybe I can shed some more light on this issue. In a product list template, we have this piece of code to access product information:
// First loop we have in a product list template, works fine
foreach (LoopItem product in GetLoop("Products"))
{
var price = product.GetDouble("Ecom:Product.Price.PriceWithVAT");
// works fine
var discount = product.GetDouble("Ecom:Product.Discount.TotalAmount.PriceWithVAT");
}
// Second loop is executed in a helper class, outside of a template
List<Dynamicweb.eCommerce.Products.Product> products = new List<Dynamicweb.eCommerce.Products.Product>();
// populated with multiple returns from Dynamicweb.eCommerce.Products.Product.GetProductByID(id)
foreach (var product in products)
{
var price = product.Price.PriceWithoutVAT;
// product.Discounts.Count is always 0, even though we know this product has a discount in discount matrix
var discount = product.Discounts.TotalDiscount.PriceWithVAT;
}
First loop is executed in Product List template, and works fine. Second loop we execute in a helper method, so we do not have the context of a template, thus use product fields instead. In such case, product.Price is fine, however, product.Discounts is always an empty list, even though we know for sure that it has discounts in discount matrix (discount is attached to a group this product belongs to).
Does that make sense?