use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method getRemoveItemFromOrderAnswer.
public static IAnswer<Order> getRemoveItemFromOrderAnswer() {
return new IAnswer<Order>() {
@Override
public Order answer() throws Throwable {
Long orderId = (Long) EasyMock.getCurrentArguments()[0];
Order order = orders.get(orderId);
Iterator<OrderItem> orderItemItr = order.getOrderItems().listIterator();
while (orderItemItr.hasNext()) {
OrderItem item = orderItemItr.next();
if (item.getId().equals(EasyMock.getCurrentArguments()[1])) {
orderItemItr.remove();
}
}
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
while (itr.hasNext()) {
if (itr.next().getOrderItem().getId().equals(EasyMock.getCurrentArguments()[1])) {
itr.remove();
}
}
}
return order;
}
};
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutTest method buildFulfillmentGroup.
private FulfillmentGroup buildFulfillmentGroup(Order order, Address address) {
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setIsShippingPriceTaxable(true);
group.setOrder(order);
group.setAddress(address);
List<FulfillmentGroup> groups = new ArrayList<>();
groups.add(group);
order.setFulfillmentGroups(groups);
Money total = new Money(5D);
group.setShippingPrice(total);
FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
option.setPrice(new Money(0));
option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
group.setFulfillmentOption(option);
return group;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutTest method testCheckout.
@Test(groups = { "checkout" }, dependsOnGroups = { "createCartForCustomer", "testShippingInsert" }, dataProvider = "USCurrency", dataProviderClass = BroadleafCurrencyProvider.class)
@Transactional
public void testCheckout(BroadleafCurrency usCurrency) throws Exception {
HashMap currencyConsiderationContext = new HashMap();
currencyConsiderationContext.put("aa", "bb");
CurrencyConversionContext.setCurrencyConversionContext(currencyConsiderationContext);
CurrencyConversionContext.setCurrencyConversionService(new CurrencyConversionService() {
@Override
public Money convertCurrency(Money source, Currency destinationCurrency, int destinationScale) {
return source;
}
});
String userName = "customer1";
Customer customer = customerService.readCustomerByUsername(userName);
Order order = orderService.createNewCartForCustomer(customer);
usCurrency = currencyService.save(usCurrency);
order.setCurrency(usCurrency);
Address address = buildAddress();
FulfillmentGroup group = buildFulfillmentGroup(order, address);
addSampleItemToOrder(order, group);
order.setTotalShipping(new Money(0D));
addPaymentToOrder(order, address);
// execute pricing for this order
orderService.save(order, true);
CheckoutResponse response = checkoutService.performCheckout(order);
assert (order.getTotal().greaterThan(order.getSubTotal()));
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroup 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.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method addFulfillmentGroupToOrder.
@Override
public FulfillmentGroup addFulfillmentGroupToOrder(FulfillmentGroupRequest fulfillmentGroupRequest, boolean priceOrder) throws PricingException {
FulfillmentGroup fg = fulfillmentGroupDao.create();
fg.setAddress(fulfillmentGroupRequest.getAddress());
fg.setOrder(fulfillmentGroupRequest.getOrder());
fg.setPhone(fulfillmentGroupRequest.getPhone());
fg.setMethod(fulfillmentGroupRequest.getMethod());
fg.setService(fulfillmentGroupRequest.getService());
for (int i = 0; i < fulfillmentGroupRequest.getFulfillmentGroupItemRequests().size(); i++) {
FulfillmentGroupItemRequest request = fulfillmentGroupRequest.getFulfillmentGroupItemRequests().get(i);
boolean shouldPriceOrder = (priceOrder && (i == (fulfillmentGroupRequest.getFulfillmentGroupItemRequests().size() - 1)));
fg = addItemToFulfillmentGroup(request.getOrderItem(), fg, request.getQuantity(), shouldPriceOrder);
}
return fg;
}
Aggregations