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 (Assigned) (JIRA)" <ji...@apache.org> on 2012/01/20 18:36:39 UTC
[jira] [Assigned] (OFBIZ-4580) Categories - calculated trails
[ https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jacques Le Roux reassigned OFBIZ-4580:
--------------------------------------
Assignee: Jacques Le Roux
> 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
>
>
> 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