Search in sources :

Example 6 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.

the class AddWorkflowPriceOrderIfNecessaryActivity method getOiFgiMap.

protected void getOiFgiMap(Order order, Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap, OrderItem oi) {
    List<FulfillmentGroupItem> fgis = new ArrayList<>();
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            if (fgi.getOrderItem().equals(oi)) {
                fgis.add(fgi);
            }
        }
    }
    oiFgiMap.put(oi, fgis);
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 7 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.

the class OfferTest method createFulfillmentGroups.

private List<FulfillmentGroup> createFulfillmentGroups(FulfillmentOption option, Double shippingPrice, Order order) {
    List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setFulfillmentOption(option);
    groups.add(group);
    group.setRetailShippingPrice(new Money(shippingPrice));
    group.setOrder(order);
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    countryService.save(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    isoService.save(isoCountry);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setName("Texas");
    state.setCountry(country);
    stateService.save(state);
    address.setState(state);
    address.setCountry(country);
    address.setIsoCountrySubdivision("US-TX");
    address.setIsoCountryAlpha2(isoCountry);
    for (OrderItem orderItem : order.getOrderItems()) {
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(orderItem);
        fgItem.setQuantity(orderItem.getQuantity());
        group.addFulfillmentGroupItem(fgItem);
    }
    group.setAddress(address);
    return groups;
}
Also used : FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) ArrayList(java.util.ArrayList) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) Money(org.broadleafcommerce.common.money.Money) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 8 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupItemDaoTest method createFulfillmentGroupItem.

@Test(groups = { "createFulfillmentGroupItem" }, dataProvider = "basicDiscreteOrderItem", dataProviderClass = OrderItemDataProvider.class, dependsOnGroups = { "createOrder", "createSku", "createItemFulfillmentGroup" })
@Rollback(false)
@Transactional
public void createFulfillmentGroupItem(DiscreteOrderItem orderItem) throws PricingException {
    Sku si = skuDao.readFirstSku();
    orderItem.setSku(si);
    orderItem = (DiscreteOrderItem) orderItemDao.save(orderItem);
    orderItem.setOrder(salesOrder);
    salesOrder.addOrderItem(orderItem);
    orderDao.save(salesOrder);
    FulfillmentGroupItemRequest fulfillmentGroupItemRequest = new FulfillmentGroupItemRequest();
    fulfillmentGroupItemRequest.setOrderItem(orderItem);
    fulfillmentGroupItemRequest.setFulfillmentGroup(fulfillmentGroup);
    fulfillmentGroupService.addItemToFulfillmentGroup(fulfillmentGroupItemRequest, true);
    FulfillmentGroupItem fgi = fulfillmentGroup.getFulfillmentGroupItems().get(fulfillmentGroup.getFulfillmentGroupItems().size() - 1);
    assert fgi.getId() != null;
    fulfillmentGroupItemId = fgi.getId();
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) Sku(org.broadleafcommerce.core.catalog.domain.Sku) FulfillmentGroupItemRequest(org.broadleafcommerce.core.order.service.call.FulfillmentGroupItemRequest) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveEqualItems.

public void testDistributeOneDollarAcrossFiveEqualItems() throws Exception {
    Order order = dataProvider.createBasicOrder();
    Money subTotal = new Money(order.getCurrency());
    for (OrderItem orderItem : order.getOrderItems()) {
        orderItem.setSalePrice(new Money(10D));
        orderItem.getOrderItemPriceDetails().clear();
        subTotal = subTotal.add(orderItem.getTotalPrice());
    }
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
    order.getOrderAdjustments().add(adjustment);
    adjustment.setOrder(order);
    order.setSubTotal(subTotal);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    // Each item is equally priced, so the adjustment should be .20 per item.
    Money proratedAdjustment = new Money(".20");
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().compareTo(proratedAdjustment.multiply(fulfillmentGroupItem.getQuantity())) == 0);
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) BigDecimal(java.math.BigDecimal)

Example 10 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.

the class OrderTest method updateItemsInOrder.

@Test(groups = { "updateItemsInOrder" }, dependsOnGroups = { "getItemsForOrder" })
@Transactional
public void updateItemsInOrder() throws UpdateCartException, RemoveFromCartException {
    // Grab the order and the first OrderItem
    Order order = orderService.findOrderById(orderId);
    List<OrderItem> orderItems = order.getOrderItems();
    assert orderItems.size() > 0;
    OrderItem item = orderItems.get(0);
    // Set the quantity of the first OrderItem to 10
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(10);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the quantity has changed
    OrderItem updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem != null;
    assert updatedItem.getQuantity() == 10;
    // Assert that the appropriate fulfillment group item has changed
    assert order.getFulfillmentGroups().size() == 1;
    FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    boolean fgItemUpdated = false;
    for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
        if (fgi.getOrderItem().equals(updatedItem)) {
            assert fgi.getQuantity() == 10;
            fgItemUpdated = true;
        }
    }
    assert fgItemUpdated;
    // Set the quantity of the first OrderItem to 5
    orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(5);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the quantity has changed - going to a smaller quantity is also ok
    updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem != null;
    assert updatedItem.getQuantity() == 5;
    // Assert that the appropriate fulfillment group item has changed
    assert order.getFulfillmentGroups().size() == 1;
    fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    fgItemUpdated = false;
    for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
        if (fgi.getOrderItem().equals(updatedItem)) {
            assert fgi.getQuantity() == 5;
            fgItemUpdated = true;
        }
    }
    assert fgItemUpdated;
    // Setting the quantity to 0 should in fact remove the item completely
    int startingSize = order.getOrderItems().size();
    orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(0);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the item has been removed
    updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem == null;
    assert order.getOrderItems().size() == startingSize - 1;
    // Assert that the appropriate fulfillment group item has been removed
    assert order.getFulfillmentGroups().size() == 0;
/*
        TODO Since we commented out some tests above, there is no longer an additional item
        in the cart, hence the fulfillment group is removed

        fg = order.getFulfillmentGroups().get(0);
        assert fg.getFulfillmentGroupItems().size() == startingSize - 1;
        boolean fgItemRemoved = true;
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            if (fgi.getOrderItem().equals(updatedItem)) {
                fgItemRemoved = false;
            }
        }
        assert fgItemRemoved;*/
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)48 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)39 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)25 Order (org.broadleafcommerce.core.order.domain.Order)21 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)20 Money (org.broadleafcommerce.common.money.Money)18 ArrayList (java.util.ArrayList)16 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)15 Sku (org.broadleafcommerce.core.catalog.domain.Sku)12 Transactional (org.springframework.transaction.annotation.Transactional)11 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)9 Address (org.broadleafcommerce.profile.core.domain.Address)9 BigDecimal (java.math.BigDecimal)8 Test (org.testng.annotations.Test)8 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)7 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)7 HashMap (java.util.HashMap)6 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)6 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)5