use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method addAnotherItemToOrder.
@Test(groups = { "addAnotherItemToOrder" }, dependsOnGroups = { "addItemToOrder" })
@Rollback(false)
@Transactional
public void addAnotherItemToOrder() throws AddToCartException, PricingException, RemoveFromCartException {
// In the database, some Skus are inactive and some are active. This ensures that we pull back an active one
// to test a successful cart add
Sku sku = getFirstActiveSku();
Order order = orderService.findOrderById(orderId);
assert order != null;
assert sku.getId() != null;
orderService.setAutomaticallyMergeLikeItems(true);
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO();
itemRequest.setQuantity(1);
itemRequest.setSkuId(sku.getId());
// Note that we are not incrementing the numOrderItems count because it should have gotten merged
order = orderService.addItem(orderId, itemRequest, true);
DiscreteOrderItem item = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
assert item.getSku() != null;
assert item.getSku().equals(sku);
// item-was merged with prior item.
assert item.getQuantity() == 2;
order = orderService.findOrderById(orderId);
assert (order.getOrderItems().size() == 1);
assert (order.getOrderItems().get(0).getQuantity() == 2);
assert order.getFulfillmentGroups().size() == 1;
FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
assert fg.getFulfillmentGroupItems().size() == 1;
FulfillmentGroupItem fgItem = fg.getFulfillmentGroupItems().get(0);
assert fgItem.getOrderItem().equals(item);
assert fgItem.getQuantity() == item.getQuantity();
// add the same item multiple times to the cart without merging or pricing
boolean currentVal = orderService.getAutomaticallyMergeLikeItems();
orderService.setAutomaticallyMergeLikeItems(false);
itemRequest = new OrderItemRequestDTO();
itemRequest.setQuantity(1);
itemRequest.setSkuId(sku.getId());
order = orderService.addItem(orderId, itemRequest, false);
order = orderService.addItem(orderId, itemRequest, false);
DiscreteOrderItem item2 = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
assert item2.getSku() != null;
assert item2.getSku().equals(sku);
// item-was not auto-merged with prior items.
assert item2.getQuantity() == 1;
order = orderService.findOrderById(orderId);
assert (order.getOrderItems().size() == 3);
// reset the cart state back to what it was prior
order = orderService.removeItem(order.getId(), order.getOrderItems().get(1).getId(), true);
order = orderService.removeItem(order.getId(), order.getOrderItems().get(1).getId(), true);
orderService.setAutomaticallyMergeLikeItems(currentVal);
assert (order.getOrderItems().size() == 1);
assert (order.getOrderItems().get(0).getQuantity() == 2);
/*
This test is not supported currently, as the order service may only do like item merging
// re-price the order without automatically merging.
orderService.setAutomaticallyMergeLikeItems(false);
numOrderItems++;
itemRequest = new OrderItemRequestDTO();
itemRequest.setQuantity(1);
itemRequest.setSkuId(sku.getId());
order = orderService.addItem(orderId, itemRequest, true);
DiscreteOrderItem item2 = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
assert item2.getSku() != null;
assert item2.getSku().equals(sku);
assert item2.getQuantity() == 1; // item-was not auto-merged with prior items.
order = orderService.findOrderById(orderId);
assert(order.getOrderItems().size()==2);
assert(order.getOrderItems().get(0).getQuantity()==2);
assert(order.getOrderItems().get(1).getQuantity()==1);
assert order.getFulfillmentGroups().size() == 1;
fg = order.getFulfillmentGroups().get(0);
assert fg.getFulfillmentGroupItems().size() == 2;
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
assert fgi.getQuantity() == fgi.getOrderItem().getQuantity();
}*/
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createOrderWithBundle.
/**
* Create order with a bundle with two items. Bundle has a quantity of 2.
* Bundle item 1 has quantity of 2, bundle item 2 has quantity of 3
* @return
*/
public Order createOrderWithBundle() {
Order order = new OrderImpl();
order.setId(getOrderId());
Category category1 = new CategoryImpl();
category1.setName("test1");
category1.setId(1L);
Product product1 = new ProductImpl();
Sku sku1 = new SkuImpl();
sku1.setName("test1");
sku1.setId(1L);
sku1.setDiscountable(true);
sku1.setRetailPrice(new Money(10D));
product1.setDefaultSku(sku1);
CategoryProductXref xref1 = new CategoryProductXrefImpl();
xref1.setProduct(product1);
xref1.setCategory(category1);
category1.getAllProductXrefs().add(xref1);
Category category2 = new CategoryImpl();
category2.setName("test2");
category2.setId(2L);
Product product2 = new ProductImpl();
Sku sku2 = new SkuImpl();
sku2.setName("test2");
sku2.setId(2L);
sku2.setDiscountable(true);
sku2.setRetailPrice(new Money(10D));
product2.setDefaultSku(sku2);
CategoryProductXref xref2 = new CategoryProductXrefImpl();
xref2.setProduct(product2);
xref2.setCategory(category2);
category2.getAllProductXrefs().add(xref2);
ProductBundle pb = new ProductBundleImpl();
pb.setPricingModel(ProductBundlePricingModelType.ITEM_SUM);
BundleOrderItem bundleOrderItem = new BundleOrderItemImpl();
bundleOrderItem.setCategory(category1);
bundleOrderItem.setName("test1");
bundleOrderItem.setOrder(order);
bundleOrderItem.setOrderItemType(OrderItemType.DISCRETE);
bundleOrderItem.setQuantity(2);
bundleOrderItem.setId(getOrderItemId());
bundleOrderItem.setOrder(order);
bundleOrderItem.setRetailPrice(new Money(10D));
bundleOrderItem.setProductBundle(pb);
OrderItemPriceDetail priceDetail = new OrderItemPriceDetailImpl();
priceDetail.setOrderItem(bundleOrderItem);
priceDetail.setQuantity(2);
bundleOrderItem.getOrderItemPriceDetails().add(priceDetail);
order.getOrderItems().add(bundleOrderItem);
DiscreteOrderItem orderItem1 = new DiscreteOrderItemImpl();
orderItem1.setCategory(category1);
orderItem1.setName("test1");
orderItem1.setOrder(order);
orderItem1.setOrderItemType(OrderItemType.DISCRETE);
orderItem1.setProduct(product1);
orderItem1.setQuantity(2);
orderItem1.setSku(sku1);
orderItem1.setId(getOrderItemId());
orderItem1.setOrder(order);
OrderItemPriceDetail priceDetail1 = new OrderItemPriceDetailImpl();
priceDetail1.setOrderItem(orderItem1);
priceDetail1.setQuantity(2);
orderItem1.getOrderItemPriceDetails().add(priceDetail1);
bundleOrderItem.getDiscreteOrderItems().add(orderItem1);
DiscreteOrderItem orderItem2 = new DiscreteOrderItemImpl();
orderItem2.setCategory(category2);
orderItem2.setName("test2");
orderItem2.setOrder(order);
orderItem2.setOrderItemType(OrderItemType.DISCRETE);
orderItem2.setProduct(product2);
orderItem2.setQuantity(3);
orderItem2.setSku(sku2);
orderItem2.setId(getOrderItemId());
orderItem2.setOrder(order);
OrderItemPriceDetail priceDetail2 = new OrderItemPriceDetailImpl();
priceDetail2.setOrderItem(orderItem2);
priceDetail2.setQuantity(3);
orderItem2.getOrderItemPriceDetails().add(priceDetail2);
bundleOrderItem.getDiscreteOrderItems().add(orderItem2);
Customer customer = new CustomerImpl();
customer.setEmailAddress("test@test.com");
customer.setFirstName("John");
customer.setLastName("Tester");
customer.setReceiveEmail(true);
customer.setRegistered(true);
order.setCustomer(customer);
order.setEmailAddress("test@test.com");
FulfillmentGroup fg1 = new FulfillmentGroupImpl();
fg1.setId(1L);
Address address1 = new AddressImpl();
address1.setAddressLine1("123 Test Road");
address1.setCity("Dallas");
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
address1.setCountry(country);
address1.setIsoCountryAlpha2(isoCountry);
address1.setDefault(true);
address1.setFirstName("John");
address1.setLastName("Tester");
address1.setPostalCode("75244");
Phone primary = new PhoneImpl();
primary.setPhoneNumber("972-976-1234");
address1.setPhonePrimary(primary);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setCountry(country);
state.setName("Texas");
address1.setState(state);
address1.setIsoCountrySubdivision("US-TX");
fg1.setAddress(address1);
fg1.setOrder(order);
fg1.setPrimary(true);
fg1.setRetailShippingPrice(new Money(10D));
fg1.setShippingPrice(new Money(10D));
fg1.setType(FulfillmentType.PHYSICAL_SHIP);
fg1.setOrder(order);
FulfillmentGroupItem fgItem1 = new FulfillmentGroupItemImpl();
fgItem1.setFulfillmentGroup(fg1);
fgItem1.setOrderItem(orderItem1);
fgItem1.setQuantity(2);
// fgItem1.setRetailPrice(new Money(19.99D));
fg1.getFulfillmentGroupItems().add(fgItem1);
order.getFulfillmentGroups().add(fg1);
FulfillmentGroup fg2 = new FulfillmentGroupImpl();
fg2.setId(2L);
Address address2 = new AddressImpl();
address2.setAddressLine1("124 Test Road");
address2.setCity("Dallas");
Country country2 = new CountryImpl();
country2.setAbbreviation("US");
country2.setName("United States");
ISOCountry isoCountry2 = new ISOCountryImpl();
isoCountry2.setAlpha2("US");
isoCountry2.setName("UNITED STATES");
address2.setCountry(country2);
address2.setIsoCountryAlpha2(isoCountry2);
address2.setDefault(true);
address2.setFirstName("John");
address2.setLastName("Tester");
address2.setPostalCode("75244");
Phone primary2 = new PhoneImpl();
primary2.setPhoneNumber("972-976-1234");
address2.setPhonePrimary(primary2);
State state2 = new StateImpl();
state2.setAbbreviation("TX");
state2.setCountry(country2);
state2.setName("Texas");
address2.setState(state2);
address2.setIsoCountrySubdivision("US-TX");
fg2.setAddress(address2);
fg2.setOrder(order);
fg2.setPrimary(true);
fg2.setRetailShippingPrice(new Money(20D));
fg2.setShippingPrice(new Money(20D));
fg2.setType(FulfillmentType.PHYSICAL_SHIP);
fg2.setOrder(order);
FulfillmentGroupItem fgItem2 = new FulfillmentGroupItemImpl();
fgItem2.setFulfillmentGroup(fg2);
fgItem2.setOrderItem(orderItem2);
fgItem2.setQuantity(3);
// fgItem2.setRetailPrice(new Money(29.99D));
fg2.getFulfillmentGroupItems().add(fgItem2);
order.getFulfillmentGroups().add(fg2);
order.setSubTotal(new Money((2 * 19.99D) + (3 * 29.99D)));
orders.put(order.getId(), order);
return order;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method getAddItemToFulfillmentGroupAnswer.
public static IAnswer<FulfillmentGroup> getAddItemToFulfillmentGroupAnswer() {
return new IAnswer<FulfillmentGroup>() {
@Override
public FulfillmentGroup answer() throws Throwable {
FulfillmentGroupItemRequest fgItemRequest = (FulfillmentGroupItemRequest) EasyMock.getCurrentArguments()[0];
FulfillmentGroup fg = fgItemRequest.getFulfillmentGroup();
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setOrderItem(fgItemRequest.getOrderItem());
fgItem.setQuantity(fgItemRequest.getQuantity());
fg.getFulfillmentGroupItems().add(fgItem);
return fg;
}
};
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method createBasicOrder.
public Order createBasicOrder() {
Order order = new OrderImpl();
order.setId(getOrderId());
Category category1 = new CategoryImpl();
category1.setName("test1");
category1.setId(1L);
Product product1 = new ProductImpl();
Sku sku1 = new SkuImpl();
sku1.setName("test1");
sku1.setId(1L);
sku1.setDiscountable(true);
sku1.setRetailPrice(new Money(19.99D));
product1.setDefaultSku(sku1);
CategoryProductXref xref1 = new CategoryProductXrefImpl();
xref1.setProduct(product1);
xref1.setCategory(category1);
category1.getAllProductXrefs().add(xref1);
Category category2 = new CategoryImpl();
category2.setName("test2");
category2.setId(2L);
Product product2 = new ProductImpl();
Sku sku2 = new SkuImpl();
sku2.setName("test2");
sku2.setId(2L);
sku2.setDiscountable(true);
sku2.setRetailPrice(new Money(29.99D));
product2.setDefaultSku(sku2);
CategoryProductXref xref2 = new CategoryProductXrefImpl();
xref2.setProduct(product2);
xref2.setCategory(category2);
category2.getAllProductXrefs().add(xref2);
DiscreteOrderItem orderItem1 = new DiscreteOrderItemImpl();
orderItem1.setCategory(category1);
orderItem1.setName("test1");
orderItem1.setOrder(order);
orderItem1.setOrderItemType(OrderItemType.DISCRETE);
orderItem1.setProduct(product1);
orderItem1.setQuantity(2);
orderItem1.setSku(sku1);
orderItem1.setId(getOrderItemId());
orderItem1.setOrder(order);
OrderItemPriceDetail priceDetail1 = new OrderItemPriceDetailImpl();
priceDetail1.setOrderItem(orderItem1);
priceDetail1.setQuantity(2);
orderItem1.getOrderItemPriceDetails().add(priceDetail1);
order.getOrderItems().add(orderItem1);
DiscreteOrderItem orderItem2 = new DiscreteOrderItemImpl();
orderItem2.setCategory(category2);
orderItem2.setName("test2");
orderItem2.setOrder(order);
orderItem2.setOrderItemType(OrderItemType.DISCRETE);
orderItem2.setProduct(product2);
orderItem2.setQuantity(3);
orderItem2.setSku(sku2);
orderItem2.setId(getOrderItemId());
orderItem2.setOrder(order);
OrderItemPriceDetail priceDetail2 = new OrderItemPriceDetailImpl();
priceDetail2.setOrderItem(orderItem2);
priceDetail2.setQuantity(3);
orderItem2.getOrderItemPriceDetails().add(priceDetail2);
order.getOrderItems().add(orderItem2);
Customer customer = new CustomerImpl();
customer.setEmailAddress("test@test.com");
customer.setFirstName("John");
customer.setLastName("Tester");
customer.setReceiveEmail(true);
customer.setRegistered(true);
order.setCustomer(customer);
order.setEmailAddress("test@test.com");
FulfillmentGroup fg1 = new FulfillmentGroupImpl();
fg1.setId(1L);
Address address1 = new AddressImpl();
address1.setAddressLine1("123 Test Road");
address1.setCity("Dallas");
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
address1.setCountry(country);
address1.setIsoCountryAlpha2(isoCountry);
address1.setDefault(true);
address1.setFirstName("John");
address1.setLastName("Tester");
address1.setPostalCode("75244");
Phone primary = new PhoneImpl();
primary.setPhoneNumber("972-976-1234");
address1.setPhonePrimary(primary);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setCountry(country);
state.setName("Texas");
address1.setState(state);
address1.setIsoCountrySubdivision("US-TX");
fg1.setAddress(address1);
fg1.setOrder(order);
fg1.setPrimary(true);
fg1.setRetailShippingPrice(new Money(10D));
fg1.setShippingPrice(new Money(10D));
fg1.setType(FulfillmentType.PHYSICAL_SHIP);
fg1.setOrder(order);
FulfillmentGroupItem fgItem1 = new FulfillmentGroupItemImpl();
fgItem1.setFulfillmentGroup(fg1);
fgItem1.setOrderItem(orderItem1);
fgItem1.setQuantity(2);
// fgItem1.setRetailPrice(new Money(19.99D));
fg1.getFulfillmentGroupItems().add(fgItem1);
order.getFulfillmentGroups().add(fg1);
FulfillmentGroup fg2 = new FulfillmentGroupImpl();
fg2.setId(2L);
Address address2 = new AddressImpl();
address2.setAddressLine1("124 Test Road");
address2.setCity("Dallas");
Country country2 = new CountryImpl();
country2.setAbbreviation("US");
country2.setName("United States");
ISOCountry isoCountry2 = new ISOCountryImpl();
isoCountry2.setAlpha2("US");
isoCountry2.setName("UNITED STATES");
address2.setCountry(country2);
address2.setIsoCountryAlpha2(isoCountry2);
address2.setDefault(true);
address2.setFirstName("John");
address2.setLastName("Tester");
address2.setPostalCode("75244");
Phone primary2 = new PhoneImpl();
primary2.setPhoneNumber("972-976-1234");
address2.setPhonePrimary(primary2);
State state2 = new StateImpl();
state2.setAbbreviation("TX");
state2.setCountry(country2);
state2.setName("Texas");
address2.setState(state2);
address2.setIsoCountrySubdivision("US-TX");
fg2.setAddress(address2);
fg2.setOrder(order);
fg2.setPrimary(true);
fg2.setRetailShippingPrice(new Money(20D));
fg2.setShippingPrice(new Money(20D));
fg2.setType(FulfillmentType.PHYSICAL_SHIP);
fg2.setOrder(order);
FulfillmentGroupItem fgItem2 = new FulfillmentGroupItemImpl();
fgItem2.setFulfillmentGroup(fg2);
fgItem2.setOrderItem(orderItem2);
fgItem2.setQuantity(3);
// fgItem2.setRetailPrice(new Money(29.99D));
fg2.getFulfillmentGroupItems().add(fgItem2);
order.getFulfillmentGroups().add(fg2);
order.setSubTotal(new Money((2 * 19.99D) + (3 * 29.99D)));
orders.put(order.getId(), order);
return order;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorTest method testApplyAllFulfillmentGroupOffersWithOrderItemOffers.
public void testApplyAllFulfillmentGroupOffersWithOrderItemOffers() throws Exception {
final ThreadLocal<Order> myOrder = new ThreadLocal<Order>();
EasyMock.expect(orderItemDaoMock.createOrderItemPriceDetail()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAnswer()).anyTimes();
EasyMock.expect(orderItemDaoMock.createOrderItemQualifier()).andAnswer(OfferDataItemProvider.getCreateOrderItemQualifierAnswer()).atLeastOnce();
EasyMock.expect(fgServiceMock.addItemToFulfillmentGroup(EasyMock.isA(FulfillmentGroupItemRequest.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getAddItemToFulfillmentGroupAnswer()).anyTimes();
EasyMock.expect(orderServiceMock.removeItem(EasyMock.isA(Long.class), EasyMock.isA(Long.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getRemoveItemFromOrderAnswer()).anyTimes();
EasyMock.expect(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes();
EasyMock.expect(offerServiceUtilitiesMock.orderMeetsQualifyingSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class), EasyMock.isA(HashMap.class))).andReturn(true).anyTimes();
EasyMock.expect(offerServiceUtilitiesMock.orderMeetsSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class))).andReturn(true).anyTimes();
EasyMock.expect(orderServiceMock.getAutomaticallyMergeLikeItems()).andReturn(true).anyTimes();
EasyMock.expect(orderItemServiceMock.saveOrderItem(EasyMock.isA(OrderItem.class))).andAnswer(OfferDataItemProvider.getSaveOrderItemAnswer()).anyTimes();
EasyMock.expect(fgItemDaoMock.save(EasyMock.isA(FulfillmentGroupItem.class))).andAnswer(OfferDataItemProvider.getSaveFulfillmentGroupItemAnswer()).anyTimes();
EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).anyTimes();
EasyMock.expect(offerDaoMock.createFulfillmentGroupAdjustment()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupAdjustmentAnswer()).anyTimes();
EasyMock.expect(orderServiceMock.findOrderById(EasyMock.isA(Long.class))).andAnswer(new IAnswer<Order>() {
@Override
public Order answer() throws Throwable {
return myOrder.get();
}
}).anyTimes();
EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() {
@Override
public List<OrderMultishipOption> answer() throws Throwable {
List<OrderMultishipOption> options = new ArrayList<OrderMultishipOption>();
PromotableOrder order = dataProvider.createBasicPromotableOrder();
for (FulfillmentGroup fg : order.getOrder().getFulfillmentGroups()) {
Address address = fg.getAddress();
for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
for (int j = 0; j < fgItem.getQuantity(); j++) {
OrderMultishipOption option = new OrderMultishipOptionImpl();
option.setOrder(order.getOrder());
option.setAddress(address);
option.setOrderItem(fgItem.getOrderItem());
options.add(option);
}
}
}
return options;
}
}).anyTimes();
multishipOptionServiceMock.deleteAllOrderMultishipOptions(EasyMock.isA(Order.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(new IAnswer<Order>() {
@Override
public Order answer() throws Throwable {
Order order = (Order) EasyMock.getCurrentArguments()[0];
order.getFulfillmentGroups().get(0).getFulfillmentGroupItems().addAll(order.getFulfillmentGroups().get(1).getFulfillmentGroupItems());
order.getFulfillmentGroups().remove(order.getFulfillmentGroups().get(1));
return order;
}
}).anyTimes();
EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes();
fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(offerTimeZoneProcessorMock.getTimeZone(EasyMock.isA(OfferImpl.class))).andReturn(TimeZone.getTimeZone("CST")).anyTimes();
replay();
PromotableOrder promotableOrder = dataProvider.createBasicPromotableOrder();
Order order = promotableOrder.getOrder();
myOrder.set(promotableOrder.getOrder());
List<PromotableCandidateFulfillmentGroupOffer> qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
List<Offer> offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
offers.addAll(dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
offers.get(1).setName("secondOffer");
offers.addAll(dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
offers.get(0).setTotalitarianOffer(true);
offerService.applyAndSaveFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
int fgAdjustmentCount = 0;
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
}
// The totalitarian offer that applies to both fg's is not combinable and is a worse offer than the order item offers
// - it is therefore ignored
// However, the second combinable fg offer is allowed to be applied.
assertTrue(fgAdjustmentCount == 1);
promotableOrder = dataProvider.createBasicPromotableOrder();
myOrder.set(promotableOrder.getOrder());
offers.get(2).setValue(new BigDecimal("1"));
offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
offerService.applyAndSaveFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
fgAdjustmentCount = 0;
order = promotableOrder.getOrder();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
}
// The totalitarian fg offer is now a better deal than the order item offers, therefore the totalitarian fg offer is applied
// and the order item offers are removed
assertTrue(fgAdjustmentCount == 2);
int itemAdjustmentCount = 0;
for (OrderItem item : order.getOrderItems()) {
for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
itemAdjustmentCount += detail.getOrderItemPriceDetailAdjustments().size();
}
}
// Confirm that the order item offers are removed
assertTrue(itemAdjustmentCount == 0);
verify();
}
Aggregations