Matching content selected Id to database list of items

Posted by Community Admin on 05-Aug-2018 16:39

Matching content selected Id to database list of items

All Replies

Posted by Community Admin on 19-Jul-2016 00:00

I have created a module Products and content type product.  I am creating a custom widget to display a single product. I have setup my designer and once I drop the widget on a page I can select from the product list using the sf-list-selector sf-dynamic-items-selector.  My issue is matching that item ID to the list of products my widget is pulling up.  Here is the code the widget uses to retrieve all products:

 

var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
var contentType = TypeResolutionService.ResolveType(typeName);
var contentElements = dynamicModuleManager.GetDataItems(contentType).Where(x => x.Status == ContentLifecycleStatus.Live);
 
products = contentElements.ToArray().Select(p => new ItemViewModel(p)).ToArray();

 

This works good and pulls up the list of products.  The question is how to filter this list using the selected product id from the designer.  I have this and they don't match:

products.Single(p => p.DataItem.Id == Guid.Parse(selectedProductId))

How do I go from the ItemViewModel to the Id the selector is giving me?

 

using Feather 9.1

Posted by Community Admin on 19-Jul-2016 00:00

Instead of getting a list of itemviewmodel first, did so:

 

var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
var contentType = TypeResolutionService.ResolveType(typeName);
var contentElement = dynamicModuleManager.GetDataItem(contentType, Guid.Parse(selectedProductId));
product =  new ItemViewModel(dynamicModuleManager.Lifecycle.GetLive(contentElement));

 

Ps: Apparently the dynamic selector returns the Id of the master version of the content which I did not understand initially what Id it was returning. 

This thread is closed