use of org.broadleafcommerce.common.money.Money 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.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testOfferNotCombinableOrderOffers.
@Test(groups = { "testOfferNotCombinableOrderOffers" }, dependsOnGroups = { "testOfferNotStackableOrderOffers" })
@Transactional
public void testOfferNotCombinableOrderOffers() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
order.addOrderItem(createDiscreteOrderItem(sku1, 100D, null, true, 2, order));
order.addOrderItem(createDiscreteOrderItem(sku2, 100D, null, true, 2, order));
order.addOfferCode(createOfferUtility.createOfferCode("20 Percent Off Order Offer", OfferType.ORDER, OfferDiscountType.PERCENT_OFF, 20, null, true, true, 1));
order.addOfferCode(createOfferUtility.createOfferCode("30 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 30, null, true, true, 1));
order.addOfferCode(createOfferUtility.createOfferCode("50 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 50, null, true, false, 1));
List<Offer> offers = offerService.buildOfferListForOrder(order);
offerService.applyAndSaveOffersToOrder(offers, order);
assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(290D));
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testFulfillmentGroupOffers.
@Test(groups = { "testFulfillmentGroupOffers" }, dependsOnGroups = { "testCustomerAssociatedOffers2" })
@Transactional
public void testFulfillmentGroupOffers() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
option.setPrice(new Money(0));
option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
order.setFulfillmentGroups(createFulfillmentGroups(option, 5D, order));
orderService.save(order, false);
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.FULFILLMENT_GROUP, OfferDiscountType.PERCENT_OFF, 20, null, true, true, 10));
order.addOfferCode(createOfferUtility.createOfferCode("3 Dollars Off Item Offer", OfferType.FULFILLMENT_GROUP, OfferDiscountType.AMOUNT_OFF, 3, null, true, true, 10));
List<Offer> offers = offerService.buildOfferListForOrder(order);
offerService.applyAndSaveOffersToOrder(offers, order);
offerService.applyAndSaveFulfillmentGroupOffersToOrder(offers, order);
assert (order.getFulfillmentGroups().get(0).getShippingPrice().equals(new Money(1.6D)));
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testPercentOffOfferWithItemMinPriceQuantityReduction.
@Test(groups = { "testPercentageOffOffer" }, dependsOnGroups = { "offerCreateSku1" })
@Transactional
public void testPercentOffOfferWithItemMinPriceQuantityReduction() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
order.addOrderItem(createDiscreteOrderItem(sku1, 3D, null, true, 2, order));
order.addOfferCode(createOfferUtility.createOfferCode("75 Percent Off Items Over $5.00", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 75, "orderItem.?price.getAmount()>5.00", true, true, 10));
List<Offer> offers = offerService.buildOfferListForOrder(order);
offerService.applyAndSaveOffersToOrder(offers, order);
// Evaluate the subtotal again with a reduced quantity to ensure that the
// offer is NOT applied due to the subtotal being greater than $5.00
order.getOrderItems().get(0).setQuantity(1);
offerService.applyAndSaveOffersToOrder(offers, order);
assert (order.getSubTotal().equals(new Money(3.00D)));
}
use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method testOfferLowerSalePriceWithNotCombinableOffer2.
@Test(groups = { "testOfferLowerSalePriceWithNotCombinableOffer2" }, dependsOnGroups = { "testOfferLowerSalePriceWithNotCombinableOffer" })
@Transactional
public void testOfferLowerSalePriceWithNotCombinableOffer2() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
order.addOrderItem(createDiscreteOrderItem(sku1, 100D, 50D, true, 2, order));
order.addOrderItem(createDiscreteOrderItem(sku2, 100D, 50D, true, 2, order));
order.addOfferCode(createOfferUtility.createOfferCode("25 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 25, null, true, false, 1));
order.addOfferCode(createOfferUtility.createOfferCode("35 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 35, null, true, false, 1));
order.addOfferCode(createOfferUtility.createOfferCode("45 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 45, null, true, false, 1));
order.addOfferCode(createOfferUtility.createOfferCode("30 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 30, null, true, true, 1));
List<Offer> offers = offerService.buildOfferListForOrder(order);
offerService.applyAndSaveOffersToOrder(offers, order);
// all of the order items) but is applied in to the full Total via the TotalAcivity in the pricing workflow
assert order.getSubTotal().equals(new Money("20"));
assert order.getOrderAdjustmentsValue().equals(new Money("20"));
}
Aggregations