Skip to content

Commit 5927ff7

Browse files
Needed to add the new order item to the childOrderItem list of the parent order item. Fixes BroadleafCommerce/QA#1184
1 parent b1e8cfe commit 5927ff7

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

core/broadleaf-framework/src/main/java/org/broadleafcommerce/core/order/service/workflow/PriceOrderIfNecessaryActivity.java

+50-5
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperation
171171
}
172172

173173
// We need to add the new item to the parent's child order items as well.
174-
for (OrderItem oi : order.getOrderItems()) {
175-
if (oi.getId().equals(request.getItemRequest().getParentOrderItemId())) {
176-
oi.getChildOrderItems().add(request.getOrderItem());
177-
}
178-
}
174+
updateChildOrderItem(request, order);
179175

180176
// If a custom implementation needs to handle additional saves before the parent Order is saved, this method
181177
// can be overridden to provide that functionality.
@@ -189,6 +185,55 @@ public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperation
189185
return context;
190186
}
191187

188+
/**
189+
* Traverses the current OrderItem for a match to the parentOrderItemId.
190+
* If found, populates and returns true.
191+
*
192+
* @param request
193+
* @param orderItem
194+
* @return
195+
*/
196+
protected void updateChildOrderItem(CartOperationRequest request, Order order) {
197+
boolean updated = false;
198+
for (OrderItem oi : order.getOrderItems()) {
199+
if (oi instanceof BundleOrderItem) {
200+
BundleOrderItem boi = (BundleOrderItem) oi;
201+
updated = checkAndUpdateChildren(request, boi); //check the bundle children
202+
if (!updated) {
203+
for (OrderItem discreteOrderItem : boi.getDiscreteOrderItems()) { //check the bundle discrete items
204+
if (checkAndUpdateChildren(request, discreteOrderItem)) {
205+
updated = true;
206+
break; //break out of the discrete items loop
207+
}
208+
}
209+
}
210+
} else {
211+
updated = checkAndUpdateChildren(request, oi);
212+
}
213+
if (updated) {
214+
break;
215+
}
216+
}
217+
}
218+
219+
protected boolean checkAndUpdateChildren(CartOperationRequest request, OrderItem orderItem) {
220+
boolean parentUpdated = false;
221+
if (orderItem.getId().equals(request.getItemRequest().getParentOrderItemId())) {
222+
orderItem.getChildOrderItems().add(request.getOrderItem());
223+
parentUpdated = true;
224+
} else {
225+
if (CollectionUtils.isNotEmpty(orderItem.getChildOrderItems())) {
226+
for (OrderItem childOrderItem : orderItem.getChildOrderItems()) {
227+
parentUpdated = checkAndUpdateChildren(request, childOrderItem);
228+
if (parentUpdated) {
229+
break;
230+
}
231+
}
232+
}
233+
}
234+
return parentUpdated;
235+
}
236+
192237
protected void getOiFgiMap(Order order, Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap, OrderItem oi) {
193238
List<FulfillmentGroupItem> fgis = new ArrayList<FulfillmentGroupItem>();
194239

0 commit comments

Comments
 (0)