use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCartController method isSafeToAdd.
protected boolean isSafeToAdd(ConfigurableOrderItemRequest itemRequest) {
if (!automaticallyAddCompleteItems) {
return false;
}
boolean canSafelyAdd = true;
for (OrderItemRequestDTO child : itemRequest.getChildOrderItems()) {
ConfigurableOrderItemRequest configurableRequest = (ConfigurableOrderItemRequest) child;
Product childProduct = configurableRequest.getProduct();
if (childProduct == null) {
return false;
}
int minQty = configurableRequest.getMinQuantity();
if (minQty == 0 || childProduct.getProductOptionXrefs().size() > 0) {
return false;
}
canSafelyAdd = isSafeToAdd(configurableRequest);
}
return canSafelyAdd;
}
use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method findAllChildProductsInRequest.
protected Set<Product> findAllChildProductsInRequest(List<OrderItemRequestDTO> childItems) {
Set<Product> allProductsSet = new HashSet<Product>();
for (OrderItemRequestDTO child : childItems) {
ConfigurableOrderItemRequest configChild = (ConfigurableOrderItemRequest) child;
Product childProduct = configChild.getProduct();
if (childProduct != null) {
allProductsSet.add(childProduct);
} else {
List<OrderItemRequestDTO> productChoices = new ArrayList<OrderItemRequestDTO>(configChild.getProductChoices());
allProductsSet.addAll(findAllChildProductsInRequest(productChoices));
}
}
return allProductsSet;
}
use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.
the class UpdateProductOptionsOrderItemActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Order order = request.getOrder();
if (orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())) != null) {
DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
orderItemService.updateDiscreteOrderItem(orderItemService.readOrderItemById(Long.valueOf(orderItemRequestDTO.getOrderItemId())), itemRequest);
}
order = orderService.save(order, false);
request.setOrder(order);
return context;
}
use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.
the class CheckUpdateAvailabilityActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
return context;
}
Sku sku;
Long orderItemId = request.getItemRequest().getOrderItemId();
OrderItem orderItem = orderItemService.readOrderItemById(orderItemId);
if (orderItem instanceof DiscreteOrderItem) {
sku = ((DiscreteOrderItem) orderItem).getSku();
} else if (orderItem instanceof BundleOrderItem) {
sku = ((BundleOrderItem) orderItem).getSku();
} else {
LOG.warn("Could not check availability; did not recognize passed-in item " + orderItem.getClass().getName());
return context;
}
Order order = context.getSeedData().getOrder();
Integer requestedQuantity = request.getItemRequest().getQuantity();
checkSkuAvailability(order, sku, requestedQuantity);
Integer previousQty = orderItem.getQuantity();
for (OrderItem child : orderItem.getChildOrderItems()) {
Sku childSku = ((DiscreteOrderItem) child).getSku();
Integer childQuantity = child.getQuantity();
childQuantity = childQuantity / previousQty;
checkSkuAvailability(order, childSku, childQuantity * requestedQuantity);
}
return context;
}
use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.
the class ValidateAddRequestActivity method validate.
protected ProcessContext<CartOperationRequest> validate(ProcessContext<CartOperationRequest> context) {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Integer orderItemQuantity = orderItemRequestDTO.getQuantity();
if (!hasQuantity(orderItemQuantity)) {
context.stopProcess();
} else if (orderItemQuantity < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
} else if (request.getOrder() == null) {
throw new IllegalArgumentException("Order is required when adding item to order");
} else {
Product product = determineProduct(orderItemRequestDTO);
Sku sku;
try {
sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes(), (ActivityMessages) context);
} catch (RequiredAttributeNotProvidedException e) {
if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
// Mark the request as a configuration error and proceed with the add.
orderItemRequestDTO.setHasConfigurationError(Boolean.TRUE);
return context;
}
throw e;
}
addSkuToCart(sku, orderItemRequestDTO, product, request);
if (!hasSameCurrency(orderItemRequestDTO, request, sku)) {
throw new IllegalArgumentException("Cannot have items with differing currencies in one cart");
}
validateIfParentOrderItemExists(orderItemRequestDTO);
}
return context;
}
Aggregations