Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.

 

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

Ash
Ash
Vote:
 

Hi all,

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

#227643
Sep 09, 2020 11:31
Vote:
 

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))
                    {
                        productContentPages.Add(productContentPage);
                    }
                }                
            }
#227644
Sep 09, 2020 13:17
Ash
Vote:
 

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.

#227645
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.