|
36 | 36 | import org.broadleafcommerce.core.order.service.type.FulfillmentType;
|
37 | 37 | import org.broadleafcommerce.core.order.service.workflow.CartOperationRequest;
|
38 | 38 | import org.broadleafcommerce.core.pricing.service.exception.PricingException;
|
| 39 | +import org.springframework.beans.factory.annotation.Value; |
39 | 40 | import org.springframework.stereotype.Service;
|
40 | 41 |
|
41 | 42 | import java.util.ArrayList;
|
@@ -68,7 +69,10 @@ public class FulfillmentGroupItemStrategyImpl implements FulfillmentGroupItemStr
|
68 | 69 | protected FulfillmentGroupItemDao fgItemDao;
|
69 | 70 |
|
70 | 71 | protected boolean removeEmptyFulfillmentGroups = true;
|
71 |
| - |
| 72 | + |
| 73 | + @Value("${sync.fulfillmentGroupItem.qty:false}") |
| 74 | + private boolean syncFGItemQty; |
| 75 | + |
72 | 76 | @Override
|
73 | 77 | public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
|
74 | 78 | Order order = request.getOrder();
|
@@ -369,19 +373,23 @@ public CartOperationRequest verify(CartOperationRequest request) throws PricingE
|
369 | 373 |
|
370 | 374 | for (Entry<Long, Integer> entry : oiQuantityMap.entrySet()) {
|
371 | 375 | 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 | + } |
384 | 390 | }
|
| 391 | + } else { |
| 392 | + throw new IllegalStateException("Not enough fulfillment group items found for DiscreteOrderItem id: " + entry.getKey()); |
385 | 393 | }
|
386 | 394 | }
|
387 | 395 | }
|
|
0 commit comments