*/
protected CatalogCategoryViewBean buildViewBeanCatalogCategory(final RequestData requestData, final AbstractCatalogCategory catalogCategory, final FetchPlan categoryFetchPlan, final FetchPlan productFetchPlan, final FetchPlan skuFetchPlan) throws Exception {
final MarketArea marketArea = requestData.getMarketArea();
final Localization localization = requestData.getMarketAreaLocalization();
final String localizationCode = localization.getCode();
final CatalogCategoryViewBean catalogCategoryViewBean = new CatalogCategoryViewBean();
if(catalogCategory != null){
catalogCategoryViewBean.setCode(catalogCategory.getCode());
catalogCategoryViewBean.setName(catalogCategory.getI18nName(localizationCode));
catalogCategoryViewBean.setDescription(catalogCategory.getDescription());
catalogCategoryViewBean.setRanking("" + catalogCategory.getRanking());
catalogCategoryViewBean.setRoot(catalogCategory.isRoot());
// ATTRIBUTES
List<AbstractAttribute> globalAttributes = catalogCategory.getGlobalAttributes();
if(globalAttributes != null){
for (Iterator<AbstractAttribute> iterator = globalAttributes.iterator(); iterator.hasNext();) {
AbstractAttribute attribute = (AbstractAttribute) iterator.next();
catalogCategoryViewBean.getGlobalAttributes().put(attribute.getAttributeDefinition().getCode(), buildViewBeanAttributeValue(requestData, attribute));
}
}
List<AbstractAttribute> marketAreaAttributes = catalogCategory.getMarketAreaAttributes(marketArea.getId());
if(marketAreaAttributes != null){
for (Iterator<AbstractAttribute> iterator = marketAreaAttributes.iterator(); iterator.hasNext();) {
AbstractAttribute attribute = (AbstractAttribute) iterator.next();
catalogCategoryViewBean.getMarketAreaAttributes().put(attribute.getAttributeDefinition().getCode(), buildViewBeanAttributeValue(requestData, attribute));
}
}
// ASSETS
final Asset defaultBackgroundImage = catalogCategory.getDefaultBackgroundImage();
if (defaultBackgroundImage != null) {
final String backgroundImage = engineSettingService.getCatalogImageWebPath(defaultBackgroundImage);
catalogCategoryViewBean.setBackgroundImage(backgroundImage);
} else {
catalogCategoryViewBean.setBackgroundImage("");
}
final Asset defaultSlideshowImage = catalogCategory.getDefaultSlideshowImage();
if (defaultSlideshowImage != null) {
final String slideshowImage = engineSettingService.getCatalogImageWebPath(defaultSlideshowImage);
catalogCategoryViewBean.setSlideshowImage(slideshowImage);
} else {
catalogCategoryViewBean.setBackgroundImage("");
}
final Asset defaultPackshotImage = catalogCategory.getDefaultPackshotImage(ImageSize.HD.getPropertyKey());
if (defaultPackshotImage != null) {
final String carouselImage = engineSettingService.getCatalogImageWebPath(defaultPackshotImage);
catalogCategoryViewBean.setCarouselImage(carouselImage);
} else {
catalogCategoryViewBean.setCarouselImage("");
}
final Asset defaultIconImage = catalogCategory.getDefaultThumbnailImage();
if (defaultIconImage != null) {
final String iconImage = engineSettingService.getCatalogImageWebPath(defaultIconImage);
catalogCategoryViewBean.setIconImage(iconImage);
} else {
catalogCategoryViewBean.setIconImage("");
}
if (catalogCategory.isRoot()) {
catalogCategoryViewBean.setProductAxeUrl(urlService.generateUrl(FoUrls.CATEGORY_AS_AXE, requestData, catalogCategory));
} else {
catalogCategoryViewBean.setProductLineUrl(urlService.generateUrl(FoUrls.CATEGORY_AS_LINE, requestData, catalogCategory));
}
// PARENT CATEGORY
if (catalogCategory != null && catalogCategory.getParentCatalogCategory() != null
&& Hibernate.isInitialized(catalogCategory.getParentCatalogCategory())) {
catalogCategoryViewBean.setDefaultParentCategory(buildViewBeanCatalogCategory(requestData, (AbstractCatalogCategory) catalogCategory.getParentCatalogCategory(), null, null, null));
}
// SUB CATEGORIES
List<CatalogCategoryViewBean> subcatalogCategoryVirtualViewBeans = new ArrayList<CatalogCategoryViewBean>();
final List<AbstractCatalogCategory> subCategories = catalogCategory.getSortedChildCatalogCategories();
if (subCategories != null) {
if (categoryFetchPlan != null) {
for (Iterator<AbstractCatalogCategory> iteratorSubcatalogCategoryVirtual = subCategories.iterator(); iteratorSubcatalogCategoryVirtual.hasNext();) {
final CatalogCategoryVirtual subcatalogCategoryVirtual = (CatalogCategoryVirtual) iteratorSubcatalogCategoryVirtual.next();
final CatalogCategoryVirtual reloadedSubCatalogCategory = catalogCategoryService.getVirtualCatalogCategoryById(subcatalogCategoryVirtual.getId(), categoryFetchPlan);
subcatalogCategoryVirtualViewBeans.add(buildViewBeanVirtualCatalogCategory(requestData, reloadedSubCatalogCategory, categoryFetchPlan, productFetchPlan, skuFetchPlan));
}
}
catalogCategoryViewBean.setCountSubCategories(subCategories.size());
}
catalogCategoryViewBean.setSubCategories(subcatalogCategoryVirtualViewBeans);
// PRODUCTS
List<ProductMarketingViewBean> productMarketingViewBeans = new ArrayList<ProductMarketingViewBean>();
List<ProductMarketingViewBean> featuredProductMarketings = new ArrayList<ProductMarketingViewBean>();
final List<ProductSku> productSkus = catalogCategory.getSortedProductSkus();
if (productSkus != null) {
if (productFetchPlan != null) {
for (Iterator<ProductSku> iteratorProductMarketing = productSkus.iterator(); iteratorProductMarketing.hasNext();) {
final ProductSku productSku = (ProductSku) iteratorProductMarketing.next();
final ProductSku reloadedProductSku = productService.getProductSkuByCode(productSku.getCode(), skuFetchPlan);
final ProductMarketing productMarketing = productService.getProductMarketingByCode(reloadedProductSku.getProductMarketing().getCode(), productFetchPlan);
ProductMarketingViewBean productMarketingViewBean = buildViewBeanProductMarketing(requestData, catalogCategory, productMarketing, reloadedProductSku);
productMarketingViewBeans.add(productMarketingViewBean);
if (productMarketing.isFeatured()) {
featuredProductMarketings.add(productMarketingViewBean);
}
}
}
catalogCategoryViewBean.setCountProductMarketings(catalogCategory.getSortedProductMarketings().size());
}
catalogCategoryViewBean.setProductMarketings(productMarketingViewBeans);
// FEATURED PRODUCTS
for (CatalogCategoryViewBean subcatalogCategoryVirtualViewBean : subcatalogCategoryVirtualViewBeans) {
featuredProductMarketings.addAll(subcatalogCategoryVirtualViewBean.getFeaturedProductMarketings());
}
catalogCategoryViewBean.setFeaturedProductMarketings(featuredProductMarketings);
}
return catalogCategoryViewBean;
}