Search in sources :

Example 16 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class UpdateOrderMultishipOptionActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    Long orderItemId = request.getItemRequest().getOrderItemId();
    Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
    if (orderItemQuantityDelta < 0) {
        int numToDelete = -1 * orderItemQuantityDelta;
        // find the qty in the default fg
        OrderItem orderItem = request.getOrderItem();
        int qty = 0;
        if (!CollectionUtils.isEmpty(orderItem.getOrder().getFulfillmentGroups())) {
            FulfillmentGroup fg = orderItem.getOrder().getFulfillmentGroups().get(0);
            if (fg.getAddress() == null && fg.getFulfillmentOption() == null) {
                for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
                    if (fgItem.getOrderItem().getId().equals(orderItemId)) {
                        qty += fgItem.getQuantity();
                    }
                }
            }
        }
        if (numToDelete >= qty) {
            request.getMultishipOptionsToDelete().add(new Long[] { orderItemId, (long) (numToDelete - qty) });
        }
    }
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 17 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method removeItemInternal.

protected Order removeItemInternal(Long orderId, Long orderItemId, boolean priceOrder) throws WorkflowException {
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(orderItemId);
    CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder);
    Session session = em.unwrap(Session.class);
    FlushMode current = session.getFlushMode();
    if (!autoFlushRemoveFromCart) {
        // 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> context;
    try {
        context = (ProcessContext<CartOperationRequest>) removeItemWorkflow.doActivities(cartOpRequest);
    } finally {
        if (!autoFlushRemoveFromCart) {
            session.setFlushMode(current);
        }
    }
    context.getSeedData().getOrder().getOrderMessages().addAll(((ActivityMessages) context).getActivityMessages());
    return context.getSeedData().getOrder();
}
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 18 with CartOperationRequest

use of org.broadleafcommerce.core.order.service.workflow.CartOperationRequest in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method updateItemQuantity.

@Override
@Transactional(value = "blTransactionManager", rollbackFor = { UpdateCartException.class, RemoveFromCartException.class })
public Order updateItemQuantity(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws UpdateCartException, RemoveFromCartException {
    Order order = findOrderById(orderId);
    preValidateCartOperation(order);
    preValidateUpdateQuantityOperation(findOrderById(orderId), orderItemRequestDTO);
    if (orderItemRequestDTO.getQuantity() == 0) {
        return removeItem(orderId, orderItemRequestDTO.getOrderItemId(), priceOrder);
    }
    try {
        CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder);
        Session session = em.unwrap(Session.class);
        FlushMode current = session.getFlushMode();
        if (!autoFlushUpdateCart) {
            // 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> context;
        try {
            context = (ProcessContext<CartOperationRequest>) updateItemWorkflow.doActivities(cartOpRequest);
        } finally {
            if (!autoFlushUpdateCart) {
                session.setFlushMode(current);
            }
        }
        context.getSeedData().getOrder().getOrderMessages().addAll(((ActivityMessages) context).getActivityMessages());
        return context.getSeedData().getOrder();
    } catch (WorkflowException e) {
        throw new UpdateCartException("Could not update cart quantity", getCartOperationExceptionRootCause(e));
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) UpdateCartException(org.broadleafcommerce.core.order.service.exception.UpdateCartException) FlushMode(org.hibernate.FlushMode) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)18 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)9 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)9 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Order (org.broadleafcommerce.core.order.domain.Order)5 FlushMode (org.hibernate.FlushMode)4 Session (org.hibernate.Session)4 UpdateCartException (org.broadleafcommerce.core.order.service.exception.UpdateCartException)3 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)2 ArrayList (java.util.ArrayList)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)1 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)1 ActivityMessageDTO (org.broadleafcommerce.core.order.service.call.ActivityMessageDTO)1 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)1 DiscreteOrderItemRequest (org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)1