use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class ProductDataProvider method getProduct.
private static Product getProduct(Long id) {
Calendar activeStartCal = Calendar.getInstance();
activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
Product product = new ProductImpl();
Sku defaultSku = new SkuImpl();
defaultSku.setRetailPrice(new Money(BigDecimal.valueOf(15.0)));
defaultSku.setSalePrice(new Money(BigDecimal.valueOf(10.0)));
defaultSku.setActiveStartDate(activeStartCal.getTime());
product.setDefaultSku(defaultSku);
if (id == null) {
defaultSku.setName("productNameTest");
return product;
}
product.setId(id);
defaultSku.setName(id.toString());
defaultSku.setId(id);
return product;
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class SkuDaoImpl method readSkusByIds.
@Override
public List<Sku> readSkusByIds(List<Long> skuIds) {
if (skuIds == null || skuIds.size() == 0) {
return null;
}
if (skuIds.size() > 100) {
logger.warn("Not recommended to use the readSkusByIds method for long lists of skuIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "sku ids was (" + skuIds.size() + ") in length.");
}
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Sku> criteria = builder.createQuery(Sku.class);
Root<SkuImpl> sku = criteria.from(SkuImpl.class);
criteria.select(sku);
// We only want results that match the sku IDs
criteria.where(sku.get("id").as(Long.class).in(sandBoxHelper.mergeCloneIds(SkuImpl.class, skuIds.toArray(new Long[skuIds.size()]))));
TypedQuery<Sku> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getResultList();
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class SkuDaoImpl method readCountAllActiveSkusInternal.
protected Long readCountAllActiveSkusInternal(Date currentDate) {
// Set up the criteria query that specifies we want to return a Long
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
// The root of our search is sku
Root<SkuImpl> sku = criteria.from(SkuImpl.class);
// We want the count of products
criteria.select(builder.count(sku));
// Ensure the sku is currently active
List<Predicate> restrictions = new ArrayList<Predicate>();
// Add the active start/end date restrictions
restrictions.add(builder.lessThan(sku.get("activeStartDate").as(Date.class), currentDate));
restrictions.add(builder.or(builder.isNull(sku.get("activeEndDate")), builder.greaterThan(sku.get("activeEndDate").as(Date.class), currentDate)));
// Add the restrictions to the criteria query
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Long> query = em.createQuery(criteria);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getSingleResult();
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class SkuDaoImpl method getCriteriaForActiveSkus.
protected CriteriaQuery<Sku> getCriteriaForActiveSkus(Date currentDate, Long lastId) {
// Set up the criteria query that specifies we want to return Products
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Sku> criteria = builder.createQuery(Sku.class);
// The root of our search is Product
Root<SkuImpl> sku = criteria.from(SkuImpl.class);
// Product objects are what we want back
criteria.select(sku);
// Ensure the product is currently active
List<Predicate> restrictions = new ArrayList<Predicate>();
// Add the active start/end date restrictions
restrictions.add(builder.lessThan(sku.get("activeStartDate").as(Date.class), currentDate));
restrictions.add(builder.or(builder.isNull(sku.get("activeEndDate")), builder.greaterThan(sku.get("activeEndDate").as(Date.class), currentDate)));
if (lastId != null) {
restrictions.add(builder.gt(sku.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(sku.get("id")));
return criteria;
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class ProductDataProvider method provideBasicProduct.
/**
* A basic product is actually a Product and a Sku
*/
@DataProvider(name = "basicProduct")
public static Object[][] provideBasicProduct() {
Product ci = new ProductImpl();
Sku defaultSku = new SkuImpl();
defaultSku.setName("setOfAggieDominoes");
defaultSku.setDescription("a fine set of bones for 42");
ci.setDefaultSku(defaultSku);
return new Object[][] { { ci } };
}
Aggregations