[
https://issues.apache.org/jira/browse/OFBIZ-4580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul Piper updated OFBIZ-4580:
------------------------------
Attachment: CategoryWorker-with-trail-export.patch
Attached you will find the patch for direct inclusion. It has been a while
since i did this, so my best guess is that we should add a proper and simple
service to wrap it around this function.
Either way, a usecase is as follows:
On any ecommerce system you may be required to export the way you need to
access a specific categoryId taken from its root. This is useful for exporting
a tree for data migration to another system, to create an easy way to print
breadcrumbs, or to later (in combination with modern search engines) create a
proper facceted index. The function attached provides the basic means for that.
> Categories - calculated trails
> ------------------------------
>
> Key: OFBIZ-4580
> URL: https://issues.apache.org/jira/browse/OFBIZ-4580
> Project: OFBiz
> Issue Type: Improvement
> Reporter: Paul Piper
> 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