Developer forum

Forum » Development » Parsing paregraph modulesettings

Parsing paregraph modulesettings

Martin Nielsen
Reply

Hi DW,

I'm building a small tool that can take a group of products and create pages base on these products.

eg. 100 ecom products -> 100 page with a "Product catalogue" module attached, set to view a specific ProductID.

I have the pagecreation down, and now i'm about the but look into updating the paragraph settings, and i wonder if there's a built in helper function to parse, add and change settings in the module settings XML?

// Martin


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Martin

Yes, use Dynamicweb.Properties class to load and manipulate the XML with module settings: http://developer.dynamicweb.com/api8/#Dynamicweb~Dynamicweb.Properties.html

I wonder why you need to create a page for each product?

BR Nicolai

 
Martin Nielsen
Reply

Thanks, i'll take a look af the Properties object.

 

In this case we have about 100 products in the eCom, and these products need to each have their own unique design/layout when viewed in the frontend.

One products page should also show related products from a smartsearch, have a form below it, and maybe show 3 related news items. Another products has none of the above, a third product somthing different.

To solve this, we've create a product template page that consists of all the posible elements a product page can consist of, (about 25 paragraphs), and i need to clone that page for each product, update all paragaphssettings to link to the product and update the products related groups.

The final result should be product pages where our client can manage the layout via the Content pane instead of tons of custom checboxes in eCommerce or changing between 30 different product templates.

// Martin

 
Martin Nielsen
Reply

Hi Nicolai, 

I cannot get the changes to the Properties object persistet down to the database. I have this code :

var paragraphs = Dynamicweb.Content.Paragraph.GetParagraphsByPageID( clonedPage.ID );
foreach( var paragraph in paragraphs )
{
  Properties p = paragraph.ModuleProperties;
  paragraph.Header = "Modified " + paragraph.Header;

  if (scenario == 1)
    p.set_Value( "ID_ProductID", product.ProductID );   
  if (scenario == 2)
    p.set_Value( "ProductAndGroupsSelector", groupSelectorValue );

  paragraph.Save();
}
clonedPage.Save();

But when i access the cloned page in the backend, none of my ModuleSettings aer saved, but my headers have.

What else do i need to do?

// Martin

 
Nicolai Høeg Pedersen
Reply

Hi Martin

You actually have to update the Paragraph.ModuleSettings with the new XML:

paragraph.ModuleSettings = p.ToString();
paragraph.Save();

BR Nicolai

 
Martin Nielsen
Reply

Dohh. That helped :-)

Thanks.

 

You must be logged in to post in the forum