use of org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceTest method testOrderItemOfferWithGiftWrap.
@Test(groups = { "testOffersWithGiftWrap" }, dependsOnGroups = { "testShippingInsert" })
@Transactional
public void testOrderItemOfferWithGiftWrap() throws PricingException {
Order order = createTestOrderWithOfferAndGiftWrap();
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))", "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))");
for (Offer offer : offers) {
offer.setName("testOffer");
// //reset the offer is the targets and qualifiers, otherwise the reference is incorrect
// for (OfferItemCriteria criteria : offer.getTargetItemCriteria()) {
// criteria.setTargetOffer(null);
// }
// for (OfferItemCriteria criteria : offer.getQualifyingItemCriteria()) {
// criteria.setQualifyingOffer(null);
// }
offerService.save(offer);
}
order = orderService.save(order, false);
Set<OrderMultishipOption> options = new HashSet<OrderMultishipOption>();
for (FulfillmentGroup fg : order.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);
option.setAddress(address);
option.setOrderItem(fgItem.getOrderItem());
option.setFulfillmentOption(fg.getFulfillmentOption());
options.add(option);
}
}
}
for (OrderMultishipOption option : options) {
orderMultishipOptionService.save(option);
}
order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
assert order.getOrderItems().size() == 3;
assert order.getTotalTax().equals(new Money("2.00"));
assert order.getTotalShipping().equals(new Money("8.50"));
assert order.getSubTotal().equals(new Money("40.00"));
assert order.getTotal().equals(new Money("50.50"));
boolean foundGiftItemAndCorrectQuantity = false;
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem && ((GiftWrapOrderItem) orderItem).getWrappedItems().size() == 1) {
foundGiftItemAndCorrectQuantity = true;
break;
}
}
assert foundGiftItemAndCorrectQuantity;
}
use of org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl in project BroadleafCommerce by BroadleafCommerce.
the class OrderMultishipOptionServiceImpl method createPopulatedOrderMultishipOption.
protected List<OrderMultishipOption> createPopulatedOrderMultishipOption(Order order, DiscreteOrderItem item, Integer quantity) {
List<OrderMultishipOption> orderMultishipOptions = new ArrayList<OrderMultishipOption>();
if (!fulfillmentGroupService.isShippable(item.getSku().getFulfillmentType()) || quantity == 0) {
return orderMultishipOptions;
}
// for (int i = 0; i < quantity; i++) {
OrderMultishipOption orderMultishipOption = new OrderMultishipOptionImpl();
orderMultishipOption.setOrder(order);
orderMultishipOption.setOrderItem(item);
orderMultishipOptions.add(orderMultishipOption);
// }
return orderMultishipOptions;
}
use of org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl 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();
}
use of org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl in project BroadleafCommerce by BroadleafCommerce.
the class OrderMultishipOptionServiceImpl method getOrderMultishipOptionsFromDTOs.
@Override
public List<OrderMultishipOption> getOrderMultishipOptionsFromDTOs(Order order, List<OrderMultishipOptionDTO> optionDtos) {
List<OrderMultishipOption> orderMultishipOptions = new ArrayList<OrderMultishipOption>();
for (OrderMultishipOptionDTO optionDto : optionDtos) {
OrderMultishipOption option = new OrderMultishipOptionImpl();
if (optionDto.getAddressId() != null) {
option.setAddress(addressService.readAddressById(optionDto.getAddressId()));
}
if (optionDto.getFulfillmentOptionId() != null) {
option.setFulfillmentOption(fulfillmentOptionService.readFulfillmentOptionById(optionDto.getFulfillmentOptionId()));
}
option.setId(optionDto.getId());
option.setOrder(order);
option.setOrderItem(orderItemService.readOrderItemById(optionDto.getOrderItemId()));
orderMultishipOptions.add(option);
}
return orderMultishipOptions;
}
Aggregations