Search in sources :

Example 1 with CustomerOfferImpl

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

the class OfferTest method testCustomerOffers.

@Test(groups = { "testCustomerOffers" }, dependsOnGroups = { "testOfferCodeDao" })
@Transactional
public void testCustomerOffers() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    CustomerOffer customerOffer = new CustomerOfferImpl();
    customerOffer.setCustomer(order.getCustomer());
    customerOffer.setOffer(offer);
    customerOffer = customerOfferDao.save(customerOffer);
    CustomerOffer customerOfferTest = customerOfferDao.readCustomerOfferById(customerOffer.getId());
    assert (customerOffer.getId().equals(customerOfferTest.getId()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) 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)

Example 2 with CustomerOfferImpl

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

the class OfferTest method testCustomerAssociatedOffers.

@Test(groups = { "testCustomerAssociatedOffers" }, dependsOnGroups = { "testGlobalOffers" })
@Transactional
public void testCustomerAssociatedOffers() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    order.addOrderItem(createDiscreteOrderItem(sku1, 10D, null, true, 2, order));
    order.addOrderItem(createDiscreteOrderItem(sku2, 20D, null, true, 1, order));
    order.addOfferCode(createOfferUtility.createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, "discreteOrderItem.sku.id == " + sku1, true, true, 10));
    order.addOfferCode(createOfferUtility.createOfferCode("3 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 3, "discreteOrderItem.sku.id != " + sku1, true, true, 10));
    Offer offer = createOfferUtility.createOffer("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, true, true, 10, null);
    offer = offerService.save(offer);
    CustomerOffer customerOffer = new CustomerOfferImpl();
    customerOffer.setCustomer(order.getCustomer());
    customerOffer.setOffer(offer);
    customerOffer = customerOfferDao.save(customerOffer);
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    offerService.applyAndSaveOffersToOrder(offers, order);
    assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(31.80D));
}
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)

Example 3 with CustomerOfferImpl

use of org.broadleafcommerce.core.offer.domain.CustomerOfferImpl 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)3 CustomerOfferImpl (org.broadleafcommerce.core.offer.domain.CustomerOfferImpl)3 Offer (org.broadleafcommerce.core.offer.domain.Offer)3 Order (org.broadleafcommerce.core.order.domain.Order)3 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Test (org.testng.annotations.Test)3 Money (org.broadleafcommerce.common.money.Money)2