Developer forum

Forum » Development » Module properties edit

Module properties edit

Jonas Mersholm
Reply

Hi. 

Is there any documentation, what so ever, on the different modules module-property names?

At the moment i am trying to assign groups to a module on a paragraph, the module is the products catalogue from the eCommerce namespace.
I tried the following without any luck.

 

 paragraph.ModuleProperties.set_Value("ProductAndGroupsSelector", "[some][g:GROUP31]");
 paragraph.Save();

 

Any help would be appreciated.

Thank you.


Replies

 
Mikkel Ricky
Reply

You can use Dynamicweb.Extensibility.ProductsAndGroupsHandler for this:

var handler = new Dynamicweb.Extensibility.ProductsAndGroupsHandler();

// All products in shop
handler.Type = Dynamicweb.Extensibility.ProductsAndGroupsHandler.Types.All;
handler.ShopSelected = "SHOP1";

// Some products and groups
handler.Type = Dynamicweb.Extensibility.ProductsAndGroupsHandler.Types.Some;
handler.ProductsSelected.Add(Dynamicweb.eCommerce.Products.Product.GetProductByID("PROD1"));
handler.ProductsSelected.Add(Dynamicweb.eCommerce.Products.Product.GetProductByID("PROD3"));
handler.GroupsSelected.Add(Dynamicweb.eCommerce.Products.Group.GetGroupByID("GROUP1"));
handler.GroupsSelected.Add(Dynamicweb.eCommerce.Products.Group.GetGroupByID("GROUP2"));

var paragraph = Dynamicweb.Content.Paragraph.GetParagraphById(87);
paragraph.ModuleProperties.set_Value("ProductAndGroupsSelector", handler.ToString());

Best regards,
Mikkel

 
Jonas Mersholm
Reply

Hi Mikkel,

It seems to be the right path. Though, it does not save/persist the moduleProperties. 

 

Dynamicweb.Extensibility.ProductsAndGroupsHandler handler = new Dynamicweb.Extensibility.ProductsAndGroupsHandler();

handler.Type = Dynamicweb.Extensibility.ProductsAndGroupsHandler.Types.All;

handler.ShopSelected = Shop.ID;

para.ModuleProperties.set_Value("ProductAndGroupsSelector", handler.ToString());

para.Save();

 

I verified that the Shop.ID is correct, and that the paragraph is correct. Yet, the Groups select on the module keeps blanks.

 

Thanks in advance 

Jonas

 
Mikkel Ricky
Reply

You have to manually deserialize the properties before saving the paragraph, i.e. add the line

para.ModuleSettings = para.ModuleProperties.ToString();

before calling para.Save(). The API should handle this, but as of now it does not.

Best regards,
Mikkel

 

You must be logged in to post in the forum