Search in sources :

Example 46 with Product

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

the class ProductDaoImpl method getCriteriaForActiveProducts.

protected CriteriaQuery<Product> getCriteriaForActiveProducts(Date currentDate, Long lastId) {
    // 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 Product
    Root<ProductImpl> product = criteria.from(ProductImpl.class);
    // We need to filter on active date on the sku
    Join<Product, Sku> sku = product.join("defaultSku");
    product.fetch("defaultSku");
    // Product objects are what we want back
    criteria.select(product);
    // Ensure the product is currently active
    List<Predicate> restrictions = new ArrayList<Predicate>();
    attachActiveRestriction(currentDate, product, sku, restrictions);
    if (lastId != null) {
        restrictions.add(builder.gt(product.get("id").as(Long.class), lastId));
    }
    // Add the restrictions to the criteria query
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    // Add ordering so that paginated queries are consistent
    criteria.orderBy(builder.asc(product.get("id")));
    return criteria;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Predicate(javax.persistence.criteria.Predicate)

Example 47 with Product

use of org.broadleafcommerce.core.catalog.domain.Product 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 48 with Product

use of org.broadleafcommerce.core.catalog.domain.Product 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 49 with Product

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

the class RelatedProductsServiceImpl method removeDuplicatesFromList.

private List<? extends PromotableProduct> removeDuplicatesFromList(List<? extends PromotableProduct> returnPromotableProducts) {
    Set<PromotableProduct> productSet = new LinkedHashSet<PromotableProduct>();
    Set<Product> relatedProductSet = new LinkedHashSet<Product>();
    if (returnPromotableProducts != null) {
        for (PromotableProduct p : returnPromotableProducts) {
            if (!relatedProductSet.contains(p.getRelatedProduct())) {
                productSet.add(p);
                relatedProductSet.add(p.getRelatedProduct());
            }
        }
    } else {
        return null;
    }
    returnPromotableProducts.clear();
    returnPromotableProducts.addAll(new ArrayList(productSet));
    return returnPromotableProducts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) FeaturedProduct(org.broadleafcommerce.core.catalog.domain.FeaturedProduct) Product(org.broadleafcommerce.core.catalog.domain.Product) PromotableProduct(org.broadleafcommerce.core.catalog.domain.PromotableProduct) PromotableProduct(org.broadleafcommerce.core.catalog.domain.PromotableProduct)

Example 50 with Product

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

the class SkuSiteMapGenerator method addSiteMapEntries.

@Override
public void addSiteMapEntries(SiteMapGeneratorConfiguration smgc, SiteMapBuilder siteMapBuilder) {
    int pageNum = 0;
    List<Sku> skus;
    do {
        skus = skuDao.readAllActiveSkus(pageNum++, pageSize);
        for (Sku sku : skus) {
            Product defaultProduct = sku.getDefaultProduct();
            if (defaultProduct != null && CollectionUtils.isNotEmpty(defaultProduct.getAdditionalSkus())) {
                continue;
            }
            if (defaultProduct instanceof ProductBundle) {
                continue;
            }
            if (StringUtils.isEmpty(sku.getProduct().getUrl() + sku.getUrlKey())) {
                continue;
            }
            SiteMapURLWrapper siteMapUrl = new SiteMapURLWrapper();
            // location
            siteMapUrl.setLoc(generateUri(siteMapBuilder, sku));
            // change frequency
            siteMapUrl.setChangeFreqType(smgc.getSiteMapChangeFreq());
            // priority
            siteMapUrl.setPriorityType(smgc.getSiteMapPriority());
            // lastModDate
            siteMapUrl.setLastModDate(generateDate(sku));
            constructImageURLs(siteMapBuilder, siteMapUrl, sku);
            siteMapBuilder.addUrl(siteMapUrl);
        }
    } while (skus.size() == pageSize);
}
Also used : ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SiteMapURLWrapper(org.broadleafcommerce.common.sitemap.wrapper.SiteMapURLWrapper)

Aggregations

Product (org.broadleafcommerce.core.catalog.domain.Product)77 Sku (org.broadleafcommerce.core.catalog.domain.Sku)34 ArrayList (java.util.ArrayList)23 Category (org.broadleafcommerce.core.catalog.domain.Category)18 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)17 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 Order (org.broadleafcommerce.core.order.domain.Order)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.testng.annotations.Test)11 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)10 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)9 Money (org.broadleafcommerce.common.money.Money)9 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)9 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)8 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)7 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)7 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 RelatedProduct (org.broadleafcommerce.core.catalog.domain.RelatedProduct)6 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)6