Skip to content

Commit 45f826f

Browse files
committed
BroadleafCommerce/QA#1663 - Add property value to enable the sync
1 parent 447ad30 commit 45f826f

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

core/broadleaf-framework/src/main/java/org/broadleafcommerce/core/order/strategy/FulfillmentGroupItemStrategyImpl.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.broadleafcommerce.core.order.service.type.FulfillmentType;
3737
import org.broadleafcommerce.core.order.service.workflow.CartOperationRequest;
3838
import org.broadleafcommerce.core.pricing.service.exception.PricingException;
39+
import org.springframework.beans.factory.annotation.Value;
3940
import org.springframework.stereotype.Service;
4041

4142
import java.util.ArrayList;
@@ -68,7 +69,10 @@ public class FulfillmentGroupItemStrategyImpl implements FulfillmentGroupItemStr
6869
protected FulfillmentGroupItemDao fgItemDao;
6970

7071
protected boolean removeEmptyFulfillmentGroups = true;
71-
72+
73+
@Value("${sync.fulfillmentGroupItem.qty:false}")
74+
private boolean syncFGItemQty;
75+
7276
@Override
7377
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
7478
Order order = request.getOrder();
@@ -369,19 +373,23 @@ public CartOperationRequest verify(CartOperationRequest request) throws PricingE
369373

370374
for (Entry<Long, Integer> entry : oiQuantityMap.entrySet()) {
371375
if (!entry.getValue().equals(0)) {
372-
LOG.warn("Not enough fulfillment group items found for DiscreteOrderItem id:" + entry.getKey());
373-
// There are edge cases where the OrderItem and FulfillmentGroupItem quantities can fall out of sync. If this happens
374-
// we set the FGItem to the correct quantity from the OrderItem and save/reprice the order to synchronize them.
375-
FulfillmentGroupItem fgItem = fgItemMap.get(entry.getKey());
376-
for (OrderItem oi : expandedOrderItems) {
377-
if (oi.getId().equals(fgItem.getOrderItem().getId())) {
378-
LOG.warn("Synchronizing FulfillmentGroupItem to match OrderItem ["
379-
+ entry.getKey() + "] quantity of : " + oi.getQuantity());
380-
fgItem.setQuantity(oi.getQuantity());
381-
// We price the order in order to get the right amount after the qty change
382-
order = orderService.save(order, true);
383-
request.setOrder(order);
376+
if (syncFGItemQty) {
377+
LOG.warn("Not enough fulfillment group items found for DiscreteOrderItem id:" + entry.getKey());
378+
// There are edge cases where the OrderItem and FulfillmentGroupItem quantities can fall out of sync. If this happens
379+
// we set the FGItem to the correct quantity from the OrderItem and save/reprice the order to synchronize them.
380+
FulfillmentGroupItem fgItem = fgItemMap.get(entry.getKey());
381+
for (OrderItem oi : expandedOrderItems) {
382+
if (oi.getId().equals(fgItem.getOrderItem().getId())) {
383+
LOG.warn("Synchronizing FulfillmentGroupItem to match OrderItem ["
384+
+ entry.getKey() + "] quantity of : " + oi.getQuantity());
385+
fgItem.setQuantity(oi.getQuantity());
386+
// We price the order in order to get the right amount after the qty change
387+
order = orderService.save(order, true);
388+
request.setOrder(order);
389+
}
384390
}
391+
} else {
392+
throw new IllegalStateException("Not enough fulfillment group items found for DiscreteOrderItem id: " + entry.getKey());
385393
}
386394
}
387395
}

core/broadleaf-framework/src/main/resources/config/bc/fw/common.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ catalogUriService.appendIdToRelativeURI=true
9191
# the last fragment of the URL instead of parsing the results of the product or category "getURL()" method
9292
catalogUriService.useUrlKey=false
9393

94-
94+
# There are edge cases where the OrderItem and FulfillmentGroupItem quantities can fall out of sync. If this happens,
95+
# by setting the sync.fulfillmentGroupItem.qty flag to true, the system will correct the fulfillmentGroup quantity
96+
# from the OrderItem and save/reprice the order to synchronize them.
97+
sync.fulfillmentGroupItem.qty=false

0 commit comments

Comments
 (0)