Search in sources :

Example 1 with FulfillmentGroup

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;
        }
    };
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) IAnswer(org.easymock.IAnswer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 2 with FulfillmentGroup

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;
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)

Example 3 with FulfillmentGroup

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()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Address(org.broadleafcommerce.profile.core.domain.Address) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer) Currency(java.util.Currency) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CurrencyConversionService(org.broadleafcommerce.common.money.CurrencyConversionService) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with FulfillmentGroup

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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with FulfillmentGroup

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;
}
Also used : FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentGroupItemRequest(org.broadleafcommerce.core.order.service.call.FulfillmentGroupItemRequest)

Aggregations

FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)67 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)39 Order (org.broadleafcommerce.core.order.domain.Order)32 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)24 Money (org.broadleafcommerce.common.money.Money)22 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)19 Transactional (org.springframework.transaction.annotation.Transactional)17 ArrayList (java.util.ArrayList)16 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)15 Address (org.broadleafcommerce.profile.core.domain.Address)15 Test (org.testng.annotations.Test)12 Sku (org.broadleafcommerce.core.catalog.domain.Sku)9 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)9 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)8 Customer (org.broadleafcommerce.profile.core.domain.Customer)8 HashMap (java.util.HashMap)7 BigDecimal (java.math.BigDecimal)6 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)6 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)6 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)5