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