GetProducts function return duplicated products
Hi,
I used function GetProducts().ToList(); to get all products butI got duplicated products with different IDs. What is correct data I should get.
Thanks
Hi,
The reason for this is that when you use GetProducts() you are getting all products in both with Live and Master state. You need to specify whether you want the master version of the item or the live version (the version that is currently published) like so:
.GetProducts().Where(i => i.Status = ContentLifecycleStatus.Live && i.Visibility = true);
The above with get all the live products that are visible (note that you can have a live version that has been unpublished so to only get the live item versions that are published you need to set the visibility = true)
You might like to read this article to get some background info: docs.sitefinity.com/for-developers-content-lifecycle
Regards,
Seth Cleaver
Telerik