Search in sources :

Example 6 with CustomerOffer

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

the class OfferTest method testCustomerAssociatedOffers2.

@Test(groups = { "testCustomerAssociatedOffers2" }, dependsOnGroups = { "testCustomerAssociatedOffers" })
@Transactional
public void testCustomerAssociatedOffers2() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    order.addOrderItem(createDiscreteOrderItem(sku1, 20D, null, true, 1, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 20D, null, true, 1, order));
    order.addOfferCode(createOfferUtility.createOfferCode("15%OFF", "15 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 15, null, false, true, 0, null));
    Offer offer1 = createOfferUtility.createOffer("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, "discreteOrderItem.sku.id == " + sku1, false, true, 0, null);
    offerDao.save(offer1);
    CustomerOffer customerOffer1 = new CustomerOfferImpl();
    customerOffer1.setCustomer(order.getCustomer());
    customerOffer1.setOffer(offer1);
    customerOfferDao.save(customerOffer1);
    Offer offer2 = createOfferUtility.createOffer("10 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 10, "discreteOrderItem.sku.id == " + sku2, false, true, 0, null);
    offerDao.save(offer2);
    CustomerOffer customerOffer2 = new CustomerOfferImpl();
    customerOffer2.setCustomer(order.getCustomer());
    customerOffer2.setOffer(offer2);
    customerOfferDao.save(customerOffer2);
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert (order.getSubTotal().equals(new Money(33D)));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) CustomerOfferImpl(org.broadleafcommerce.core.offer.domain.CustomerOfferImpl) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)6 Offer (org.broadleafcommerce.core.offer.domain.Offer)6 CustomerOfferImpl (org.broadleafcommerce.core.offer.domain.CustomerOfferImpl)4 Order (org.broadleafcommerce.core.order.domain.Order)4 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Test (org.testng.annotations.Test)4 Money (org.broadleafcommerce.common.money.Money)2 Customer (org.broadleafcommerce.profile.core.domain.Customer)2 ArrayList (java.util.ArrayList)1 CandidateItemOffer (org.broadleafcommerce.core.offer.domain.CandidateItemOffer)1 CandidateOrderOffer (org.broadleafcommerce.core.offer.domain.CandidateOrderOffer)1 OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)1 OfferImpl (org.broadleafcommerce.core.offer.domain.OfferImpl)1 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)1 PromotableCandidateItemOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer)1 PromotableCandidateOrderOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer)1