Search in sources :

Example 51 with FulfillmentGroup

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

the class CheckoutFormServiceImpl method prePopulateShippingInfoForm.

@Override
public ShippingInfoForm prePopulateShippingInfoForm(ShippingInfoForm shippingInfoForm, Order cart) {
    FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
    if (firstShippableFulfillmentGroup != null) {
        // if the cart has already has fulfillment information
        if (firstShippableFulfillmentGroup.getAddress() != null) {
            shippingInfoForm.setAddress(firstShippableFulfillmentGroup.getAddress());
        } else {
            // check for a default address for the customer
            CustomerAddress defaultAddress = customerAddressService.findDefaultCustomerAddress(CustomerState.getCustomer().getId());
            if (defaultAddress != null) {
                shippingInfoForm.setAddress(defaultAddress.getAddress());
                shippingInfoForm.setAddressName(defaultAddress.getAddressName());
            }
        }
        FulfillmentOption fulfillmentOption = firstShippableFulfillmentGroup.getFulfillmentOption();
        if (fulfillmentOption != null) {
            shippingInfoForm.setFulfillmentOption(fulfillmentOption);
            shippingInfoForm.setFulfillmentOptionId(fulfillmentOption.getId());
        }
    }
    return shippingInfoForm;
}
Also used : FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 52 with FulfillmentGroup

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

the class FulfillmentGroupServiceImpl method addItemToFulfillmentGroup.

@Override
public // @Transactional("blTransactionManager")
FulfillmentGroup addItemToFulfillmentGroup(FulfillmentGroupItemRequest fulfillmentGroupItemRequest, boolean priceOrder, boolean save) throws PricingException {
    if (priceOrder && !save) {
        throw new IllegalArgumentException("Pricing requires a save");
    }
    Order order = fulfillmentGroupItemRequest.getOrder();
    OrderItem item = fulfillmentGroupItemRequest.getOrderItem();
    FulfillmentGroup fulfillmentGroup = fulfillmentGroupItemRequest.getFulfillmentGroup();
    if (order == null) {
        if (item.getOrder() != null) {
            order = item.getOrder();
        } else {
            throw new IllegalArgumentException("Order must not be null");
        }
    }
    // 1) Find the order item's existing fulfillment group, if any
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
        while (itr.hasNext()) {
            FulfillmentGroupItem fgItem = itr.next();
            if (fgItem.getOrderItem().equals(item)) {
                // 2) remove item from it's existing fulfillment group
                itr.remove();
                fulfillmentGroupItemDao.delete(fgItem);
            }
        }
    }
    if (fulfillmentGroup == null) {
        // API user is trying to add an item to a fulfillment group not created
        fulfillmentGroup = fulfillmentGroupDao.create();
        FulfillmentGroupRequest fgRequest = new FulfillmentGroupRequest();
        fgRequest.setOrder(order);
        fulfillmentGroup = addFulfillmentGroupToOrder(fgRequest, false);
        fulfillmentGroup = save(fulfillmentGroup);
        order.getFulfillmentGroups().add(fulfillmentGroup);
    }
    FulfillmentGroupItem fgi = createFulfillmentGroupItemFromOrderItem(item, fulfillmentGroup, fulfillmentGroupItemRequest.getQuantity());
    if (save) {
        fgi = fulfillmentGroupItemDao.save(fgi);
    }
    // 3) add the item to the new fulfillment group
    fulfillmentGroup.addFulfillmentGroupItem(fgi);
    if (save) {
        order = orderService.save(order, priceOrder);
    }
    return fulfillmentGroup;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroupRequest(org.broadleafcommerce.core.order.service.call.FulfillmentGroupRequest) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 53 with FulfillmentGroup

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

the class FulfillmentGroupServiceImpl method getAllShippableFulfillmentGroups.

@Override
public List<FulfillmentGroup> getAllShippableFulfillmentGroups(Order order) {
    List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
    List<FulfillmentGroup> shippable = new ArrayList<FulfillmentGroup>();
    if (fulfillmentGroups != null) {
        for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
            if (isShippable(fulfillmentGroup.getType())) {
                shippable.add(fulfillmentGroup);
            }
        }
    }
    return shippable;
}
Also used : ArrayList(java.util.ArrayList) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 54 with FulfillmentGroup

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

the class FulfillmentGroupServiceImpl method removeOrderItemFromFullfillmentGroups.

@Override
@Transactional("blTransactionManager")
public void removeOrderItemFromFullfillmentGroups(Order order, OrderItem orderItem) {
    List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
    for (FulfillmentGroup fulfillmentGroup : fulfillmentGroups) {
        Iterator<FulfillmentGroupItem> itr = fulfillmentGroup.getFulfillmentGroupItems().iterator();
        while (itr.hasNext()) {
            FulfillmentGroupItem fulfillmentGroupItem = itr.next();
            if (fulfillmentGroupItem.getOrderItem().equals(orderItem)) {
                itr.remove();
                fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (fulfillmentGroupItem.getOrderItem().equals(discreteOrderItem)) {
                        itr.remove();
                        fulfillmentGroupItemDao.delete(fulfillmentGroupItem);
                        break;
                    }
                }
            }
        }
    }
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with FulfillmentGroup

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

the class FulfillmentGroupServiceImpl method removeAllFulfillmentGroupsFromOrder.

@Override
@Transactional("blTransactionManager")
public Order 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);
        }
        order = orderService.save(order, priceOrder);
    }
    return order;
}
Also used : FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Transactional(org.springframework.transaction.annotation.Transactional)

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