use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class ValidateUpdateRequestActivity 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 when removing from order");
}
// Throw an exception if the user tried to update an item to a negative quantity
if (orderItemRequestDTO.getQuantity() < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
}
// 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 item quantities");
}
// 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) {
throw new IllegalArgumentException("Cannot update an item that is part of a bundle");
}
}
return context;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class AddWorkflowPriceOrderIfNecessaryActivity method updateChildOrderItem.
/**
* Traverses the current OrderItem for a match to the parentOrderItemId.
* If found, populates and returns true.
*
* @param request
* @param orderItem
* @return
*/
protected void updateChildOrderItem(CartOperationRequest request, Order order) {
boolean updated = false;
for (OrderItem oi : order.getOrderItems()) {
if (oi instanceof BundleOrderItem) {
BundleOrderItem boi = (BundleOrderItem) oi;
// check the bundle children
updated = checkAndUpdateChildren(request, boi);
if (!updated) {
for (OrderItem discreteOrderItem : boi.getDiscreteOrderItems()) {
// check the bundle discrete items
if (checkAndUpdateChildren(request, discreteOrderItem)) {
updated = true;
// break out of the discrete items loop
break;
}
}
}
} else {
updated = checkAndUpdateChildren(request, oi);
}
if (updated) {
break;
}
}
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class AddWorkflowPriceOrderIfNecessaryActivity method checkAndUpdateChildren.
protected boolean checkAndUpdateChildren(CartOperationRequest request, OrderItem orderItem) {
boolean parentUpdated = false;
if (orderItem.getId().equals(request.getItemRequest().getParentOrderItemId())) {
orderItem.getChildOrderItems().add(request.getOrderItem());
parentUpdated = true;
} else {
if (CollectionUtils.isNotEmpty(orderItem.getChildOrderItems())) {
for (OrderItem childOrderItem : orderItem.getChildOrderItems()) {
parentUpdated = checkAndUpdateChildren(request, childOrderItem);
if (parentUpdated) {
break;
}
}
}
}
return parentUpdated;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method createFulfillmentGroups.
private List<FulfillmentGroup> createFulfillmentGroups(FulfillmentOption option, Double shippingPrice, Order order) {
List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setFulfillmentOption(option);
groups.add(group);
group.setRetailShippingPrice(new Money(shippingPrice));
group.setOrder(order);
Address address = new AddressImpl();
address.setAddressLine1("123 Test Rd");
address.setCity("Dallas");
address.setFirstName("Jeff");
address.setLastName("Fischer");
address.setPostalCode("75240");
address.setPrimaryPhone("972-978-9067");
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
stateService.save(state);
address.setState(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
for (OrderItem orderItem : order.getOrderItems()) {
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(orderItem);
fgItem.setQuantity(orderItem.getQuantity());
group.addFulfillmentGroupItem(fgItem);
}
group.setAddress(address);
return groups;
}
use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class CartTest method testMoveAllItemsToCartFromNamedOrder.
@Test(groups = { "testCartAndNamedOrder" })
@Transactional
public void testMoveAllItemsToCartFromNamedOrder() throws RemoveFromCartException, AddToCartException {
Order namedOrder = setUpNamedOrder();
List<OrderItem> namedOrderItems = new ArrayList<>();
namedOrderItems.addAll(namedOrder.getOrderItems());
Order cart = orderService.createNewCartForCustomer(namedOrder.getCustomer());
cart = orderService.addAllItemsFromNamedOrder(namedOrder, true);
assert cartContainsOnlyTheseItems(cart, namedOrderItems);
assert namedOrder.getOrderItems().size() == 0;
}
Aggregations