Search in sources :

Example 11 with OrderItem

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

the class LegacyMergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomer(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
                if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                    if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                        itemsToRemove.add(orderItem);
                    }
                } else {
                    if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                        itemsToRemove.add(orderItem);
                    }
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                boolean removeBundle = false;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                        if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                            /*
                                 * Bundle has an inactive item in it -- remove the
                                 * whole bundle
                                 */
                            removeBundle = true;
                            break;
                        }
                    } else {
                        if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                            removeBundle = true;
                            break;
                        }
                    }
                }
                if (removeBundle) {
                    itemsToRemove.add(orderItem);
                }
            }
        }
        // Remove any giftwrap items who have one or more wrapped item members that have been removed
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof GiftWrapOrderItem) {
                for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
                    if (itemsToRemove.contains(wrappedItem)) {
                        itemsToRemove.add(orderItem);
                        break;
                    }
                }
            }
        }
        for (OrderItem item : itemsToRemove) {
            removeItemFromOrder(customerCart, item, priceOrder);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
    }
    reconstructCartResponse.setOrder(customerCart);
    return reconstructCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)

Example 12 with OrderItem

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

the class LegacyOrderServiceImpl method addOrderItemToOrder.

@Override
@Deprecated
public OrderItem addOrderItemToOrder(Order order, OrderItem newOrderItem, boolean priceOrder) throws PricingException {
    if (automaticallyMergeLikeItems) {
        OrderItem item = findMatchingItem(order, newOrderItem);
        if (item != null) {
            item.setQuantity(item.getQuantity() + newOrderItem.getQuantity());
            try {
                updateItemQuantity(order, item, priceOrder);
            } catch (ItemNotFoundException e) {
                LOG.error(e);
            }
            return findMatchingItem(order, newOrderItem);
        }
    }
    List<OrderItem> orderItems = order.getOrderItems();
    orderItems.add(newOrderItem);
    newOrderItem.setOrder(order);
    order = updateOrder(order, priceOrder);
    return findMatchingItem(order, newOrderItem);
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 13 with OrderItem

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

the class LegacyOrderServiceImpl method removeItemFromOrder.

@Override
public Order removeItemFromOrder(Long orderId, Long itemId, boolean priceOrder) throws PricingException {
    Order order = findOrderById(orderId);
    OrderItem orderItem = orderItemService.readOrderItemById(itemId);
    return removeItemFromOrder(order, orderItem, priceOrder);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 14 with OrderItem

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

the class LegacyOrderServiceImpl method moveItemToOrder.

public Order moveItemToOrder(Order originalOrder, Order destinationOrder, OrderItem item, boolean priceOrder) throws PricingException {
    fulfillmentGroupService.removeOrderItemFromFullfillmentGroups(originalOrder, item);
    OrderItem itemFromOrder = originalOrder.getOrderItems().remove(originalOrder.getOrderItems().indexOf(item));
    itemFromOrder.setOrder(null);
    originalOrder = updateOrder(originalOrder, priceOrder);
    addOrderItemToOrder(destinationOrder, item, priceOrder);
    return destinationOrder;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 15 with OrderItem

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

the class LegacyOrderServiceImpl method removeOrderItemAttribute.

@Override
public Order removeOrderItemAttribute(Order order, OrderItem item, String attributeName, boolean priceOrder) throws ItemNotFoundException, PricingException {
    if (!order.getOrderItems().contains(item)) {
        throw new ItemNotFoundException("Order Item (" + item.getId() + ") not found in Order (" + order.getId() + ")");
    }
    OrderItem itemFromOrder = order.getOrderItems().get(order.getOrderItems().indexOf(item));
    boolean changeMade = false;
    Map<String, OrderItemAttribute> orderItemAttributes = itemFromOrder.getOrderItemAttributes();
    if (orderItemAttributes != null) {
        if (orderItemAttributes.containsKey(attributeName)) {
            changeMade = true;
            orderItemAttributes.remove(attributeName);
        }
    }
    if (changeMade) {
        return updateOrder(order, priceOrder);
    } else {
        return order;
    }
}
Also used : OrderItemAttribute(org.broadleafcommerce.core.order.domain.OrderItemAttribute) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Aggregations

OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)100 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)69 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)54 Order (org.broadleafcommerce.core.order.domain.Order)46 ArrayList (java.util.ArrayList)32 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)23 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)20 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)19 Transactional (org.springframework.transaction.annotation.Transactional)19 Test (org.testng.annotations.Test)16 Money (org.broadleafcommerce.common.money.Money)13 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)13 HashMap (java.util.HashMap)11 Sku (org.broadleafcommerce.core.catalog.domain.Sku)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 BigDecimal (java.math.BigDecimal)5 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)5 List (java.util.List)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4