Search in sources :

Example 91 with OrderItem

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

the class LegacyMergeCartServiceImpl method mergeCart.

@Override
public MergeCartResponse mergeCart(Customer customer, Order anonymousCart, boolean priceOrder) throws PricingException {
    MergeCartResponse mergeCartResponse = new MergeCartResponse();
    // reconstruct cart items (make sure they are valid)
    ReconstructCartResponse reconstructCartResponse = reconstructCart(customer, false);
    mergeCartResponse.setRemovedItems(reconstructCartResponse.getRemovedItems());
    Order customerCart = reconstructCartResponse.getOrder();
    if (anonymousCart != null && customerCart != null && anonymousCart.getId().equals(customerCart.getId())) {
        /*
             * Set merged to false if the cart ids are equal (cookied customer
             * logs in).
             */
        mergeCartResponse.setMerged(false);
    } else {
        /*
             * Set the response to merged if the saved cart has any items
             * available to merge in.
             */
        mergeCartResponse.setMerged(customerCart != null && customerCart.getOrderItems().size() > 0);
    }
    // add anonymous cart items (make sure they are valid)
    if (anonymousCart != null && (customerCart == null || !customerCart.getId().equals(anonymousCart.getId()))) {
        if (anonymousCart != null && anonymousCart.getOrderItems() != null && !anonymousCart.getOrderItems().isEmpty()) {
            if (customerCart == null) {
                customerCart = orderService.createNewCartForCustomer(customer);
            }
            Map<OrderItem, OrderItem> oldNewItemMap = new HashMap<OrderItem, OrderItem>();
            customerCart = mergeRegularOrderItems(anonymousCart, mergeCartResponse, customerCart, oldNewItemMap);
            customerCart = mergeOfferCodes(anonymousCart, customerCart);
            customerCart = removeExpiredGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);
            customerCart = mergeGiftWrapOrderItems(mergeCartResponse, customerCart, oldNewItemMap);
            orderService.cancelOrder(anonymousCart);
        }
    }
    // copy the customer's email to this order, overriding any previously set email
    if (customerCart != null && StringUtils.isNotBlank(customer.getEmailAddress())) {
        customerCart.setEmailAddress(customer.getEmailAddress());
        customerCart = orderService.save(customerCart, priceOrder);
    }
    mergeCartResponse.setOrder(customerCart);
    return mergeCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) HashMap(java.util.HashMap) 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) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse) MergeCartResponse(org.broadleafcommerce.core.order.service.call.MergeCartResponse)

Example 92 with OrderItem

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

the class LegacyOrderServiceImpl method addOrUpdateOrderItemAttributes.

/**
 * Adds the passed in name/value pair to the order-item.    If the
 * attribute already exists, then it is updated with the new value.
 * <p/>
 * If the value passed in is null and the attribute exists, it is removed
 * from the order item.
 *
 * @param order
 * @param item
 * @param attributeValues
 * @param priceOrder
 * @return
 */
@Override
public Order addOrUpdateOrderItemAttributes(Order order, OrderItem item, Map<String, String> attributeValues, 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));
    Map<String, OrderItemAttribute> orderItemAttributes = itemFromOrder.getOrderItemAttributes();
    if (orderItemAttributes == null) {
        orderItemAttributes = new HashMap<String, OrderItemAttribute>();
        itemFromOrder.setOrderItemAttributes(orderItemAttributes);
    }
    boolean changeMade = false;
    for (String attributeName : attributeValues.keySet()) {
        String attributeValue = attributeValues.get(attributeName);
        OrderItemAttribute attribute = orderItemAttributes.get(attributeName);
        if (attribute != null && attribute.getValue().equals(attributeValue)) {
            // no change made.
            continue;
        } else {
            changeMade = true;
            if (attribute == null) {
                attribute = new OrderItemAttributeImpl();
                attribute.setOrderItem(itemFromOrder);
                attribute.setName(attributeName);
                attribute.setValue(attributeValue);
            } else if (attributeValue == null) {
                orderItemAttributes.remove(attributeValue);
            } else {
                attribute.setValue(attributeValue);
            }
        }
    }
    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) OrderItemAttributeImpl(org.broadleafcommerce.core.order.domain.OrderItemAttributeImpl) ItemNotFoundException(org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)

Example 93 with OrderItem

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

the class LegacyOrderServiceImpl method createDefaultFulfillmentGroup.

@Override
public FulfillmentGroup createDefaultFulfillmentGroup(Order order, Address address) {
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        if (fulfillmentGroup.isPrimary()) {
            return fulfillmentGroup;
        }
    }
    FulfillmentGroup newFg = fulfillmentGroupService.createEmptyFulfillmentGroup();
    newFg.setOrder(order);
    newFg.setPrimary(true);
    newFg.setAddress(address);
    for (OrderItem orderItem : order.getOrderItems()) {
        newFg.addFulfillmentGroupItem(createFulfillmentGroupItemFromOrderItem(orderItem, newFg, orderItem.getQuantity()));
    }
    return newFg;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 94 with OrderItem

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

the class LegacyOrderServiceImpl method removeItemFromOrder.

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

Example 95 with OrderItem

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

the class OrderServiceImpl method addAllItemsFromNamedOrder.

@Override
@Transactional("blTransactionManager")
public Order addAllItemsFromNamedOrder(Order namedOrder, boolean priceOrder) throws RemoveFromCartException, AddToCartException {
    Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
    if (cartOrder == null) {
        cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
    }
    List<OrderItem> items = new ArrayList<OrderItem>(namedOrder.getOrderItems());
    // Remove any order items that are children
    CollectionUtils.filter(items, new TypedPredicate<OrderItem>() {

        @Override
        public boolean eval(OrderItem orderItem) {
            return orderItem.getParentOrderItem() == null;
        }
    });
    for (OrderItem item : items) {
        OrderItemRequestDTO orderItemRequest = orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
        cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);
        if (moveNamedOrderItems) {
            removeItem(namedOrder.getId(), item.getId(), false);
        }
    }
    if (deleteEmptyNamedOrders) {
        cancelOrder(namedOrder);
    }
    return cartOrder;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

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