Search in sources :

Example 46 with Category

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 "";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 47 with Category

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;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) HashMap(java.util.HashMap) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 48 with Category

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 "";
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 49 with Category

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;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) SearchCriteria(org.broadleafcommerce.core.search.domain.SearchCriteria)

Aggregations

Category (org.broadleafcommerce.core.catalog.domain.Category)49 Product (org.broadleafcommerce.core.catalog.domain.Product)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)13 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)8 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)7 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)7 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)7 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 ArrayList (java.util.ArrayList)6 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)6 CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)6 Money (org.broadleafcommerce.common.money.Money)5 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Customer (org.broadleafcommerce.profile.core.domain.Customer)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)4 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 Calendar (java.util.Calendar)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3