|
Home > Archive > WebSphere Commerce suite > February 2006 > Determining A Parent Category from a Product
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Determining A Parent Category from a Product
|
|
|
| Hi,
I am using WebSphere Commerce Express Developer 5.6.1 on Windows 2000.
I am having trouble determing the Parent Category for a Product/Item
I've noticed that the starterstores pass the parameter 'parent_category_rn=blah' and the ProductDisplay pages use this parameter to determine a Parent Category. Is there any way to determine the Parent Category if this parameter is not present. Eg when a
Product/Item is returned from a search.
I have tried to access the parent ids using the following code in the CachedProductOnlyDisplay.jsp
<c:set var="parentId" value="${product.parentCatalogEntryIds[0].categoryId}"/>
Though the String[] returned from parentCatalogEntryIds is empty. Do I need to call another method for the ProductDataBean to retrieve the parent ID's from the CATENTREL table?
Any help would be greatly appreciated,
Cheers,
Peter O'Neill
| |
|
| the code snippet did not display so here it is again without jstl formatting...
'c:set var="parentId" value="${ product.parentCatalogEntryIds[0].categoryId }" '
| |
|
| Peter,
You are definitely on the wrong track there. The method getParentCatalogEntryIds will return an array of Strings, representing the parent catalog ENTRIES. A catalog entry is a product, item, package or bundle. The use for this API is that you can retrieve
a list of the products for which the current item is a child. Under normal circumstances this should be a list of zero or one elements, but the data model allows for more than one parent.
I don't know of any catalog entry bean methods that will retrieve the parent categories (in a sales catalog, there can be more than one). You can use the finder methods on the CatalogGroupCatalogEntryRelationAccessBe
an to retrieve that list for a catalog
entry. I suggest you build that into a data bean to make the JSP simpler. You might find a problem with those finder methods, though, as they do not seem to take the catalog into consideration. You must thus subsequently filter away hits that does not per
tain to your current catalog. Bummer.
| |
|
| Hi,
I've been able to use the CatalogGroupCatalogEntryRelationAccessBe
an bean to determine the Parent Catalog Group Id. As you mention is would be neater to use a DataBean. I've tried the to use the com.ibm.commerce.catalog.beans.CatalogGroupCatalogEntryRela
tionDataBean
with the following code, but receive a null pointer error.
' wcbase:useBean id="parentCategoryGroupRel" classname="com.ibm.commerce.catalog.beans. CatalogGroupCatalogEntryRelationDataBean
" >
' c:set property="dataBeanKeyCatalogEntryId" value="${WCParam.productId}" target="${parentCategoryGroupRel}" />
'/wcbase:useBean>
The error is
CMN0420E: The following command exception has occurred during processing: "java.lang.NullPointerException".java.lang.NullPointerException
at com.ibm.commerce.catalog.objects.CatalogGroupCatalogEntryRelationKey. hashCode(CatalogGroupCatalogEntryRelatio
nKey.java:50)
at com.ibm.commerce.catalog.objects. LiteCatalogGroupCatalogEntryRelationCont
ainerObject. findByPrimaryKey(LiteCatalogGroupCatalog
EntryRelationContainerObject.java:211)
at com.ibm.commerce.catalog.objects. LiteCatalogGroupCatalogEntryRelationHome
. findByPrimaryKey(LiteCatalogGroupCatalog
EntryRelationHome.java:37)
at com.ibm.commerce.catalog.objects. CatalogGroupCatalogEntryRelationAccessBe
an. instantiateEJB(CatalogGroupCatalogEntryR
elationAccessBean.java:160)
at com.ibm.ivj.ejb.runtime.AbstractEntityAccessBean._instantiate(AbstractEntityAccessBean.java:165)
at com.ibm.ivj.ejb.runtime.AbstractEntityAccessBean. refreshCopyHelper(AbstractEntityAccessBe
an.java:304)
at com.ibm.commerce.catalog.objects. CatalogGroupCatalogEntryRelationAccessBe
an. refreshCopyHelper(CatalogGroupCatalogEnt
ryRelationAccessBean.java:218)
at com.ibm.commerce.catalog.beans. CatalogGroupCatalogEntryRelationDataBean
. populate(CatalogGroupCatalogEntryRelatio
nDataBean.java:133)
at com.ibm.commerce.beans.DataBeanManager.directActivate(DataBeanManager.java:294)
at com.ibm.commerce.beans.DataBeanManager.activate(DataBeanManager.java:102)
at com.ibm.commerce.beans.DataBeanManager.activate(DataBeanManager.java:199)
at com.ibm.commerce.taglibs.base.tag.UseBean.doEndTag(UseBean.java:99)
at org.apache.jsp._CachedProductOnlyDisplay._jspService(_CachedProductOnlyDisplay.java:2058)
Any help pointing me in the right direction would be very much appreciated.
Cheer
Peter O'Neill
| |
|
| I guess what the generated access bean code is trying to tell you is that not all the key fields has been set. The useBean tag attempts to instantiate a single relationship bean, which would require all primary key fields to be set.
What I mean by using a data bean was to make one yourself. That is, make a data bean that you can instantiate with the useBean tag that will retrieve the desired values.
What I suggest is that you make a SmartDataBean implementation that has a childCatalogEntryId property and which, in its populate method will use the CatalogGroupCatalogEntryRelationAccessBe
an's finder methods to retrieve the "best candidate" for a parent
catalog group. Something like this:
<pre>
public class MyParentCatalogFinder extends com.ibm.commerce.beans.SmartDataBeanImpl {
private Long childCatalogEntryId;
private CatalogGroupDataBean parentCatalogEntry;
public setChildCatalogEntryId(Long childCatalogEntryId) {
this.childCatalogEntryId = childCatalogEntryId;
}
public CatalogGroupDataBean getParentCatalogEntry() {
return parentCatalogEntry;
}
public void populate() {
...code to retrieve parent and populate the parentCatalogEntry field...
}
}
</pre>
The bean could then be used somewhat like this:
<pre>
<wcbase:useBean id="parentCategoryFinder" classname="mypackage.MyParentCatalogFinder">
<c:set property="childCatalogEntryId" value="${WCParam.productId}" target="${parentCategoryFinder}" />
</wcbase:useBean>
Parent category name: <c:out value="${parentCategoryFinder.parentCatalogEntry.name}" />
</pre>
| |
|
| > I guess what the generated access bean code is trying
> to tell you is that not all the key fields has been
> set. The useBean tag attempts to instantiate a single
> relationship bean, which would require all primary
> key fields to be set.
>
> What I mean by using a data bean was to make one
> yourself. That is, make a data bean that you can
> instantiate with the useBean tag that will retrieve
> the desired values.
>
> What I suggest is that you make a SmartDataBean
> implementation that has a childCatalogEntryId
> property and which, in its populate method will use
> the CatalogGroupCatalogEntryRelationAccessBe
an's
> finder methods to retrieve the "best candidate" for a
> parent catalog group. Something like this:
>
> <pre>
> public class MyParentCatalogFinder extends
> com.ibm.commerce.beans.SmartDataBeanImpl {
> private Long childCatalogEntryId;
> private CatalogGroupDataBean parentCatalogEntry;
> public setChildCatalogEntryId(Long
> ng childCatalogEntryId) {
> this.childCatalogEntryId = childCatalogEntryId;
> }
> public CatalogGroupDataBean getParentCatalogEntry()
> () {
> return parentCatalogEntry;
> }
> public void populate() {
> ...code to retrieve parent and populate the
> the parentCatalogEntry field...
> }
> }
> </pre>
>
> The bean could then be used somewhat like this:
>
> <pre>
> <wcbase:useBean id="parentCategoryFinder"
> classname="mypackage.MyParentCatalogFinder">
>
> <c:set property="childCatalogEntryId"
> d" value="${WCParam.productId}"
> target="${parentCategoryFinder}" />
>
> </wcbase:useBean>
>
> Parent category name: <c:out
> value="${parentCategoryFinder.parentCatalogEntry.name}
> " />
> </pre>
Hi,
You can find the parent category by using findByCatalogEntryId method of CatalogGroupCatalogEntryRelationAccessBe
an, by passing the catentryId to it.
It returns a list of parents as one product can belong to more than one category(list may have only one or more than one depending on your catalog).
Pl. see the sample code below.
parentCategoriesEnu = new CatalogGroupCatalogEntryRelationAccessBe
an().findByCatalogEntryId(new Long(catEntryId));
if (parentCategoriesEnu != null) {
while(parentCategoriesEnu.hasMoreElements()){
cgceRelationAB= (CatalogGroupCatalogEntryRelationAccessB
ean)parentCategoriesEnu.nextElement();
categoryId=cgceRelationAB.getCatalogGroupId();
pageContext.setAttribute("categoryId",categoryId);
}
}
Then you can careate a category Bean as you have the categoryId using jstl tags.
Hope this helps.
Ganesh.
|
|
|
|
|