Search in sources :

Example 6 with FulfillmentGroup

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

the class LegacyOrderServiceImpl method removeAllFulfillmentGroupsFromOrder.

@Override
public void removeAllFulfillmentGroupsFromOrder(Order order, boolean priceOrder) throws PricingException {
    if (order.getFulfillmentGroups() != null) {
        for (Iterator<FulfillmentGroup> iterator = order.getFulfillmentGroups().iterator(); iterator.hasNext(); ) {
            FulfillmentGroup fulfillmentGroup = iterator.next();
            iterator.remove();
            fulfillmentGroupDao.delete(fulfillmentGroup);
        }
        updateOrder(order, priceOrder);
    }
}
Also used : FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 7 with FulfillmentGroup

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

the class FulfillmentGroupItemStrategyImpl method onItemAdded.

@Override
public CartOperationRequest onItemAdded(CartOperationRequest request) throws PricingException {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    Map<FulfillmentType, FulfillmentGroup> fulfillmentGroups = new HashMap<FulfillmentType, FulfillmentGroup>();
    FulfillmentGroup nullFulfillmentTypeGroup = null;
    // We'll use the first of each type that we find. Implementors can choose to move groups / items around later.
    if (order.getFulfillmentGroups() != null) {
        for (FulfillmentGroup group : order.getFulfillmentGroups()) {
            if (group.getType() == null) {
                if (nullFulfillmentTypeGroup == null) {
                    nullFulfillmentTypeGroup = group;
                }
            } else {
                if (fulfillmentGroups.get(group.getType()) == null) {
                    fulfillmentGroups.put(group.getType(), group);
                }
            }
        }
    }
    if (orderItem instanceof BundleOrderItem) {
        // We only care about the discrete order items
        List<DiscreteOrderItem> itemsToAdd = new ArrayList<DiscreteOrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
        for (DiscreteOrderItem doi : itemsToAdd) {
            FulfillmentGroup fulfillmentGroup = null;
            FulfillmentType type = resolveFulfillmentType(doi);
            if (type == null) {
                // Use the fulfillment group with a null type
                fulfillmentGroup = nullFulfillmentTypeGroup;
            } else {
                if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                    // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                    // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                    type = FulfillmentType.PHYSICAL_SHIP;
                }
                // Use the fulfillment group with the specified type
                fulfillmentGroup = fulfillmentGroups.get(type);
            }
            // If the null type or specified type, above were null, then we need to create a new fulfillment group
            boolean createdFulfillmentGroup = false;
            if (fulfillmentGroup == null) {
                fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
                // Set the type
                fulfillmentGroup.setType(type);
                fulfillmentGroup.setOrder(order);
                order.getFulfillmentGroups().add(fulfillmentGroup);
                createdFulfillmentGroup = true;
            }
            fulfillmentGroup = addItemToFulfillmentGroup(order, doi, doi.getQuantity() * orderItem.getQuantity(), fulfillmentGroup);
            order = fulfillmentGroup.getOrder();
            // of fulfillment groups
            if (createdFulfillmentGroup) {
                if (type == null) {
                    nullFulfillmentTypeGroup = fulfillmentGroup;
                } else {
                    fulfillmentGroups.put(type, fulfillmentGroup);
                }
            }
        }
    } else if (orderItem instanceof DiscreteOrderItem) {
        DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
        FulfillmentGroup fulfillmentGroup = null;
        FulfillmentType type = resolveFulfillmentType(doi);
        if (type == null) {
            // Use the fulfillment group with a null type
            fulfillmentGroup = nullFulfillmentTypeGroup;
        } else {
            if (FulfillmentType.PHYSICAL_PICKUP_OR_SHIP.equals(type)) {
                // This is really a special case. "PICKUP_OR_SHIP" is convenient to allow a sku to be picked up or shipped.
                // However, it is ambiguous when actually trying to create a fulfillment group. So we default to "PHYSICAL_SHIP".
                type = FulfillmentType.PHYSICAL_SHIP;
            }
            // Use the fulfillment group with the specified type
            fulfillmentGroup = fulfillmentGroups.get(type);
        }
        // If the null type or specified type, above were null, then we need to create a new fulfillment group
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            // Set the type
            fulfillmentGroup.setType(type);
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
        order = fulfillmentGroup.getOrder();
    } else {
        FulfillmentGroup fulfillmentGroup = nullFulfillmentTypeGroup;
        if (fulfillmentGroup == null) {
            fulfillmentGroup = fulfillmentGroupService.createEmptyFulfillmentGroup();
            fulfillmentGroup.setOrder(order);
            order.getFulfillmentGroups().add(fulfillmentGroup);
        }
        fulfillmentGroup = addItemToFulfillmentGroup(order, orderItem, fulfillmentGroup);
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) HashMap(java.util.HashMap) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentType(org.broadleafcommerce.core.order.service.type.FulfillmentType)

Example 8 with FulfillmentGroup

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

the class PaymentResponseDTOToEntityServiceImpl method populateShippingInfo.

@Override
public void populateShippingInfo(PaymentResponseDTO responseDTO, Order order) {
    FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(order);
    if (responseDTO.getShipTo() != null && responseDTO.getShipTo().addressPopulated() && shippableFulfillmentGroup != null) {
        Address shippingAddress = addressService.create();
        AddressDTO<PaymentResponseDTO> shipToDTO = responseDTO.getShipTo();
        populateAddressInfo(shipToDTO, shippingAddress);
        shippableFulfillmentGroup = fulfillmentGroupService.findFulfillmentGroupById(shippableFulfillmentGroup.getId());
        if (shippableFulfillmentGroup != null) {
            shippableFulfillmentGroup.setAddress(shippingAddress);
            fulfillmentGroupService.save(shippableFulfillmentGroup);
        }
    }
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Example 9 with FulfillmentGroup

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

the class AddWorkflowPriceOrderIfNecessaryActivity method getOiFgiMap.

protected void getOiFgiMap(Order order, Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap, OrderItem oi) {
    List<FulfillmentGroupItem> fgis = new ArrayList<>();
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            if (fgi.getOrderItem().equals(oi)) {
                fgis.add(fgi);
            }
        }
    }
    oiFgiMap.put(oi, fgis);
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 10 with FulfillmentGroup

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

the class OfferTest method createFulfillmentGroups.

private List<FulfillmentGroup> createFulfillmentGroups(FulfillmentOption option, Double shippingPrice, Order order) {
    List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setFulfillmentOption(option);
    groups.add(group);
    group.setRetailShippingPrice(new Money(shippingPrice));
    group.setOrder(order);
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    countryService.save(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    isoService.save(isoCountry);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setName("Texas");
    state.setCountry(country);
    stateService.save(state);
    address.setState(state);
    address.setCountry(country);
    address.setIsoCountrySubdivision("US-TX");
    address.setIsoCountryAlpha2(isoCountry);
    for (OrderItem orderItem : order.getOrderItems()) {
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(orderItem);
        fgItem.setQuantity(orderItem.getQuantity());
        group.addFulfillmentGroupItem(fgItem);
    }
    group.setAddress(address);
    return groups;
}
Also used : FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) ArrayList(java.util.ArrayList) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) Money(org.broadleafcommerce.common.money.Money) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

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