Search in sources :

Example 1 with CategoryXref

use of org.broadleafcommerce.core.catalog.domain.CategoryXref in project BroadleafCommerce by BroadleafCommerce.

the class CategoryParentCategoryFieldPersistenceProvider method getDefaultCategory.

protected Category getDefaultCategory(Category category) {
    Category response = null;
    List<CategoryXref> xrefs = category.getAllParentCategoryXrefs();
    if (!CollectionUtils.isEmpty(xrefs)) {
        for (CategoryXref xref : xrefs) {
            if (xref.getCategory().isActive() && xref.getDefaultReference() != null && xref.getDefaultReference()) {
                response = xref.getCategory();
                break;
            }
        }
    }
    return response;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 2 with CategoryXref

use of org.broadleafcommerce.core.catalog.domain.CategoryXref in project BroadleafCommerce by BroadleafCommerce.

the class CategoryXrefDaoImpl method readXrefByIds.

@Override
public CategoryXref readXrefByIds(Long categoryId, Long subCategoryId) {
    Query query = em.createNamedQuery("BC_READ_CATEGORY_XREF_BY_IDS");
    query.setParameter("categoryId", categoryId);
    query.setParameter("subCategoryId", subCategoryId);
    return (CategoryXref) query.getSingleResult();
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 3 with CategoryXref

use of org.broadleafcommerce.core.catalog.domain.CategoryXref in project BroadleafCommerce by BroadleafCommerce.

the class CategoryCustomPersistenceHandler method setupXref.

protected void setupXref(Category adminInstance) {
    if (isDefaultCategoryLegacyMode()) {
        CategoryXref categoryXref = new CategoryXrefImpl();
        categoryXref.setCategory(getExistingDefaultCategory(adminInstance));
        categoryXref.setSubCategory(adminInstance);
        if (!adminInstance.getAllParentCategoryXrefs().contains(categoryXref) && categoryXref.getCategory() != null) {
            adminInstance.getAllParentCategoryXrefs().add(categoryXref);
        }
    }
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 4 with CategoryXref

use of org.broadleafcommerce.core.catalog.domain.CategoryXref in project BroadleafCommerce by BroadleafCommerce.

the class ChildCategoriesCustomPersistenceHandler method createXref.

protected CategoryXref createXref(Tuple<Category, Category> parentAndChild) {
    CategoryXref xref = new CategoryXrefImpl();
    xref.setCategory(parentAndChild.getFirst());
    xref.setSubCategory(parentAndChild.getSecond());
    return xref;
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 5 with CategoryXref

use of org.broadleafcommerce.core.catalog.domain.CategoryXref in project BroadleafCommerce by BroadleafCommerce.

the class ChildCategoriesCustomPersistenceHandler method checkCategoryAncestry.

protected void checkCategoryAncestry(Category category, Set<Category> knownAncestors) {
    List<CategoryXref> parentXrefs = ListUtils.emptyIfNull(category.getAllParentCategoryXrefs());
    knownAncestors.add(category);
    for (CategoryXref parentXref : parentXrefs) {
        final Category parentCategory = parentXref.getCategory();
        if (!knownAncestors.contains(parentCategory)) {
            checkCategoryAncestry(parentCategory, knownAncestors);
        }
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Aggregations

CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)10 Category (org.broadleafcommerce.core.catalog.domain.Category)6 CategoryXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 Media (org.broadleafcommerce.common.media.domain.Media)1 MediaImpl (org.broadleafcommerce.common.media.domain.MediaImpl)1 Money (org.broadleafcommerce.common.money.Money)1 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)1 CategoryMediaXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl)1 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)1 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)1