RE: RE: Widget Template (Search Results)

thumbnail
Jamie Sammons, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Hello, I'm creating a Widget Template (Search Results Template). I'm working with CPCatalogEntry and CPDefinitionLocalService classes and I'm wondering how to get the list of specifications of a product.

Liferay Community Edition Portal 7.4.3.13 CE GA13

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Hi Gennaro, is your question really about ow to use the CP services and models to get all product specifications, or is there something about doing it in a Widget Template for the Search Results widget that is giving you trouble? 

thumbnail
Jamie Sammons, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Hello Russell, thank you for your interest. No, I'm not getting troubles because I'm doing it in a Widget Template.

I actually don't know how to get the specifications list starting from a product (CPCatalogEntry object). In particular my question was about the widget because in it I have this CPCatalogEntry list:

<#if entries?has_content>
	<#list entries as curCPCatalogEntry>
	       //do something
	</#list>
</#if>

 

thumbnail
Jamie Sammons, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

I did it! this is the my code to get specifications:

<#if entries?has_content>

	<#list entries as curCPCatalogEntry>
		<#assign CPDefinitionLocalService = serviceLocator.findService("com.liferay.commerce.product.service.CPDefinitionLocalService")
			
			CPDefinition = CPDefinitionLocalService.getCPDefinition(curCPCatalogEntry.getCPDefinitionId())
			CPDefinitionSpecificationOptionValues = CPDefinition.getCPDefinitionSpecificationOptionValues()
		/>
		
		<#list CPDefinitionSpecificationOptionValues as cpdsov>
			<#assign cpSpecificationOption = cpdsov.getCPSpecificationOption() />
			<span>${cpSpecificationOption.getTitle(locale)}</span>
			<span>${cpdsov.getValue()}</span>
		</#list>
		
	</#list>
</#if>

 

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Great! You could make an answer with same content as your last comment, then accept it as the answer.

thumbnail
Jamie Sammons, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

I did it! this is my code to get specifications:

<#if entries?has_content>

	<#list entries as curCPCatalogEntry>
		<#assign CPDefinitionLocalService = serviceLocator.findService("com.liferay.commerce.product.service.CPDefinitionLocalService")
			
			CPDefinition = CPDefinitionLocalService.getCPDefinition(curCPCatalogEntry.getCPDefinitionId())
			CPDefinitionSpecificationOptionValues = CPDefinition.getCPDefinitionSpecificationOptionValues()
		/>
		
		<#list CPDefinitionSpecificationOptionValues as cpdsov>
			<#assign cpSpecificationOption = cpdsov.getCPSpecificationOption() />
			<span>${cpSpecificationOption.getTitle(locale)}</span>
			<span>${cpdsov.getValue()}</span>
		</#list>
		
	</#list>
</#if>