Search in sources :

Example 66 with FulfillmentGroup

use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivity method fixOrderSavingsRoundingIssues.

/**
 * It is possible due to rounding that the order adjustments do not match the
 * total.   This method fixes by adding or removing the pennies.
 * @param order
 * @param partialOrderItemMap
 */
protected void fixOrderSavingsRoundingIssues(Order order, Money totalOrderAdjustmentDistributed) {
    if (!order.getHasOrderAdjustments()) {
        return;
    }
    Money orderAdjustmentTotal = order.getOrderAdjustmentsValue();
    Money amountDiff = orderAdjustmentTotal.subtract(totalOrderAdjustmentDistributed);
    if (!(amountDiff.getAmount().compareTo(BigDecimal.ZERO) == 0)) {
        long numApplicationsNeeded = countNumberOfUnits(amountDiff);
        Money unitAmount = getUnitAmount(amountDiff);
        for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
            for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) {
                numApplicationsNeeded = numApplicationsNeeded - applyDifferenceToProratedAdj(fgItem, numApplicationsNeeded, unitAmount);
                if (numApplicationsNeeded == 0) {
                    break;
                }
            }
        }
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 67 with FulfillmentGroup

use of org.broadleafcommerce.core.order.domain.FulfillmentGroup in project BroadleafCommerce by BroadleafCommerce.

the class TotalActivity method execute.

@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;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentGroupFee(org.broadleafcommerce.core.order.domain.FulfillmentGroupFee)

Aggregations

FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)67 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)39 Order (org.broadleafcommerce.core.order.domain.Order)32 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)24 Money (org.broadleafcommerce.common.money.Money)22 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)19 Transactional (org.springframework.transaction.annotation.Transactional)17 ArrayList (java.util.ArrayList)16 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)15 Address (org.broadleafcommerce.profile.core.domain.Address)15 Test (org.testng.annotations.Test)12 Sku (org.broadleafcommerce.core.catalog.domain.Sku)9 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)9 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)8 Customer (org.broadleafcommerce.profile.core.domain.Customer)8 HashMap (java.util.HashMap)7 BigDecimal (java.math.BigDecimal)6 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)6 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)6 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)5