My first attempt of structuring a coldbox handler for nested pages.
My “viewCategoryProductList” event calls other methods within the handler which generate HTML (first they call methods to load the required data into the event)
The HTML is then added to the event and finally at the end rendered into a layout.
I have tried to make each HTML generation method reusable so that multiple templates can use them in the future.
Please take a look at let me know if there is a better way of achieving this.
Hopefully I have not going down the completely wrong route!
Thanks very much
Alex
public function viewCategoryProductList(event,rc,prc,numeric intSelectedCategoryID){
//Announce interception
announceInterception(‘DisplayCategoryProducts’);
//Bread crumb
event.setValue(‘strBreadCrumbTrailHTML’, getBreadCrumbHTML(event,rc,prc));
//setProductSearchHTML
event.setValue(‘strProductSearchHTML’, getProductSearchHTML(event,rc,prc));
//Get the sub category HTML
event.setValue(‘strSubCategoryHTML’, getSubCategoryHTML(event,rc,prc));
//Set the product list to be the main view
setProductListData(event,rc,prc);
event.setView(‘coldbox/productlist/productlist’);
//Bread crumb
event.setLayout(‘category/categorylist’);
}
public function setProductSearchData(event,rc,prc){
//Get root node
event.setValue(‘rsActiveSuppliers’, objSupplierService.getActiveUnBlockedSuppliers());
//Get the root parent sub categories
event.paramValue(‘intSelectedCategoryID’, variables.objCategoryService.getRootNode());
local.intSelectedCategoryID = event.getValue(‘intSelectedCategoryID’);
event.paramValue(‘blnGetSubCategoryChildren’, 0);
local.blnGetSubCategoryChildren = event.getValue(‘blnGetSubCategoryChildren’);
event.setValue(‘objCategory’, variables.objCategoryService.getCategoryWithImmediateSubCategories(
intParentCategoryID = local.intSelectedCategoryID
, blnGetSubCategoryChildren = local.blnGetSubCategoryChildren
));
}
public string function getProductSearchHTML(event,rc,prc){
setProductSearchData();
return renderView(‘coldbox/productlist/search’);
}
public function setBreadCrumbData(event,rc,prc){
event.paramValue(‘intSelectedCategoryID’, variables.objCategoryService.getRootNode());
local.intSelectedCategoryID = event.getValue(‘intSelectedCategoryID’);
local.objProductCategeoryLegacyCFC = new epsys.legacy.cfcs.product_cats();
local.stuBreadCrumbTrail = objProductCategeoryLegacyCFC.getBreadCrumb(local.intSelectedCategoryID);
event.setValue(‘stuBreadCrumbTrail’, local.stuBreadCrumbTrail );
}
public string function getBreadCrumbHTML(event,rc,prc){
setBreadCrumbData();
return renderView(‘coldbox/productlist/breadcrumbtrail’);
}
public string function setSubCategoryData(event,rc,prc){
local.intSelectedCategoryID = event.getValue(‘intSelectedCategoryID’, variables.objCategoryService.getRootNode());
//Get the sub categories based on the selected category id
local.stuCategoryHolder = variables.objCategoryService.getParentSubCategoriesForOutput(
intParentID=local.intSelectedCategoryID
);
event.setValue(‘stuCategoryHolder’, local.stuCategoryHolder);
event.setValue(‘strSubCategoryHTML’, renderView(‘coldbox/category/subcategories’));
}
public string function getSubCategoryHTML(event,rc,prc){
setSubCategoryData();
return renderView(‘coldbox/category/subcategories’);
}
public string function setProductListData(event,rc,prc){
}