Search in sources :

Example 1 with OfferCodeImpl

use of org.broadleafcommerce.core.offer.domain.OfferCodeImpl in project BroadleafCommerce by BroadleafCommerce.

the class PricingTest method createOfferCode.

private OfferCode createOfferCode(String offerName, OfferType offerType, OfferDiscountType discountType, double value, String customerRule, String orderRule) {
    OfferCode offerCode = new OfferCodeImpl();
    Offer offer = createOffer(offerName, offerType, discountType, value, customerRule, orderRule);
    offerCode.setOffer(offer);
    offerCode.setOfferCode("OPRAH");
    offerCode = offerService.saveOfferCode(offerCode);
    return offerCode;
}
Also used : Offer(org.broadleafcommerce.core.offer.domain.Offer) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferCodeImpl(org.broadleafcommerce.core.offer.domain.OfferCodeImpl)

Example 2 with OfferCodeImpl

use of org.broadleafcommerce.core.offer.domain.OfferCodeImpl 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)

Aggregations

OfferCodeImpl (org.broadleafcommerce.core.offer.domain.OfferCodeImpl)2 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)1