Search in sources :

Example 6 with OrderImpl

use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method createCustomerWithBasicOrderAndAddresses.

/**
 * Create a state, country, and customer with a basic order and some addresses
 */
public Customer createCustomerWithBasicOrderAndAddresses() {
    Customer customer = createCustomerWithAddresses();
    Order order = new OrderImpl();
    order.setStatus(OrderStatus.IN_PROCESS);
    order.setTotal(new Money(BigDecimal.valueOf(1000)));
    assert order.getId() == null;
    order.setCustomer(customer);
    order = orderDao.save(order);
    assert order.getId() != null;
    return customer;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 7 with OrderImpl

use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class OfferCodeDaoImpl method offerCodeIsUsed.

@Override
public Boolean offerCodeIsUsed(OfferCode code) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
    Root<OrderImpl> baseOrder = criteria.from(OrderImpl.class);
    criteria.select(baseOrder);
    Join<OrderImpl, OfferCodeImpl> join = baseOrder.join("addedOfferCodes");
    criteria.where(builder.equal(join.get("id"), code.getId()));
    TypedQuery<Order> query = em.createQuery(criteria);
    try {
        query.getSingleResult();
    } catch (NoResultException e) {
        return false;
    }
    return true;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) OfferCodeImpl(org.broadleafcommerce.core.offer.domain.OfferCodeImpl) NoResultException(javax.persistence.NoResultException)

Example 8 with OrderImpl

use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class OrderDaoImpl method readOrdersByDateRange.

@Override
public List<Order> readOrdersByDateRange(final Date startDate, final Date endDate) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Order> criteria = builder.createQuery(Order.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    criteria.select(order);
    criteria.where(builder.between(order.<Date>get("submitDate"), startDate, endDate));
    criteria.orderBy(builder.desc(order.get("submitDate")));
    TypedQuery<Order> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) Date(java.util.Date)

Example 9 with OrderImpl

use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method readOrderItemsForCustomersInDateRange.

@Override
public List<OrderItem> readOrderItemsForCustomersInDateRange(List<Long> customerIds, Date startDate, Date endDate) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    Join<Order, OrderItem> orderItems = order.join("orderItems");
    criteria.select(orderItems);
    List<Predicate> restrictions = new ArrayList<>();
    restrictions.add(builder.between(order.<Date>get("submitDate"), startDate, endDate));
    restrictions.add(order.get("customer").get("id").in(customerIds));
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    criteria.orderBy(builder.desc(order.get("customer")), builder.asc(order.get("submitDate")));
    TypedQuery<OrderItem> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) Predicate(javax.persistence.criteria.Predicate)

Example 10 with OrderImpl

use of org.broadleafcommerce.core.order.domain.OrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemDaoImpl method readBatchOrderItems.

@Override
public List<OrderItem> readBatchOrderItems(int start, int count, List<OrderStatus> statuses) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<OrderItem> criteria = builder.createQuery(OrderItem.class);
    Root<OrderImpl> order = criteria.from(OrderImpl.class);
    Join<Order, OrderItem> orderItems = order.join("orderItems");
    criteria.select(orderItems);
    List<Predicate> restrictions = new ArrayList<>();
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    if (CollectionUtils.isNotEmpty(statuses)) {
        // We only want results that match the orders with the correct status
        ArrayList<String> statusStrings = new ArrayList<String>();
        for (OrderStatus status : statuses) {
            statusStrings.add(status.getType());
        }
        criteria.where(order.get("status").as(String.class).in(statusStrings));
    }
    TypedQuery<OrderItem> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(count);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.broadleafcommerce.core.order.domain.Order) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) OrderStatus(org.broadleafcommerce.core.order.service.type.OrderStatus) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Aggregations

OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)17 Order (org.broadleafcommerce.core.order.domain.Order)12 ArrayList (java.util.ArrayList)9 Money (org.broadleafcommerce.common.money.Money)9 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)8 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)6 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)5 Predicate (javax.persistence.criteria.Predicate)4 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)4 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)4 Sku (org.broadleafcommerce.core.catalog.domain.Sku)4 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)4 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)4 NullOrderImpl (org.broadleafcommerce.core.order.domain.NullOrderImpl)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)3