Search in sources :

Example 6 with BandedPriceFulfillmentOption

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

the class BandedPriceFulfillmentTest method testLowestPriceSelection.

/**
 * If the retail price sum falls within 2 bands but with the same retail minimum, the lowest price should be selected
 */
public void testLowestPriceSelection() throws Exception {
    BandedPriceFulfillmentOption option = createPriceBands(new String[] { "10", "10", "10" }, new String[] { "30", "20", "10" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE });
    assertEquals(calculationResponse(option, createCandidateOrder(new BigDecimal("10.00"), 2, option)), new Money("10.00"));
}
Also used : Money(org.broadleafcommerce.common.money.Money) BandedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption) BigDecimal(java.math.BigDecimal)

Example 7 with BandedPriceFulfillmentOption

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

the class BandedPriceFulfillmentTest method testMinimumAmountsWithZero.

public void testMinimumAmountsWithZero() throws Exception {
    BandedPriceFulfillmentOption option = createPriceBands(new String[] { "0", "20", "30" }, new String[] { "10", "20", "30" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE });
    assertEquals(new Money("20.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("20.00"), 2, option)));
    assertEquals(new Money("10.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("9.00"), 3, option)));
    assertEquals(new Money("30.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("30.00"), 3, option)));
    assertEquals(new Money("20.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("25.00"), 5, option)));
    assertEquals(new Money("30.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("100.00"), 5, option)));
}
Also used : Money(org.broadleafcommerce.common.money.Money) BandedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption) BigDecimal(java.math.BigDecimal)

Example 8 with BandedPriceFulfillmentOption

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

the class BandedPriceFulfillmentTest method testFlatRatesWithBands.

public void testFlatRatesWithBands() throws Exception {
    BandedPriceFulfillmentOption option = createPriceBands(new String[] { "30", "20", "10" }, new String[] { "30", "20", "10" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE, FulfillmentBandResultAmountType.RATE });
    assertEquals(new Money("35"), calculationResponse(option, createCandidateOrder(new BigDecimal("18.00"), 6, new String[] { "10", "15" }, null, option)));
    assertEquals(new Money("125"), calculationResponse(option, createCandidateOrder(new BigDecimal("18.00"), 6, new String[] { "5", "100", "20" }, null, option)));
    assertEquals(new Money("41"), calculationResponse(option, createCandidateOrder(new BigDecimal("60.00"), 6, new String[] { "8", "2", "1" }, null, option)));
}
Also used : Money(org.broadleafcommerce.common.money.Money) BandedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption) BigDecimal(java.math.BigDecimal)

Example 9 with BandedPriceFulfillmentOption

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

the class BandedPriceFulfillmentTest method testPriceBandPercentage.

public void testPriceBandPercentage() throws Exception {
    BandedPriceFulfillmentOption option = createPriceBands(new String[] { "10", "30", "20" }, new String[] { ".10", ".20", ".30" }, new FulfillmentBandResultAmountType[] { FulfillmentBandResultAmountType.PERCENTAGE, FulfillmentBandResultAmountType.PERCENTAGE, FulfillmentBandResultAmountType.PERCENTAGE });
    assertEquals(new Money("1.50"), calculationResponse(option, createCandidateOrder(new BigDecimal("15.00"), 3, option)));
    assertEquals(new Money("6.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("30.00"), 3, option)));
    assertEquals(new Money("7.50"), calculationResponse(option, createCandidateOrder(new BigDecimal("25.00"), 5, option)));
    assertEquals(new Money("20.00"), calculationResponse(option, createCandidateOrder(new BigDecimal("100.00"), 5, option)));
}
Also used : Money(org.broadleafcommerce.common.money.Money) BandedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption) BigDecimal(java.math.BigDecimal)

Example 10 with BandedPriceFulfillmentOption

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

the class BandedPriceFulfillmentTest method createCandidateOrder.

/**
 * @param total - this number divided by the number of items to create is the value of either the weight or the price
 * (depending on which <b>option</b> is being passed in) for a single order item. Note that the final price of each item
 * will be: (<b>total</b> / <b>orderItemsToCreate</b>) * <b>quantity</b>
 * @param orderItemsToCreate - the number of order items to split the retail total across
 * @param flatRates - the flat rates to assign to the OrderItems that are created. To have an Order that is mixed between OrderItems and
 * DiscreteOrderItems (which are created for flat rates) ensure that the size of this array is less than <b>orderItemsToCreate</b>
 * @param quantities - the quantities to assign to each OrderItem. If specified, this should be equal to the number of
 * items to create
 * @param option - the option to associate with the flat rates
 * @return
 */
protected Order createCandidateOrder(BigDecimal total, int orderItemsToCreate, String[] flatRates, int[] quantities, FulfillmentOption option) {
    if (flatRates != null && flatRates.length > orderItemsToCreate) {
        throw new IllegalStateException("Flat rates for Skus should be less than or equal to the number of order items being created");
    }
    if (quantities != null && quantities.length != orderItemsToCreate) {
        throw new IllegalStateException("Quantities for Skus should be less than or equal to the number of order items being created");
    }
    Order result = new OrderImpl();
    List<FulfillmentGroupItem> fulfillmentItems = new ArrayList<FulfillmentGroupItem>();
    for (int i = 0; i < orderItemsToCreate; i++) {
        DiscreteOrderItem orderItem = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        // set the sku price to some arbitrary amount - won't matter because the test is based on order item price
        sku.setRetailPrice(new Money("1"));
        orderItem.setSku(sku);
        if (flatRates != null && i < flatRates.length) {
            sku.getFulfillmentFlatRates().put(option, new BigDecimal(flatRates[i]));
        }
        if (option instanceof BandedPriceFulfillmentOption) {
            orderItem.setPrice(new Money(total.divide(new BigDecimal(orderItemsToCreate))));
        } else if (option instanceof BandedWeightFulfillmentOption) {
            Weight weight = new Weight();
            weight.setWeight(total.divide(new BigDecimal(orderItemsToCreate)));
            weight.setWeightUnitOfMeasure(WeightUnitOfMeasureType.POUNDS);
            orderItem.getSku().setWeight(weight);
            orderItem.setPrice(new Money(BigDecimal.ZERO));
        }
        orderItem.setOrder(result);
        FulfillmentGroupItem fulfillmentItem = new FulfillmentGroupItemImpl();
        fulfillmentItem.setOrderItem(orderItem);
        if (quantities == null) {
            fulfillmentItem.setQuantity(1);
        } else {
            fulfillmentItem.setQuantity(quantities[i]);
        }
        fulfillmentItems.add(fulfillmentItem);
    }
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setOrder(result);
    group.setFulfillmentGroupItems(fulfillmentItems);
    List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
    groups.add(group);
    result.setFulfillmentGroups(groups);
    return result;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) ArrayList(java.util.ArrayList) BandedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption) BigDecimal(java.math.BigDecimal) Weight(org.broadleafcommerce.core.catalog.domain.Weight) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Sku(org.broadleafcommerce.core.catalog.domain.Sku) BandedWeightFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.BandedWeightFulfillmentOption) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Aggregations

BigDecimal (java.math.BigDecimal)10 BandedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.BandedPriceFulfillmentOption)10 Money (org.broadleafcommerce.common.money.Money)9 ArrayList (java.util.ArrayList)2 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)2 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)2 BandedWeightFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.BandedWeightFulfillmentOption)2 FulfillmentPriceBand (org.broadleafcommerce.core.order.fulfillment.domain.FulfillmentPriceBand)2 HashMap (java.util.HashMap)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1 Weight (org.broadleafcommerce.core.catalog.domain.Weight)1 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)1 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)1 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)1 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)1 Order (org.broadleafcommerce.core.order.domain.Order)1 OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)1