fgOrderItemMap.put(fgi.getOrderItem().getId(), fgi); FulfillmentGroupItem fgi = fgItemIter.next(); Long orderItemId = fgi.getOrderItem().getId(); FulfillmentGroupItem matchingFgi = fgOrderItemMap.get(orderItemId); matchingFgi.setFulfillmentGroup(collapsedFg); matchingFgi.setOrderItem(fgi.getOrderItem()); matchingFgi.setQuantity(fgi.getQuantity()); matchingFgi = fulfillmentGroupItemDao.save(matchingFgi); collapsedFg.getFulfillmentGroupItems().add(matchingFgi); fgOrderItemMap.put(orderItemId, matchingFgi); } else { matchingFgi.setQuantity(matchingFgi.getQuantity() + fgi.getQuantity());
public void delete(FulfillmentGroupItem fulfillmentGroupItem) { if (!em.contains(fulfillmentGroupItem)) { fulfillmentGroupItem = readFulfillmentGroupItemById(fulfillmentGroupItem.getId()); } em.remove(fulfillmentGroupItem); }
/** * Returns the total price for all fulfillment items. * @param order * @return */ protected void updateTaxableAmountsOnItems(Order order) { Money zero = new Money(order.getCurrency()); for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) { if (fgItem.getOrderItem().isTaxable()) { Money proratedOrderAdjAmt = fgItem.getProratedOrderAdjustmentAmount(); if (proratedOrderAdjAmt != null) { fgItem.setTotalItemTaxableAmount(fgItem.getTotalItemAmount().subtract(proratedOrderAdjAmt)); } else { fgItem.setTotalItemTaxableAmount(fgItem.getTotalItemAmount()); } } else { fgItem.setTotalItemTaxableAmount(zero); } } } }
protected FulfillmentGroupItem createFulfillmentGroupItemFromOrderItem(OrderItem orderItem, FulfillmentGroup fulfillmentGroup, int quantity) { FulfillmentGroupItem fgi = fulfillmentGroupItemDao.create(); fgi.setFulfillmentGroup(fulfillmentGroup); fgi.setOrderItem(orderItem); fgi.setQuantity(quantity); return fgi; }
public long applyDifferenceToAmount(FulfillmentGroupItem fgItem, long numApplicationsNeeded, Money unitAmount) { BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity())); Money oldAmount = fgItem.getTotalItemAmount(); Money changeToAmount = unitAmount.multiply(numTimesToApply); fgItem.setTotalItemAmount(oldAmount.add(changeToAmount)); return numTimesToApply.longValue(); }
public long applyDifferenceToProratedAdj(FulfillmentGroupItem fgItem, long numApplicationsNeeded, Money unitAmount) { BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity())); Money oldAmount = fgItem.getProratedOrderAdjustmentAmount(); Money changeToAmount = unitAmount.multiply(numTimesToApply); fgItem.setProratedOrderAdjustmentAmount(oldAmount.add(changeToAmount)); return numTimesToApply.longValue(); }
fgItemQuantityMap.put(fgi.getId(), fgi.getQuantity()); if (fgi.getOrderItem().getId().equals(orderItem.getId())) { fulfillmentGroupItem = fgi; fulfillmentGroupItem.setFulfillmentGroup(fg); fulfillmentGroupItem.setOrderItem(orderItem); fulfillmentGroupItem.setQuantity(orderItem.getQuantity()); fulfillmentGroupItem = fulfillmentGroupItemDao.save(fulfillmentGroupItem); fg.getFulfillmentGroupItems().add(fulfillmentGroupItem); if (fulfillmentGroupItem.getId() != null) { Integer qty = fgItemQuantityMap.get(fulfillmentGroupItem.getId()); if (qty == null || qty == 0) { fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1); } else { qty -= 1; fgItemQuantityMap.put(fulfillmentGroupItem.getId(), qty); fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1); if (entry.getValue() > 0) { FulfillmentGroupItem fgi = fulfillmentGroupItemDao.readFulfillmentGroupItemById(entry.getKey()); if (fgi.getQuantity() == entry.getValue()) { FulfillmentGroup fg = fgi.getFulfillmentGroup(); fg.getFulfillmentGroupItems().remove(fgi); fulfillmentGroupItemDao.delete(fgi); fgi.setQuantity(fgi.getQuantity() - entry.getValue());
protected boolean isItemTaxable(FulfillmentGroupItem item) { return item.getOrderItem().isTaxable(); }
Long oiId = fgi.getOrderItem().getId(); Integer oiQuantity = oiQuantityMap.get(oiId); throw new IllegalStateException("Fulfillment group items and discrete order items are not in sync. DiscreteOrderItem id: " + oiId); oiQuantity -= fgi.getQuantity(); oiQuantityMap.put(oiId, oiQuantity);
@Override public <G extends FulfillmentGroupItem> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this); if (createResponse.isAlreadyPopulated()) { return createResponse; } FulfillmentGroupItem cloned = createResponse.getClone(); cloned.setFulfillmentGroup(fulfillmentGroup.createOrRetrieveCopyInstance(context).getClone()); cloned.setOrderItem(orderItem.createOrRetrieveCopyInstance(context).getClone()); cloned.setProratedOrderAdjustmentAmount(proratedOrderAdjustment == null ? null : new Money(proratedOrderAdjustment)); cloned.setQuantity(quantity); if (getStatus() != null) { cloned.setStatus(getStatus()); } cloneTaxDetails(context, cloned); cloned.setTotalItemAmount(totalItemAmount == null ? null : new Money(totalItemAmount)); cloned.setTotalItemTaxableAmount(totalItemTaxableAmount == null ? null : new Money(totalItemTaxableAmount)); cloned.setTotalTax(totalTax == null ? null : new Money(totalTax)); return createResponse; }
@Override public FulfillmentGroupItem clone() { //this is likely an extended class - instantiate from the fully qualified name via reflection FulfillmentGroupItem clonedFulfillmentGroupItem; try { clonedFulfillmentGroupItem = (FulfillmentGroupItem) Class.forName(this.getClass().getName()).newInstance(); try { checkCloneable(clonedFulfillmentGroupItem); } catch (CloneNotSupportedException e) { LOG.warn("Clone implementation missing in inheritance hierarchy outside of Broadleaf: " + clonedFulfillmentGroupItem.getClass().getName(), e); } clonedFulfillmentGroupItem.setFulfillmentGroup(getFulfillmentGroup()); clonedFulfillmentGroupItem.setOrderItem(getOrderItem()); clonedFulfillmentGroupItem.setQuantity(getQuantity()); clonedFulfillmentGroupItem.setTotalItemAmount(getTotalItemAmount()); clonedFulfillmentGroupItem.setTotalItemTaxableAmount(getTotalItemTaxableAmount()); if (getStatus() != null) { clonedFulfillmentGroupItem.setStatus(getStatus()); } } catch (Exception e) { throw new RuntimeException(e); } return clonedFulfillmentGroupItem; }
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) { if (fulfillmentGroupItem.getOrderItem() instanceof DiscreteOrderItem) { DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) fulfillmentGroupItem.getOrderItem(); skuIdFulfillmentGroupMap.put(discreteOrderItem.getSku().getId(), fulfillmentGroupItem); FulfillmentGroupItem newFulfillmentGroupItem = fulfillmentGroupItem.clone(); newFulfillmentGroupItem.setOrderItem(newOrderItem); newFulfillmentGroupItem.setQuantity(newOrderItem.getQuantity()); newFulfillmentGroupItem = fulfillmentGroupItemDao.save(newFulfillmentGroupItem); if (newFulfillmentGroupItem.getFulfillmentGroup() != null && fg.getId().equals(newFulfillmentGroupItem.getFulfillmentGroup().getId())) { fg.addFulfillmentGroupItem(newFulfillmentGroupItem); FulfillmentGroupItem newFulfillmentGroupItem = fulfillmentGroupItem.clone(); newFulfillmentGroupItem.setOrderItem(discreteOrderItem); newFulfillmentGroupItem.setQuantity(discreteOrderItem.getQuantity()); if (newFulfillmentGroupItem.getFulfillmentGroup() != null && fg.getId().equals(newFulfillmentGroupItem.getFulfillmentGroup().getId())) { fg.addFulfillmentGroupItem(newFulfillmentGroupItem);
if (!done && fgItem.getOrderItem().equals(orderItem)) { fgItem.setQuantity(fgItem.getQuantity() + orderItemQuantityDelta); done = true; if (fgItem.getOrderItem().equals(orderItem)) { if (!done &&fgItem.getQuantity() == remainingToDecrement) { } else if (!done && fgItem.getQuantity() > remainingToDecrement) { fgItem.setQuantity(fgItem.getQuantity() - remainingToDecrement); done = true; } else if (!done) { remainingToDecrement = remainingToDecrement - fgItem.getQuantity(); fgisToDelete.add(fgItem);
/** * Sets the fulfillment amount which includes the relative portion of the total price for * the corresponding order item. * * @param order * @param partialOrderItemMap */ protected void populateItemTotalAmount(Order order, Map<OrderItem, List<FulfillmentGroupItem>> partialOrderItemMap) { for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) { OrderItem orderItem = fgItem.getOrderItem(); int fgItemQty = fgItem.getQuantity(); int orderItemQty = orderItem.getQuantity(); Money totalItemAmount = orderItem.getTotalPrice(); if (fgItemQty != orderItemQty) { // We need to keep track of all of these items in case we need to distribute a remainder // to one or more of the items. List<FulfillmentGroupItem> fgItemList = partialOrderItemMap.get(orderItem); if (fgItemList == null) { fgItemList = new ArrayList<>(); partialOrderItemMap.put(orderItem, fgItemList); } fgItemList.add(fgItem); fgItem.setTotalItemAmount(totalItemAmount.multiply(fgItemQty).divide(orderItemQty)); } else { fgItem.setTotalItemAmount(totalItemAmount); } } } }
@Override public FulfillmentGroup answer() throws Throwable { FulfillmentGroupItemRequest fgItemRequest = (FulfillmentGroupItemRequest) EasyMock.getCurrentArguments()[0]; FulfillmentGroup fg = fgItemRequest.getFulfillmentGroup(); FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl(); fgItem.setOrderItem(fgItemRequest.getOrderItem()); fgItem.setQuantity(fgItemRequest.getQuantity()); fg.getFulfillmentGroupItems().add(fgItem); return fg; } };
if (fulfillmentGroupItem.getOrderItem() instanceof DiscreteOrderItem) { sku = ((DiscreteOrderItem)fulfillmentGroupItem.getOrderItem()).getSku(); } else if (fulfillmentGroupItem.getOrderItem() instanceof BundleOrderItem) { sku = ((BundleOrderItem)fulfillmentGroupItem.getOrderItem()).getSku(); BigDecimal price = (fulfillmentGroupItem.getTotalItemAmount() != null) ? fulfillmentGroupItem.getTotalItemAmount().getAmount() : null; if (price == null) { price = fulfillmentGroupItem.getOrderItem().getAveragePrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity())); BigDecimal convertedWeight = convertWeight(sku.getWeight().getWeight(), sku.getWeight().getWeightUnitOfMeasure()).multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity())); weightTotal = weightTotal.add(convertedWeight);
BigDecimal price = (fulfillmentGroupItem.getRetailPrice() != null) ? fulfillmentGroupItem.getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity())) : null; if (price == null) { price = fulfillmentGroupItem.getOrderItem().getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity()));
public long applyTaxDifference(FulfillmentGroupItem fgItem, long numApplicationsNeeded, Money unitAmount) { BigDecimal numTimesToApply = new BigDecimal(Math.min(numApplicationsNeeded, fgItem.getQuantity())); Money oldAmount = fgItem.getTotalItemTaxableAmount(); Money changeToAmount = unitAmount.multiply(numTimesToApply); fgItem.setTotalItemTaxableAmount(oldAmount.add(changeToAmount)); return numTimesToApply.longValue(); }
public void testDistributeOneDollarAcrossFiveEqualItems() throws Exception { Order order = dataProvider.createBasicOrder(); Money subTotal = new Money(order.getCurrency()); for (OrderItem orderItem : order.getOrderItems()) { orderItem.setSalePrice(new Money(10D)); orderItem.getOrderItemPriceDetails().clear(); subTotal = subTotal.add(orderItem.getTotalPrice()); } OrderAdjustment adjustment = new OrderAdjustmentImpl(); adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency())); order.getOrderAdjustments().add(adjustment); adjustment.setOrder(order); order.setSubTotal(subTotal); ProcessContext<Order> context = new DefaultProcessContextImpl<Order>(); context.setSeedData(order); fulfillmentItemPricingActivity.execute(context); // Each item is equally priced, so the adjustment should be .20 per item. Money proratedAdjustment = new Money(".20"); for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) { for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) { assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().compareTo( proratedAdjustment.multiply(fulfillmentGroupItem.getQuantity())) == 0); } } }
cloned.setType(getType()); for (FulfillmentGroupItem fgi: fulfillmentGroupItems) { FulfillmentGroupItem fulfillmentGroupItem = fgi.createOrRetrieveCopyInstance(context).getClone(); fulfillmentGroupItem.setFulfillmentGroup(cloned); cloned.getFulfillmentGroupItems().add(fulfillmentGroupItem);