Search in sources :

Example 46 with FulfillmentGroup

use of org.broadleafcommerce.core.order.domain.FulfillmentGroup 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)

Example 47 with FulfillmentGroup

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

the class FixedPriceFulfillmentTest method testNullFulfillmentOptionInEstimation.

public void testNullFulfillmentOptionInEstimation() throws Exception {
    Set<FulfillmentOption> options = new HashSet<FulfillmentOption>();
    FixedPriceFulfillmentOption option1 = new FixedPriceFulfillmentOptionImpl();
    option1.setPrice(new Money(BigDecimal.ONE));
    FixedPriceFulfillmentOption option2 = new FixedPriceFulfillmentOptionImpl();
    option2.setPrice(new Money(BigDecimal.TEN));
    options.add(option1);
    options.add(option2);
    FixedPriceFulfillmentPricingProvider provider = new FixedPriceFulfillmentPricingProvider();
    FulfillmentGroup fg = new FulfillmentGroupImpl();
    FulfillmentEstimationResponse response = provider.estimateCostForFulfillmentGroup(fg, options);
    for (Entry<? extends FulfillmentOption, Money> entry : response.getFulfillmentOptionPrices().entrySet()) {
        assertEquals(((FixedPriceFulfillmentOption) entry.getKey()).getPrice(), entry.getValue());
    }
}
Also used : FixedPriceFulfillmentPricingProvider(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FixedPriceFulfillmentPricingProvider) Money(org.broadleafcommerce.common.money.Money) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) HashSet(java.util.HashSet)

Example 48 with FulfillmentGroup

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

the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveItems.

public void testDistributeOneDollarAcrossFiveItems() throws Exception {
    Order order = dataProvider.createBasicOrder();
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
    adjustment.setOrder(order);
    order.getOrderAdjustments().add(adjustment);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    Money adj1 = new Money(".31");
    Money adj2 = new Money(".69");
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            if (fulfillmentGroupItem.getSalePrice().equals(new Money("19.99"))) {
                assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().equals(adj1));
            } else {
                assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().equals(adj2));
            }
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) Money(org.broadleafcommerce.common.money.Money) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) BigDecimal(java.math.BigDecimal)

Example 49 with FulfillmentGroup

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

the class FulfillmentVariableExpression method getFulfillmentEstimateResponse.

public FulfillmentEstimationResponse getFulfillmentEstimateResponse() {
    Order cart = CartState.getCart();
    if (!isNullOrder(cart) && cart.getFulfillmentGroups().size() > 0 && cartStateService.cartHasPopulatedShippingAddress()) {
        try {
            List<FulfillmentOption> fulfillmentOptions = fulfillmentOptionService.readAllFulfillmentOptions();
            FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
            return fulfillmentPricingService.estimateCostForFulfillmentGroup(firstShippableFulfillmentGroup, new HashSet<>(fulfillmentOptions));
        } catch (FulfillmentPriceException e) {
        // do nothing
        }
    }
    return null;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) FulfillmentPriceException(org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption)

Example 50 with FulfillmentGroup

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

the class BroadleafShippingInfoController method saveSingleShip.

/**
 * Processes the request to save a single shipping address.  Allows modules to add module specific shipping logic.
 *
 * Note:  the default Broadleaf implementation creates an order
 * with a single fulfillment group. In the case of shipping to multiple addresses,
 * the multiship methods should be used.
 *
 * @param request
 * @param response
 * @param model
 * @param shippingForm
 * @return the return path
 * @throws org.broadleafcommerce.common.exception.ServiceException
 */
public String saveSingleShip(HttpServletRequest request, HttpServletResponse response, Model model, ShippingInfoForm shippingForm, BindingResult result) throws PricingException, ServiceException {
    Order cart = CartState.getCart();
    if (shippingForm.shouldUseBillingAddress()) {
        copyBillingAddressToShippingAddress(cart, shippingForm);
    }
    addressService.populateAddressISOCountrySub(shippingForm.getAddress());
    shippingInfoFormValidator.validate(shippingForm, result);
    if (result.hasErrors()) {
        return getCheckoutView();
    }
    if ((shippingForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
        shippingForm.getAddress().setPhonePrimary(null);
    }
    if ((shippingForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
        shippingForm.getAddress().setPhoneSecondary(null);
    }
    if ((shippingForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(shippingForm.getAddress().getPhoneFax().getPhoneNumber()))) {
        shippingForm.getAddress().setPhoneFax(null);
    }
    Customer customer = CustomerState.getCustomer();
    if (!customer.isAnonymous() && shippingForm.isSaveAsDefault()) {
        Address address = addressService.saveAddress(shippingForm.getAddress());
        CustomerAddress customerAddress = customerAddressService.create();
        customerAddress.setAddress(address);
        customerAddress.setAddressName(shippingForm.getAddressName());
        customerAddress.setCustomer(customer);
        customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
        customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customer.getId());
    }
    FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
    if (shippableFulfillmentGroup != null) {
        shippableFulfillmentGroup.setAddress(shippingForm.getAddress());
        shippableFulfillmentGroup.setPersonalMessage(shippingForm.getPersonalMessage());
        shippableFulfillmentGroup.setDeliveryInstruction(shippingForm.getDeliveryMessage());
        FulfillmentOption fulfillmentOption = fulfillmentOptionService.readFulfillmentOptionById(shippingForm.getFulfillmentOptionId());
        shippableFulfillmentGroup.setFulfillmentOption(fulfillmentOption);
        cart = orderService.save(cart, true);
    }
    // Add module specific logic
    checkoutControllerExtensionManager.getProxy().performAdditionalShippingAction();
    if (isAjaxRequest(request)) {
        // Add module specific model variables
        checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
        return getCheckoutView();
    } else {
        return getCheckoutPageRedirect();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Customer(org.broadleafcommerce.profile.core.domain.Customer) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

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