Search in sources :

Example 31 with Category

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

the class ProductParentCategoryFieldPersistenceProvider method checkDirtyState.

protected boolean checkDirtyState(Product instance, Long checkValue) {
    boolean dirty = !(instance == null && checkValue == null) && (instance == null || checkValue == null);
    if (!dirty) {
        Long value = null;
        Category category = getDefaultCategory(instance);
        if (category != null) {
            value = category.getId();
        }
        dirty = value == null || !value.equals(checkValue);
    }
    return dirty;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 32 with Category

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

the class ProductDaoImpl method readFilteredActiveProductsByCategoryInternal.

protected List<Product> readFilteredActiveProductsByCategoryInternal(Long categoryId, Date currentDate, SearchCriteria searchCriteria) {
    // Set up the criteria query that specifies we want to return Products
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
    // The root of our search is Category since we are browsing
    Root<CategoryProductXrefImpl> productXref = criteria.from(CategoryProductXrefImpl.class);
    // We want to filter on attributes from product and sku
    Join<CategoryProductXref, Product> product = productXref.join("product");
    Join<Product, Sku> sku = product.join("defaultSku");
    Join<CategoryProductXref, Category> category = productXref.join("category");
    // Product objects are what we want back
    criteria.select(product);
    // We only want results from the determine category
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(category.get("id").in(sandBoxHelper.mergeCloneIds(CategoryImpl.class, categoryId)));
    attachSearchCriteria(searchCriteria, product, sku, restrictions);
    attachActiveRestriction(currentDate, product, sku, restrictions);
    attachOrderBy(searchCriteria, product, sku, criteria);
    // Execute the query with the restrictions
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    TypedQuery<Product> typedQuery = em.createQuery(criteria);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Predicate(javax.persistence.criteria.Predicate) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 33 with Category

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

the class CategorySiteMapGenerator method addCategorySiteMapEntries.

protected void addCategorySiteMapEntries(Category parentCategory, int currentDepth, CategorySiteMapGeneratorConfiguration categorySMGC, SiteMapBuilder siteMapBuilder) {
    // If we've reached beyond the ending depth, don't proceed
    if (currentDepth > categorySMGC.getEndingDepth()) {
        return;
    }
    // If we're at or past the starting depth, add this category to the site map
    if (currentDepth >= categorySMGC.getStartingDepth()) {
        constructSiteMapURLs(categorySMGC, siteMapBuilder, parentCategory);
    }
    // Recurse on child categories in batches of size rowLimit
    int rowOffset = 0;
    List<Category> categories;
    do {
        categories = categoryDao.readActiveSubCategoriesByCategory(parentCategory, rowLimit, rowOffset);
        rowOffset += categories.size();
        for (Category category : categories) {
            if (StringUtils.isNotEmpty(category.getUrl())) {
                addCategorySiteMapEntries(category, currentDepth + 1, categorySMGC, siteMapBuilder);
            } else {
                LOG.debug("Skipping empty category URL: " + category.getId());
            }
        }
    } while (categories.size() == rowLimit);
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 34 with Category

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

the class RelatedProductsServiceImpl method findRelatedProducts.

@Override
public List<? extends PromotableProduct> findRelatedProducts(RelatedProductDTO relatedProductDTO) {
    Product product = lookupProduct(relatedProductDTO);
    Category category = lookupCategory(relatedProductDTO);
    if (RelatedProductTypeEnum.FEATURED.equals(relatedProductDTO.getType())) {
        return buildFeaturedProductsList(product, category, relatedProductDTO);
    } else if (RelatedProductTypeEnum.CROSS_SALE.equals(relatedProductDTO.getType())) {
        return buildCrossSaleProductsList(product, category, relatedProductDTO);
    } else if (RelatedProductTypeEnum.UP_SALE.equals(relatedProductDTO.getType())) {
        return buildUpSaleProductsList(product, category, relatedProductDTO);
    } else {
        throw new IllegalArgumentException("RelatedProductType " + relatedProductDTO.getType() + " not supported.");
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) FeaturedProduct(org.broadleafcommerce.core.catalog.domain.FeaturedProduct) Product(org.broadleafcommerce.core.catalog.domain.Product) PromotableProduct(org.broadleafcommerce.core.catalog.domain.PromotableProduct)

Example 35 with Category

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

the class CatalogTest method testCatalog.

@Test(groups = { "testCatalog" })
@Transactional
public void testCatalog() throws Exception {
    Category category = new CategoryImpl();
    category.setName("Soaps");
    category = catalogService.saveCategory(category);
    Category category2 = new CategoryImpl();
    category2.setName("Towels");
    category2 = catalogService.saveCategory(category2);
    Category category3 = new CategoryImpl();
    category3.setName("SuperCategory");
    category3 = catalogService.saveCategory(category3);
    CategoryXref temp = new CategoryXrefImpl();
    temp.setCategory(category);
    temp.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp);
    category3 = catalogService.saveCategory(category3);
    // Test category hierarchy
    Long cat3Id = category3.getId();
    category3 = null;
    category3 = catalogService.findCategoryById(cat3Id);
    category3.getAllParentCategoryXrefs().clear();
    CategoryXref temp2 = new CategoryXrefImpl();
    temp2.setCategory(category);
    temp2.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp2);
    CategoryXref temp3 = new CategoryXrefImpl();
    temp3.setCategory(category2);
    temp3.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp3);
    category3 = catalogService.saveCategory(category3);
    assert category3.getAllParentCategoryXrefs().size() == 2;
    Product newProduct = new ProductImpl();
    Sku newDefaultSku = new SkuImpl();
    newDefaultSku = catalogService.saveSku(newDefaultSku);
    newProduct.setDefaultSku(newDefaultSku);
    newProduct.setName("Lavender Soap");
    Calendar activeStartCal = Calendar.getInstance();
    activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
    newProduct.setActiveStartDate(activeStartCal.getTime());
    // newProduct.setAllParentCategories(allParentCategories);
    newProduct.setDefaultCategory(category);
    newProduct.getAllParentCategoryXrefs().clear();
    newProduct = catalogService.saveProduct(newProduct);
    CategoryProductXref categoryXref = new CategoryProductXrefImpl();
    categoryXref.setProduct(newProduct);
    categoryXref.setCategory(category);
    newProduct.getAllParentCategoryXrefs().add(categoryXref);
    CategoryProductXref categoryXref2 = new CategoryProductXrefImpl();
    categoryXref2.setProduct(newProduct);
    categoryXref2.setCategory(category2);
    newProduct.getAllParentCategoryXrefs().add(categoryXref2);
    newProduct = catalogService.saveProduct(newProduct);
    Long newProductId = newProduct.getId();
    Product testProduct = catalogService.findProductById(newProductId);
    assert testProduct.getId().equals(testProduct.getId());
    Category testCategory = catalogService.findCategoryByName("Soaps");
    assert testCategory.getId().equals(category.getId());
    testCategory = catalogService.findCategoryById(category.getId());
    assert testCategory.getId().equals(category.getId());
    Media media = new MediaImpl();
    media.setAltText("test");
    media.setTitle("large");
    media.setUrl("http://myUrl");
    category.getCategoryMediaXref().put("large", new CategoryMediaXrefImpl(category, media, "large"));
    catalogService.saveCategory(testCategory);
    testCategory = catalogService.findCategoryById(category.getId());
    assert (testCategory.getCategoryMediaXref().get("large") != null);
    List<Category> categories = catalogService.findAllCategories();
    assert categories != null && categories.size() == 3;
    List<Product> products = catalogService.findAllProducts();
    boolean foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    products = catalogService.findProductsByName(newProduct.getName());
    foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    Sku newSku = new SkuImpl();
    newSku.setName("Under Armor T-Shirt -- Red");
    newSku.setRetailPrice(new Money(14.99));
    newSku.setActiveStartDate(activeStartCal.getTime());
    newSku = catalogService.saveSku(newSku);
    List<Sku> allSkus = new ArrayList<>();
    allSkus.add(newSku);
    newProduct.setAdditionalSkus(allSkus);
    newProduct = catalogService.saveProduct(newProduct);
    Long skuId = newProduct.getSkus().get(0).getId();
    Sku testSku = catalogService.findSkuById(skuId);
    assert testSku.getId().equals(skuId);
    List<Sku> testSkus = catalogService.findAllSkus();
    boolean foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
    List<Long> skuIds = new ArrayList<>();
    skuIds.add(skuId);
    testSkus = catalogService.findSkusByIds(skuIds);
    foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) MediaImpl(org.broadleafcommerce.common.media.domain.MediaImpl) Calendar(java.util.Calendar) Media(org.broadleafcommerce.common.media.domain.Media) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) CategoryMediaXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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