Search in sources :

Example 6 with SkuImpl

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) Calendar(java.util.Calendar) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 7 with SkuImpl

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 8 with SkuImpl

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 9 with SkuImpl

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ArrayList(java.util.ArrayList) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 10 with SkuImpl

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 } };
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) DataProvider(org.testng.annotations.DataProvider)

Aggregations

SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)21 Sku (org.broadleafcommerce.core.catalog.domain.Sku)20 ArrayList (java.util.ArrayList)12 Money (org.broadleafcommerce.common.money.Money)12 Product (org.broadleafcommerce.core.catalog.domain.Product)11 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)11 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)7 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)7 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)7 Order (org.broadleafcommerce.core.order.domain.Order)7 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)6 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)6 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)6 Test (org.testng.annotations.Test)6 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)5 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)5 Address (org.broadleafcommerce.profile.core.domain.Address)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5