Developer forum

Forum » Ecommerce - Standard features » Add product to Customer center favorites in API

Add product to Customer center favorites in API

Dmitrij Jazel
Reply

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.


Replies

 
Alexander
Reply
This post has been marked as an answer

Hi Dmitrij,

Try to use Dynamicweb.eCommerce.CustomerCenter.CustomerProductList.AddToFavorites functions instead of your sample.

 

 

 

 

Votes for this answer: 1
 
Dmitrij Jazel
Reply

Hej Alexander,

Thanks for suggestion :) Worked great :) 

I was not able to feed this method an Product object dirrectly, for some reason compiler complained.

But than I used this:

Dynamicweb.eCommerce.CustomerCenter.CustomerProductList.AddToFavorites(prod.ID, prod.VariantID, prod.LanguageID);

Worked perfectly! :)

Thanks allot for help! :)

 

/Dmitrij

 

 

You must be logged in to post in the forum