You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by "Jacques Le Roux (Commented) (JIRA)" <ji...@apache.org> on 2012/01/29 16:47:09 UTC

[jira] [Commented] (OFBIZ-4580) Categories - calculated trails

    [ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13195769#comment-13195769 ] 

Jacques Le Roux commented on OFBIZ-4580:
----------------------------------------

BTW, here are comments from Kiran on dev ML

{quote}
Hello Paul,

I agree that having such function to generate the trail would be useful. 
But this is an expensive operation (not sure if it would hit the cache) as 
it recursively lookups the parent category by doing query. A comment 
should be added to make it clear to user.

When possible, you should set category_id and pcategory. These are used to 
update the trail (see setTrail). setTrail can be called from anywhere as 
below:

curCategoryId = parameters.category_id ?: parameters.CATEGORY_ID ?: "";
CategoryWorker.setTrail(request, curCategoryId);

Cheers,
Kiran
{quote}


                
> Categories - calculated trails
> ------------------------------
>
>                 Key: OFBIZ-4580
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-4580
>             Project: OFBiz
>          Issue Type: Improvement
>            Reporter: Paul Piper
>            Assignee: Jacques Le Roux
>            Priority: Minor
>         Attachments: CategoryWorker-with-trail-export.patch, CategoryWorker.patch, OFBIZ-4580-CategoryWorker-with-trail-export.patch
>
>
> Hey folks,
> been a while since I contributed. I noticed that currently ofbiz misses a simple function to generate a category trail. Generating a trail, however, is often useful when generating breadcrums, facetted search results, and proper category trees in general. Hence I created the following as a timesaver:
> {code:title=getCategoryTrail|borderStyle=solid}
> public static  List getCategoryTrail(String productCategoryId,DispatchContext dctx){
> 		GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
> 		List<String> trailElements = FastList.newInstance();
>         trailElements.add(productCategoryId);
>         String parentProductCategoryId = productCategoryId;
>         while (UtilValidate.isNotEmpty(parentProductCategoryId)) {
>             // find product category rollup
>             try {
>                 List<EntityCondition> rolllupConds = FastList.newInstance();
>                 rolllupConds.add(EntityCondition.makeCondition("productCategoryId", parentProductCategoryId));
>                 rolllupConds.add(EntityUtil.getFilterByDateExpr());
>                 List<GenericValue> productCategoryRollups = delegator.findList("ProductCategoryRollup", EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("-fromDate"), null, true);
>                 if (UtilValidate.isNotEmpty(productCategoryRollups)) {
>                     // add only categories that belong to the top category to trail
>                     for (GenericValue productCategoryRollup : productCategoryRollups) {
>                         String trailCategoryId = productCategoryRollup.getString("parentProductCategoryId");
>                         parentProductCategoryId = trailCategoryId;
>                         if (trailElements.contains(trailCategoryId)) {
>                             break;
>                         }else{
>                         	trailElements.add(trailCategoryId);
>                         }
>                     }
>                 } else {
>                     parentProductCategoryId = null;
>                 }
>             } catch (GenericEntityException e) {
>                 Debug.logError(e, "Cannot generate trail from product category", module);
>             }
>         }
>         Collections.reverse(trailElements);
>         return trailElements;
> 	}
> {code}
> I suggest to add this to the CategoryWorker.java

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira