Search in sources :

Example 1 with CustomerOffer

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

the class OfferServiceTest method testBuildOfferListForOrder.

public void testBuildOfferListForOrder() throws Exception {
    EasyMock.expect(customerOfferDaoMock.readCustomerOffersByCustomer(EasyMock.isA(Customer.class))).andReturn(new ArrayList<CustomerOffer>());
    EasyMock.expect(offerDaoMock.readOffersByAutomaticDeliveryType()).andReturn(dataProvider.createCustomerBasedOffer(null, dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF));
    replay();
    Order order = dataProvider.createBasicPromotableOrder().getOrder();
    List<Offer> offers = offerService.buildOfferListForOrder(order);
    assertTrue(offers.size() == 1);
    verify();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CandidateOrderOffer(org.broadleafcommerce.core.offer.domain.CandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer)

Example 2 with CustomerOffer

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

the class OfferTest method testOfferDelete.

@Test(groups = { "testOfferDelete" }, dependsOnGroups = { "testFulfillmentGroupOffers" })
@Transactional
public void testOfferDelete() throws Exception {
    CustomerOffer customerOffer = customerOfferDao.create();
    Customer customer = createCustomer();
    Long customerId = customer.getId();
    customerOffer.setCustomer(customerService.saveCustomer(customer));
    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);
    Long offerId = offer.getId();
    offerDao.delete(offer);
    Offer deletedOffer = offerDao.readOfferById(offerId);
    assert ((OfferImpl) deletedOffer).getArchived() == 'Y';
    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.setOffer(offer);
    customerOffer = customerOfferDao.save(customerOffer);
    Long customerOfferId = customerOffer.getId();
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert (customerOffer != null);
    Customer customer2 = createCustomer();
    customerOffer.setCustomer(customerService.saveCustomer(customer2));
    customerOffer = customerOfferDao.save(customerOffer);
    assert !customerOffer.getCustomer().getId().equals(customerId);
    customerOfferDao.delete(customerOffer);
    customerOffer = customerOfferDao.readCustomerOfferById(customerOfferId);
    assert customerOffer == null || ((OfferImpl) customerOffer).getArchived() == 'Y';
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) Offer(org.broadleafcommerce.core.offer.domain.Offer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) CustomerOfferImpl(org.broadleafcommerce.core.offer.domain.CustomerOfferImpl) OfferImpl(org.broadleafcommerce.core.offer.domain.OfferImpl) 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 CustomerOffer

use of org.broadleafcommerce.core.offer.domain.CustomerOffer 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 4 with CustomerOffer

use of org.broadleafcommerce.core.offer.domain.CustomerOffer 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 5 with CustomerOffer

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

the class OfferServiceImpl method buildOfferListForOrder.

/**
 * Creates a list of offers that applies to this order.  All offers that are assigned to the customer,
 * entered during checkout, or has a delivery type of automatic are added to the list.  The same offer
 * cannot appear more than once in the list.
 *
 * @param order
 * @return a List of offers that may apply to this order
 */
@Override
public List<Offer> buildOfferListForOrder(Order order) {
    List<Offer> offers = new ArrayList<Offer>();
    List<CustomerOffer> customerOffers = lookupOfferCustomerByCustomer(order.getCustomer());
    for (CustomerOffer customerOffer : customerOffers) {
        if (!offers.contains(customerOffer.getOffer())) {
            offers.add(customerOffer.getOffer());
        }
    }
    List<OfferCode> orderOfferCodes = refreshOfferCodesIfApplicable(order);
    orderOfferCodes = removeOutOfDateOfferCodes(orderOfferCodes);
    for (OfferCode orderOfferCode : orderOfferCodes) {
        if (!offers.contains(orderOfferCode.getOffer())) {
            offers.add(orderOfferCode.getOffer());
        }
        extensionManager.getProxy().addAdditionalOffersForCode(offers, orderOfferCode);
    }
    List<Offer> globalOffers = lookupAutomaticDeliveryOffers();
    for (Offer globalOffer : globalOffers) {
        if (!offers.contains(globalOffer) && verifyMaxCustomerUsageThreshold(order, globalOffer)) {
            offers.add(globalOffer);
        }
    }
    if (extensionManager != null) {
        extensionManager.applyAdditionalFilters(offers, order);
    }
    return offers;
}
Also used : PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) ArrayList(java.util.ArrayList) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer)

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