use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemAdded.
@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
FulfillmentGroup nullFulfillmentTypeGroup = null;
// We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
if (order.getFulfillmentGroups() != null) {
for (FulfillmentGroup group : order.getFulfillmentGroups()) {
if (group.getType() == null) {
if (nullFulfillmentTypeGroup == null) {
nullFulfillmentTypeGroup = group;
}
} else {
if (fulfillmentGroups.get(group.getType()) == null) {
fulfillmentGroups.put(group.getType(), group);
}
}
}
}
if (orderItem instanceof BundleOrderItem) {
// We only care about the discrete order items
List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (DiscreteOrderItem doi : itemsToAdd) {
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
boolean createdFulfillmentGroup = false;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
createdFulfillmentGroup = true;
}
fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
order = fulfillmentGroup.getOrder();
// of fulfillment groups
if (createdFulfillmentGroup) {
if (type == null) {
nullFulfillmentTypeGroup = fulfillmentGroup;
} else {
fulfillmentGroups.put(type, fulfillmentGroup);
}
}
}
} else if (orderItem instanceof DiscreteOrderItem) {
DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
FulfillmentGroup fulfillmentGroup = null;
FulfillmentType type = resolveFulfillmentType(doi);
if (type == null) {
// Use the fulfillment group with a null type
fulfillmentGroup = nullFulfillmentTypeGroup;
} else {
if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
// This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
// However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
type = FulfillmentType.PHYSICAL_SHIP;
}
// Use the fulfillment group with the specified type
fulfillmentGroup = fulfillmentGroups.get(type);
}
// If the null type or specified type, above were null, then we need to create a new fulfillment group
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
// Set the type
fulfillmentGroup.setType(type);
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
order = fulfillmentGroup.getOrder();
} else {
FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
if (fulfillmentGroup == null) {
fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
fulfillmentGroup.setOrder(order);
order.getFulfillmentGroups().add(fulfillmentGroup);
}
fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
}
return request;
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemRemoved.
@Override
public CartOperationRequest onItemRemoved(CartOperationRequest request) {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
if (orderItem instanceof BundleOrderItem) {
List<OrderItem> itemsToRemove = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (OrderItem oi : itemsToRemove) {
request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, oi));
}
} else {
request.getFgisToDelete().addAll(fulfillmentGroupService.getFulfillmentGroupItemsForOrderItem(order, orderItem));
}
return request;
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class RemoveOrderMultishipOptionActivity method execute.
@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
CartOperationRequest request = context.getSeedData();
Long orderItemId = request.getItemRequest().getOrderItemId();
OrderItem orderItem = request.getOrderItem();
if (orderItem instanceof BundleOrderItem) {
for (OrderItem discrete : ((BundleOrderItem) orderItem).getDiscreteOrderItems()) {
request.getMultishipOptionsToDelete().add(new Long[] { discrete.getId(), null });
}
} else {
request.getMultishipOptionsToDelete().add(new Long[] { orderItemId, null });
}
return context;
}
use of org.broadleafcommerce.core.order.domain.BundleOrderItem 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.BundleOrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method addBundleToOrder.
@Test(groups = { "addBundleToOrder" }, dependsOnGroups = { "addAnotherItemToOrder" })
@Rollback(false)
@Transactional
public void addBundleToOrder() throws AddToCartException {
numOrderItems++;
Sku sku = skuDao.readFirstSku();
Order order = orderService.findOrderById(orderId);
assert order != null;
assert sku.getId() != null;
ProductBundle bundleItem = addProductBundle();
OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
orderItemRequestDTO.setProductId(bundleItem.getId());
orderItemRequestDTO.setSkuId(bundleItem.getDefaultSku().getId());
orderItemRequestDTO.setQuantity(1);
order = orderService.addItem(order.getId(), orderItemRequestDTO, true);
BundleOrderItem item = (BundleOrderItem) orderService.findLastMatchingItem(order, bundleItem.getDefaultSku().getId(), null);
bundleOrderItemId = item.getId();
assert item != null;
assert item.getQuantity() == 1;
assert item.getDiscreteOrderItems().size() == 1;
}
Aggregations