Hej Guys,
Trying this code, but for some reason getting custCent_prod is null. I am 100% sure that Product exists in the shop, but I can't get it's customer center instance so I could add it.
var user = User.get_Current(PagePermissionLevels.Frontend);
Dynamicweb.eCommerce.CustomerCenter.CustomerProductList list = new Dynamicweb.eCommerce.CustomerCenter.CustomerProductList();
try{
// products is List<string> Type
foreach (string s in products)
{
//Get actual product data
var prod = Dynamicweb.eCommerce.Products.Product.GetProductByID(s);
if (prod == null)
{
debug = debug + " prod is null ";
}
//Get Customer center product instance, and add it.
var custCent_prod = Dynamicweb.eCommerce.CustomerCenter.CustomerProductListProduct.GetProductById(prod.ID, prod.LanguageID, prod.VariantID);
if (custCent_prod != null)
{
// add custCent_prod to customer center list
list.Products.Add(custCent_prod);
}else{
debug = debug + " custCent_prod is null ";
}
}
// merge lists
Dynamicweb.eCommerce.CustomerCenter.CustomerProductList.GetListByCustomerId(user.ID).Add(list);
}catch(Exception exc){
debug = debug + exc.ToString();
}
Suggestions?
Tryed several ways to solve this, but can't quite find a solution.
Long story short:
I have a list of strings (products), and I need them to add to a favorite list of loggedin user.