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;
}
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();
}
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));
}
}
Aggregations