use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class CatalogRelativeHrefProcessor method buildRelativeHref.
protected String buildRelativeHref(String tagName, Map<String, String> tagAttributes, String attributeName, String attributeValue, BroadleafTemplateContext context) {
Object result = context.parseExpression(attributeValue);
HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest();
String currentUrl = request.getRequestURI();
if (request.getQueryString() != null) {
currentUrl = currentUrl + "?" + request.getQueryString();
}
if (result instanceof Product) {
return catalogURLService.buildRelativeProductURL(currentUrl, (Product) result);
} else if (result instanceof Category) {
return catalogURLService.buildRelativeCategoryURL(currentUrl, (Category) result);
}
return "";
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class CategoriesProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
String resultVar = tagAttributes.get("resultVar");
String parentCategory = tagAttributes.get("parentCategory");
String unparsedMaxResults = tagAttributes.get("maxResults");
Map<String, Object> newModelVars = new HashMap<>();
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findAllPossibleChildCategories(parentCategory, unparsedMaxResults, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
newModelVars.put(resultVar, holder.getResult());
return newModelVars;
}
}
// TODO: Potentially write an algorithm that will pick the minimum depth category
// instead of the first category in the list
List<Category> categories = catalogService.findCategoriesByName(parentCategory);
if (categories != null && categories.size() > 0) {
// gets child categories in order ONLY if they are in the xref table and active
List<CategoryXref> subcategories = categories.get(0).getChildCategoryXrefs();
List<Category> results = Collections.emptyList();
if (subcategories != null && !subcategories.isEmpty()) {
results = new ArrayList<>(subcategories.size());
if (StringUtils.isNotEmpty(unparsedMaxResults)) {
int maxResults = Integer.parseInt(unparsedMaxResults);
if (subcategories.size() > maxResults) {
subcategories = subcategories.subList(0, maxResults);
}
}
for (CategoryXref xref : subcategories) {
results.add(xref.getSubCategory());
}
}
newModelVars.put(resultVar, results);
}
return newModelVars;
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class SeoDefaultPropertyServiceImpl method getProductTitlePattern.
@Override
public String getProductTitlePattern(Product product) {
try {
Category category = product.getCategory();
String pattern = category.getProductTitlePatternOverride();
if (StringUtils.isEmpty(pattern)) {
pattern = env.getProperty("seo.product.title.pattern");
}
return pattern;
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
return "";
}
}
use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.
the class MvelToSearchCriteriaConversionServiceImpl method convert.
@Override
public SearchCriteria convert(String mvelRule) {
SearchCriteria criteria = new SearchCriteria();
criteria.setPageSize(Integer.MAX_VALUE);
if (isCustomFieldTargetingRule(mvelRule)) {
String customFieldQuery = buildCustomFieldQuery(mvelRule);
criteria.setQuery(customFieldQuery);
} else if (isCategoryTargetingRule(mvelRule)) {
Long categoryId = getCategoryId(mvelRule);
Category category = catalogService.findCategoryById(categoryId);
criteria.setCategory(category);
} else {
throw new UnsupportedOperationException("The provided MVEL rule format is not currently supported " + "for MVEL to Solr Search Criteria conversion.");
}
return criteria;
}
Aggregations