Search in sources :

Example 1 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method addItemFromNamedOrder.

@Override
@Transactional("blTransactionManager")
public Order addItemFromNamedOrder(Order namedOrder, OrderItem item, boolean priceOrder) throws RemoveFromCartException, AddToCartException {
    Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
    if (cartOrder == null) {
        cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
    }
    OrderItemRequestDTO orderItemRequest = orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
    cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);
    if (moveNamedOrderItems) {
        removeItem(namedOrder.getId(), item.getId(), false);
    }
    if (namedOrder.getOrderItems().size() == 0 && deleteEmptyNamedOrders) {
        cancelOrder(namedOrder);
    }
    return cartOrder;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method addItemFromNamedOrder.

@Override
@Transactional("blTransactionManager")
public Order addItemFromNamedOrder(Order namedOrder, OrderItem item, int quantity, boolean priceOrder) throws RemoveFromCartException, AddToCartException, UpdateCartException {
    // Validate that the quantity requested makes sense
    if (quantity < 1 || quantity > item.getQuantity()) {
        throw new IllegalArgumentException("Cannot move 0 or less quantity");
    } else if (quantity == item.getQuantity()) {
        return addItemFromNamedOrder(namedOrder, item, priceOrder);
    }
    Order cartOrder = orderDao.readCartForCustomer(namedOrder.getCustomer());
    if (cartOrder == null) {
        cartOrder = createNewCartForCustomer(namedOrder.getCustomer());
    }
    OrderItemRequestDTO orderItemRequest = orderItemService.buildOrderItemRequestDTOFromOrderItem(item);
    orderItemRequest.setQuantity(quantity);
    cartOrder = addItem(cartOrder.getId(), orderItemRequest, priceOrder);
    if (moveNamedOrderItems) {
        // Update the old item to its new quantity only if we're moving items
        OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
        orderItemRequestDTO.setOrderItemId(item.getId());
        orderItemRequestDTO.setQuantity(item.getQuantity() - quantity);
        updateItemQuantity(namedOrder.getId(), orderItemRequestDTO, false);
    }
    return cartOrder;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method addChildItems.

@Override
public void addChildItems(OrderItemRequestDTO orderItemRequestDTO, int numAdditionRequests, int currentAddition, ProcessContext<CartOperationRequest> context, List<ActivityMessageDTO> orderMessages) throws WorkflowException {
    if (CollectionUtils.isNotEmpty(orderItemRequestDTO.getChildOrderItems())) {
        Long parentOrderItemId = context.getSeedData().getOrderItem().getId();
        for (OrderItemRequestDTO childRequest : orderItemRequestDTO.getChildOrderItems()) {
            childRequest.setParentOrderItemId(parentOrderItemId);
            currentAddition++;
            if (childRequest.getQuantity() > 0) {
                CartOperationRequest childCartOpRequest = new CartOperationRequest(context.getSeedData().getOrder(), childRequest, currentAddition == numAdditionRequests);
                Session session = em.unwrap(Session.class);
                FlushMode current = session.getFlushMode();
                if (!autoFlushAddToCart) {
                    // Performance measure. Hibernate will sometimes perform an autoflush when performing query operations and this can
                    // be expensive. It is possible to avoid the autoflush if there's no concern about queries in the flow returning
                    // incorrect results because something has not been flushed to the database yet.
                    session.setFlushMode(FlushMode.MANUAL);
                }
                ProcessContext<CartOperationRequest> childContext;
                try {
                    childContext = (ProcessContext<CartOperationRequest>) addItemWorkflow.doActivities(childCartOpRequest);
                } finally {
                    if (!autoFlushAddToCart) {
                        session.setFlushMode(current);
                    }
                }
                orderMessages.addAll(((ActivityMessages) childContext).getActivityMessages());
                addChildItems(childRequest, numAdditionRequests, currentAddition, childContext, orderMessages);
            }
        }
    }
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) FlushMode(org.hibernate.FlushMode) Session(org.hibernate.Session)

Example 4 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method addSkuToOrder.

@Override
@Deprecated
public OrderItem addSkuToOrder(Long orderId, Long skuId, Long productId, Long categoryId, Integer quantity, boolean priceOrder, Map<String, String> itemAttributes) throws PricingException {
    if (orderId == null || (productId == null && skuId == null) || quantity == null) {
        return null;
    }
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setCategoryId(categoryId);
    orderItemRequestDTO.setProductId(productId);
    orderItemRequestDTO.setSkuId(skuId);
    orderItemRequestDTO.setQuantity(quantity);
    orderItemRequestDTO.setItemAttributes(itemAttributes);
    Order order = addItemToOrder(orderId, orderItemRequestDTO, priceOrder);
    if (order == null) {
        return null;
    }
    return findLastMatchingItem(order, skuId, productId);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)

Example 5 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class ValidateUpdateProductOptionsRequestActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
    // Throw an exception if the user did not specify an orderItemId
    if (orderItemRequestDTO.getOrderItemId() == null) {
        throw new IllegalArgumentException("OrderItemId must be specified to locate the order item");
    }
    // Throw an exception if the user did not specify an order to add the item to
    if (request.getOrder() == null) {
        throw new IllegalArgumentException("Order is required when updating items in the order");
    }
    // Throw an exception if the user is trying to update an order item that is part of a bundle
    OrderItem orderItem = orderItemService.readOrderItemById(orderItemRequestDTO.getOrderItemId());
    if (orderItem != null && orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        if (doi.getBundleOrderItem() != null) {
        // then its ok , since we are just updating the product options
        }
    }
    return context;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem)

Aggregations

OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)30 Order (org.broadleafcommerce.core.order.domain.Order)19 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 Transactional (org.springframework.transaction.annotation.Transactional)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 Product (org.broadleafcommerce.core.catalog.domain.Product)8 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)8 Test (org.testng.annotations.Test)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)5 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)4 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)4 ArrayList (java.util.ArrayList)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)3 AddToCartException (org.broadleafcommerce.core.order.service.exception.AddToCartException)3 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 Rollback (org.springframework.test.annotation.Rollback)3 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)2