*/
public class TotalActivity extends BaseActivity<ProcessContext<Order>> {
@Override
public ProcessContext<Order> execute(ProcessContext<Order> context) throws Exception {
Order order = context.getSeedData();
setTaxSums(order);
Money total = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
total = total.add(order.getSubTotal());
total = total.subtract(order.getOrderAdjustmentsValue());
total = total.add(order.getTotalShipping());
// There may not be any taxes on the order
if (order.getTotalTax() != null) {
total = total.add(order.getTotalTax());
}
Money fees = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
Money fgTotal = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, order.getCurrency());
fgTotal = fgTotal.add(fulfillmentGroup.getMerchandiseTotal());
fgTotal = fgTotal.add(fulfillmentGroup.getShippingPrice());
fgTotal = fgTotal.add(fulfillmentGroup.getTotalTax());
for (FulfillmentGroupFee fulfillmentGroupFee : fulfillmentGroup.getFulfillmentGroupFees()) {
fgTotal = fgTotal.add(fulfillmentGroupFee.getAmount());
fees = fees.add(fulfillmentGroupFee.getAmount());
}
fulfillmentGroup.setTotal(fgTotal);
}
total = total.add(fees);
order.setTotal(total);
context.setSeedData(order);
return context;
}