Ask - Test
Custom Product Renderer
Tom Jacobs, modified 6 Years ago.
Custom Product Renderer
New Member Posts: 12 Join Date: 3/11/19 Recent Posts
Hi,
I'm trying to create a Custom Product Renderer. I followed these steps from the documentation (which is very limited IMO), but no success: https://commerce.liferay.dev/developer-guide/-/knowledge_base/developer/creating-a-custom-product-renderer
This is the code for my Custom Renderer class:
@Component(
immediate = true,
property = {
"commerce.product.content.renderer.key=" + BooksRenderer.KEY,
"commerce.product.content.renderer.order=" + Integer.MIN_VALUE,
"commerce.product.content.renderer.type=" + SimpleCPTypeConstants.NAME
},
service = CPContentRenderer.class
)
public class BooksRenderer implements CPContentRenderer {
public static final String KEY = "MyKey";
@Reference
private BooksRendererViewHelper viewHelper;
@Override
public String getKey() {
return KEY;
}
@Override
public String getLabel(Locale locale) {
ResourceBundle resourceBundle = ResourceBundleUtil.getBundle(
"content.Language", locale, getClass());
return LanguageUtil.get(resourceBundle, KEY);
}
@Override
public void render(CPCatalogEntry cpCatalogEntry, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
httpServletRequest.setAttribute(
BooksRendererConstants.VIEW_HELPER, viewHelper);
_jspRenderer.renderJSP(_servletContext, httpServletRequest, httpServletResponse, "/render/view.jsp");
}
@Reference
private JSPRenderer _jspRenderer;
@Reference(
target = "(osgi.web.symbolicname=be.amatron.books.renderer)"
)
private ServletContext _servletContext;
}
My view.jsp page atm is just an empty page saying "test"
In the Product Publisher I can however not select my new, custom renderer.
What am I missing?
I'm trying to create a Custom Product Renderer. I followed these steps from the documentation (which is very limited IMO), but no success: https://commerce.liferay.dev/developer-guide/-/knowledge_base/developer/creating-a-custom-product-renderer
This is the code for my Custom Renderer class:
@Component(
immediate = true,
property = {
"commerce.product.content.renderer.key=" + BooksRenderer.KEY,
"commerce.product.content.renderer.order=" + Integer.MIN_VALUE,
"commerce.product.content.renderer.type=" + SimpleCPTypeConstants.NAME
},
service = CPContentRenderer.class
)
public class BooksRenderer implements CPContentRenderer {
public static final String KEY = "MyKey";
@Reference
private BooksRendererViewHelper viewHelper;
@Override
public String getKey() {
return KEY;
}
@Override
public String getLabel(Locale locale) {
ResourceBundle resourceBundle = ResourceBundleUtil.getBundle(
"content.Language", locale, getClass());
return LanguageUtil.get(resourceBundle, KEY);
}
@Override
public void render(CPCatalogEntry cpCatalogEntry, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
httpServletRequest.setAttribute(
BooksRendererConstants.VIEW_HELPER, viewHelper);
_jspRenderer.renderJSP(_servletContext, httpServletRequest, httpServletResponse, "/render/view.jsp");
}
@Reference
private JSPRenderer _jspRenderer;
@Reference(
target = "(osgi.web.symbolicname=be.amatron.books.renderer)"
)
private ServletContext _servletContext;
}
My view.jsp page atm is just an empty page saying "test"
In the Product Publisher I can however not select my new, custom renderer.
What am I missing?
Joshua St. Clair, modified 6 Years ago.
RE: Custom Product Renderer
New Member Posts: 5 Join Date: 6/16/16 Recent Posts
Hi Tom,
I feel your pain. I too struggled implementing my own custom product renderer.
I discovered that the documentation leaves out an important line. In your bnd.bnd, you need to specify a Web-ContextPath with your module name. In my case, my module was called wholesale-product-renderer so the line was:
Hopefully that is the missing piece for you like it was for me.
Let me know what your findings are.
I feel your pain. I too struggled implementing my own custom product renderer.
I discovered that the documentation leaves out an important line. In your bnd.bnd, you need to specify a Web-ContextPath with your module name. In my case, my module was called wholesale-product-renderer so the line was:
Web-ContextPath: /wholesale-product-renderer
Hopefully that is the missing piece for you like it was for me.
Let me know what your findings are.
Tom Jacobs, modified 6 Years ago.
RE: Custom Product Renderer
New Member Posts: 12 Join Date: 3/11/19 Recent Posts
Hi Joshua,
Thank you for your quick reply. I have added the line to my bnd.bnd file, but still no result. This is what my bnd.bnd file looks like now:
Bundle-Name: amatron-books-renderer
Bundle-SymbolicName: be.amatron.books.renderer
Bundle-Version: 1.0.0
Web-ContextPath: /amatron-books-renderer
I also added a screenshot of my folder structure, maybe there is something wrong there?
Edit: I did spot a mistake myself: the folder for my view.jsp should be "render" and not "renderer", but still I cannot find my custom renderer for the Product Publisher
Thank you for your quick reply. I have added the line to my bnd.bnd file, but still no result. This is what my bnd.bnd file looks like now:
Bundle-Name: amatron-books-renderer
Bundle-SymbolicName: be.amatron.books.renderer
Bundle-Version: 1.0.0
Web-ContextPath: /amatron-books-renderer
I also added a screenshot of my folder structure, maybe there is something wrong there?
Edit: I did spot a mistake myself: the folder for my view.jsp should be "render" and not "renderer", but still I cannot find my custom renderer for the Product Publisher
Attachments:
Tom Jacobs, modified 6 Years ago.
RE: Custom Product Renderer
New Member Posts: 12 Join Date: 3/11/19 Recent Posts
Ok, I discovered some more:
I was trying to create a Product List Renderer this time, implementing the CPContentListRenderer interface (again, didnt get it to work), but I also discovered that there is a CPContentListEntryRenderer. Maybe this is what I was looking for in the first place, since it acctualy apears in the dropdown under "Product Type Renderer". I'm still not entirely sure when to implement which interface, and what the required properties are, but it's a start.
I was trying to create a Product List Renderer this time, implementing the CPContentListRenderer interface (again, didnt get it to work), but I also discovered that there is a CPContentListEntryRenderer. Maybe this is what I was looking for in the first place, since it acctualy apears in the dropdown under "Product Type Renderer". I'm still not entirely sure when to implement which interface, and what the required properties are, but it's a start.
Marco Leo, modified 6 Years ago.
RE: Custom Product Renderer
New Member Posts: 18 Join Date: 2/13/17 Recent Posts
Hi TomCPContentListRenderer and CPContentListEntryRenderer can be used in combination or singularly.
CPContentListRenderer takes care of organizing the list of products, like in a grid, list, carousel, table, and so on.
CPContentListEntryRenderer takes care to render the single product abstract template in the list organized by the CPContentListRenderer.
CPContentRenderer is used to render the product just in the Product Detail Portlet.
This combination allows you to be able to reuse the same implementation of your product in different portlets: search results, product publisher, compare list.
Let me know if this clarifies the differentiation.
ThanksMarco
CPContentListRenderer takes care of organizing the list of products, like in a grid, list, carousel, table, and so on.
CPContentListEntryRenderer takes care to render the single product abstract template in the list organized by the CPContentListRenderer.
CPContentRenderer is used to render the product just in the Product Detail Portlet.
This combination allows you to be able to reuse the same implementation of your product in different portlets: search results, product publisher, compare list.
Let me know if this clarifies the differentiation.
ThanksMarco
Joshua St. Clair, modified 6 Years ago.
RE: Custom Product Renderer
New Member Posts: 5 Join Date: 6/16/16 Recent Posts
Hey Tom,
Sorry that you're still having trouble. I went ahead and uploaded my code for you in this github repository. It has the minimum amount of code you need to get your own Custom Product Renderer working. I hope referencing it helps you solve your issues and clarifies what needs to be overridden and extended.
https://github.com/JoshuaStClair/liferay-module-examples/tree/master/modules/commerce-custom-product-renderer
Sorry that you're still having trouble. I went ahead and uploaded my code for you in this github repository. It has the minimum amount of code you need to get your own Custom Product Renderer working. I hope referencing it helps you solve your issues and clarifies what needs to be overridden and extended.
https://github.com/JoshuaStClair/liferay-module-examples/tree/master/modules/commerce-custom-product-renderer
Ashish Kumar, modified 1 Year ago.
RE: RE: Custom Product Renderer
New Member Posts: 2 Join Date: 11/16/23 Recent PostsI used the same code for product publisher but instead of product
publisher custom renderer is working with product details
product
publisher -> configuration -> setup -> render selection
-> PRODUCT TYPE RENDERER -> Simple -> only default is coming
Product detail -> configuration -> render selection -> CUSTOM RENDERER -> custom, custom product renderer
so it's working with Product details, not with product publisher, is
it expected ?
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™