Search in sources :

Example 6 with BundleOrderItem

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

the class FulfillmentGroupItemStrategyImpl method onItemAdded.

@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
    FulfillmentGroup nullFulfillmentTypeGroup = null;
    // We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup group : order.getFulfillmentGroups()) {
            if (group.getType() == null) {
                if (nullFulfillmentTypeGroup == null) {
                    nullFulfillmentTypeGroup = group;
                }
            } else {
                if (fulfillmentGroups.get(group.getType()) == null) {
                    fulfillmentGroups.put(group.getType(), group);
                }
            }
        }
    }
    if (orderItem instanceof BundleOrderItem) {
        // We only care about the discrete order items
        List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
        for (DiscreteOrderItem doi : itemsToAdd) {
            FulfillmentGroup fulfillmentGroup = null;
            FulfillmentType type = resolveFulfillmentType(doi);
            if (type == null) {
                // Use the fulfillment group with a null type
                fulfillmentGroup = nullFulfillmentTypeGroup;
            } else {
                if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                    // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                    // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                    type = FulfillmentType.PHYSICAL_SHIP;
                }
                // Use the fulfillment group with the specified type
                fulfillmentGroup = fulfillmentGroups.get(type);
            }
            // If the null type or specified type, above were null, then we need to create a new fulfillment group
            boolean createdFulfillmentGroup = false;
            if (fulfillmentGroup == null) {
                fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
                // Set the type
                fulfillmentGroup.setType(type);
                fulfillmentGroup.setOrder(order);
                order.getFulfillmentGroups().add(fulfillmentGroup);
                createdFulfillmentGroup = true;
            }
            fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
            order = fulfillmentGroup.getOrder();
            // of fulfillment groups
            if (createdFulfillmentGroup) {
                if (type == null) {
                    nullFulfillmentTypeGroup = fulfillmentGroup;
                } else {
                    fulfillmentGroups.put(type, fulfillmentGroup);
                }
            }
        }
    } else if (orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        FulfillmentGroup fulfillmentGroup = null;
        FulfillmentType type = resolveFulfillmentType(doi);
        if (type == null) {
            // Use the fulfillment group with a null type
            fulfillmentGroup = nullFulfillmentTypeGroup;
        } else {
            if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                type = FulfillmentType.PHYSICAL_SHIP;
            }
            // Use the fulfillment group with the specified type
            fulfillmentGroup = fulfillmentGroups.get(type);
        }
        // If the null type or specified type, above were null, then we need to create a new fulfillment group
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            // Set the type
            fulfillmentGroup.setType(type);
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
        order = fulfillmentGroup.getOrder();
    } else {
        FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) HashMap(java.util.HashMap) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentType(org.broadleafcommerce.core.order.service.type.FulfillmentType)

Example 7 with BundleOrderItem

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

the class FulfillmentGroupItemStrategyImpl method onItemRemoved.

@Override
public CartOperationRequest onItemRemoved(CartOperationRequest request) {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    if (orderItem instanceof BundleOrderItem) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
        for (OrderItem oi : itemsToRemove) {
            request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, oi));
        }
    } else {
        request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, orderItem));
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList)

Example 8 with BundleOrderItem

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

the class RemoveOrderMultishipOptionActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    Long orderItemId = request.getItemRequest().getOrderItemId();
    OrderItem orderItem = request.getOrderItem();
    if (orderItem instanceof BundleOrderItem) {
        for (OrderItem discrete : ((BundleOrderItem) orderItem).getDiscreteOrderItems()) {
            request.getMultishipOptionsToDelete().add(new Long[] { discrete.getId(), null });
        }
    } else {
        request.getMultishipOptionsToDelete().add(new Long[] { orderItemId, null });
    }
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 9 with BundleOrderItem

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

the class AddWorkflowPriceOrderIfNecessaryActivity method updateChildOrderItem.

/**
 * Traverses the current OrderItem for a match to the parentOrderItemId.
 * If found, populates and returns true.
 *
 * @param request
 * @param orderItem
 * @return
 */
protected void updateChildOrderItem(CartOperationRequest request, Order order) {
    boolean updated = false;
    for (OrderItem oi : order.getOrderItems()) {
        if (oi instanceof BundleOrderItem) {
            BundleOrderItem boi = (BundleOrderItem) oi;
            // check the bundle children
            updated = checkAndUpdateChildren(request, boi);
            if (!updated) {
                for (OrderItem discreteOrderItem : boi.getDiscreteOrderItems()) {
                    // check the bundle discrete items
                    if (checkAndUpdateChildren(request, discreteOrderItem)) {
                        updated = true;
                        // break out of the discrete items loop
                        break;
                    }
                }
            }
        } else {
            updated = checkAndUpdateChildren(request, oi);
        }
        if (updated) {
            break;
        }
    }
}
Also used : BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 10 with BundleOrderItem

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

the class OrderTest method addBundleToOrder.

@Test(groups = { "addBundleToOrder" }, dependsOnGroups = { "addAnotherItemToOrder" })
@Rollback(false)
@Transactional
public void addBundleToOrder() throws AddToCartException {
    numOrderItems++;
    Sku sku = skuDao.readFirstSku();
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    assert sku.getId() != null;
    ProductBundle bundleItem = addProductBundle();
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setProductId(bundleItem.getId());
    orderItemRequestDTO.setSkuId(bundleItem.getDefaultSku().getId());
    orderItemRequestDTO.setQuantity(1);
    order = orderService.addItem(order.getId(), orderItemRequestDTO, true);
    BundleOrderItem item = (BundleOrderItem) orderService.findLastMatchingItem(order, bundleItem.getDefaultSku().getId(), null);
    bundleOrderItemId = item.getId();
    assert item != null;
    assert item.getQuantity() == 1;
    assert item.getDiscreteOrderItems().size() == 1;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)35 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)30 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)23 Order (org.broadleafcommerce.core.order.domain.Order)16 ArrayList (java.util.ArrayList)13 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)10 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)9 Sku (org.broadleafcommerce.core.catalog.domain.Sku)8 HashMap (java.util.HashMap)7 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)5 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Product (org.broadleafcommerce.core.catalog.domain.Product)4 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)4 Test (org.testng.annotations.Test)4 List (java.util.List)3 Money (org.broadleafcommerce.common.money.Money)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)3 BigDecimal (java.math.BigDecimal)2