SaaS CMS has officially launched! Learn more now.

how to extract the properties of the product present in content area of a page?


Hi all,

how to extract the properties of a product present in content area of a page using code?

Sep 09, 2020 11:31

Try with the below code:

Inject the IContentLoader  dependency on constructor level e.g. private readonly IContentLoader _contentLoader; 

           var contentLinks = block?.ProductContentArea?.FilteredItems?.Select(x => x.ContentLink).ToList();

            if (contentLinks != null && contentLinks.Any())
                var productContentPages = new List<ProductContentPage>();

                foreach (var contentLink in contentLinks)
                    if (_contentLoader.TryGet(contentLink, out ProductContentPage productContentPage))
Sep 09, 2020 13:17

Hi sanjay,

Thanks for the reply, But could you please elaborate it a little more.

I mean i am little confuse with "block" and "ProductContentPage" keywords here.

Edited, Sep 09, 2020 13:44
Sanjay Kumar - Sep 09, 2020 14:04
Use your "page " place of "block" and "NodeContent" place of "ProductContentPage".
Ash - Sep 09, 2020 14:12
No its not working sanjay.
This code giving me error.
Sanjay Kumar - Sep 09, 2020 14:15
Have you created Products from Commerce-->Catalog area?
Ash - Sep 09, 2020 14:24
I have to check it.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.