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;
}
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();
}
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.");
}
}
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;
}
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);
}
Aggregations