Package org.broadleafcommerce.core.order.domain

Examples of org.broadleafcommerce.core.order.domain.FulfillmentGroup


            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);
        }
View Full Code Here


            return order;
        }

        // Get the default (first) shippable fulfillment group to collapse the others into
        ListIterator<FulfillmentGroup> fgIter = shippableFulfillmentGroupList.listIterator();
        FulfillmentGroup collapsedFg = fgIter.next();
       
        List<FulfillmentGroup> newFulfillmentGroupList = nonShippableFulfillmentGroupList;
        newFulfillmentGroupList.add(collapsedFg);
        order.setFulfillmentGroups(newFulfillmentGroupList);

        // Build out a map representing the default shippable fgs items keyed by OrderItem id
        Map<Long, FulfillmentGroupItem> fgOrderItemMap = new HashMap<Long, FulfillmentGroupItem>();
        for (FulfillmentGroupItem fgi : collapsedFg.getFulfillmentGroupItems()) {
            fgOrderItemMap.put(fgi.getOrderItem().getId(), fgi);
        }
       
        // For all non default shippable fgs, collapse the items into the default shippable fg
        while (fgIter.hasNext()) {
            FulfillmentGroup fg = fgIter.next();
            ListIterator<FulfillmentGroupItem> fgItemIter = fg.getFulfillmentGroupItems().listIterator();
            while (fgItemIter.hasNext()) {
                FulfillmentGroupItem fgi = fgItemIter.next();
               
                Long orderItemId = fgi.getOrderItem().getId();
                FulfillmentGroupItem matchingFgi = fgOrderItemMap.get(orderItemId);
View Full Code Here

            }
        }
       
        for (OrderMultishipOption option : multishipOptions) {
            String key = getKey(option.getAddress(), option.getFulfillmentOption(), ((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());
            FulfillmentGroup fg = multishipGroups.get(key);
           
            // Get or create a fulfillment group that matches this OrderMultishipOption destination
            if (fg == null) {
                FulfillmentGroupRequest fgr = new FulfillmentGroupRequest();
               
                fgr.setOrder(order);
               
                if (option.getAddress() != null) {
                    fgr.setAddress(option.getAddress());
                }
               
                if (option.getFulfillmentOption() != null) {
                    fgr.setOption(option.getFulfillmentOption());
                }
               
                fgr.setFulfillmentType(((DiscreteOrderItem) option.getOrderItem()).getSku().getFulfillmentType());

                fg = addFulfillmentGroupToOrder(fgr, false);
                fg = save(fg);
                order.getFulfillmentGroups().add(fg);
            }
           
            // See if there is a fulfillment group item that matches this OrderMultishipOption
            // OrderItem request
            FulfillmentGroupItem fulfillmentGroupItem = null;
            for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
                if (fgi.getOrderItem().getId() == option.getOrderItem().getId()) {
                    fulfillmentGroupItem = fgi;
                }
            }
           
            // If there is no matching fulfillment group item, create a new one with quantity 1
            if (fulfillmentGroupItem == null) {
                fulfillmentGroupItem = fulfillmentGroupItemDao.create();
                fulfillmentGroupItem.setFulfillmentGroup(fg);
                fulfillmentGroupItem.setOrderItem(option.getOrderItem());
                fulfillmentGroupItem.setQuantity(1);
                fulfillmentGroupItem = fulfillmentGroupItemDao.save(fulfillmentGroupItem);
                fg.getFulfillmentGroupItems().add(fulfillmentGroupItem);
            } else {
                // There are three potential scenarios where a fulfillment group item exists:
                //   1: It has been previously created and exists in the database and
                //      has an id. This means it's in the fgItemQuantityMap. If there is
                //      remaining quantity in that map, we will decrement it for future
                //      usage. If the quantity is 0 in the map, that means that we have more
                //      items than we did before, and we must simply increment the quantity.
                //      (qty == 0 or qty is not null)
                //   2: It was created in this request but has been saved to the database because
                //      it is a brand new fulfillment group and so it has an id.
                //      However, it does not have an entry in the fgItemQuantityMap,
                //      so we can simply increment the quantity.
                //      (qty == null)
                //   3: It was created in this request and has not yet been saved to the database.
                //      This is because it was a previously existing fulfillment group that has new
                //      items. Therefore, we simply increment the quantity.
                //      (fulfillmentGroupItem.getId() == null)
                if (fulfillmentGroupItem.getId() != null) {
                    Integer qty = fgItemQuantityMap.get(fulfillmentGroupItem.getId());
                    if (qty == null || qty == 0) {
                        fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
                    } else {
                        qty -= 1;
                        fgItemQuantityMap.put(fulfillmentGroupItem.getId(), qty);
                    }
                } else {
                    fulfillmentGroupItem.setQuantity(fulfillmentGroupItem.getQuantity() + 1);
                }
            }
           
            multishipGroups.put(key, fg);
        }
       
        // Go through all of the items in the fgItemQuantityMap. For all items that have a
        // zero quantity, we don't need to do anything because we've already matched them
        // to the newly requested OrderMultishipOption. For items that have a non-zero quantity,
        // there are two possible scenarios:
        //   1: The quantity remaining matches exactly the quantity of a fulfillmentGroupItem.
        //      In this case, we can simply remove the fulfillmentGroupItem.
        //   2: The quantity in the map is greater than what we've found. This means that we
        //      need to subtract the remaining old quantity from the new quantity.
        // Furthermore, delete the empty fulfillment groups.
        for (Entry<Long, Integer> entry : fgItemQuantityMap.entrySet()) {
            if (entry.getValue() > 0) {
                FulfillmentGroupItem fgi = fulfillmentGroupItemDao.readFulfillmentGroupItemById(entry.getKey());
                if (fgi.getQuantity() == entry.getValue()) {
                    FulfillmentGroup fg = fgi.getFulfillmentGroup();
                    fg.getFulfillmentGroupItems().remove(fgi);
                    fulfillmentGroupItemDao.delete(fgi);
                    if (fg.getFulfillmentGroupItems().size() == 0) {
                        order.getFulfillmentGroups().remove(fg);
                        fulfillmentGroupDao.delete(fg);
                    }
                } else {
                    fgi.setQuantity(fgi.getQuantity() - entry.getValue());
View Full Code Here

    @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);
        }
View Full Code Here

        Address address = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId()).get(0).getAddress();
        Order order = cartService.findOrderById(orderId);

        fulfillmentGroup.setOrder(order);
        fulfillmentGroup.setAddress(address);
        FulfillmentGroup fg = cartService.addFulfillmentGroupToOrder(order, fulfillmentGroup);
        assert fg != null;
        assert fg.getId() != null;
        assert fg.getAddress().equals(fulfillmentGroup.getAddress());
        assert fg.getOrder().equals(order);
        assert fg.getMethod().equals(fulfillmentGroup.getMethod());
        assert fg.getReferenceNumber().equals(fulfillmentGroup.getReferenceNumber());
        this.fulfillmentGroupId = fg.getId();
    }
View Full Code Here

    public void removeFulfillmentGroupFromOrder() throws PricingException {
        Order order = cartService.findOrderById(orderId);
        List<FulfillmentGroup> fgItems = order.getFulfillmentGroups();
        assert fgItems.size() > 0;
        int startingSize = fgItems.size();
        FulfillmentGroup item = fgItems.get(0);
        assert item != null;
        cartService.removeFulfillmentGroupFromOrder(order, item);
        order = cartService.findOrderById(orderId);
        List<FulfillmentGroup> items = order.getFulfillmentGroups();
        assert items != null;
View Full Code Here

    @Test(groups = { "findFulFillmentGroupForOrderFirstLegacy" }, dependsOnGroups = { "addFulfillmentGroupToOrderFirstLegacy" })
    @Transactional
    public void findFillmentGroupForOrderFirst() {
        Order order = cartService.findOrderById(orderId);
        FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
        assert fg != null;
        assert fg.getId() != null;
        FulfillmentGroup fulfillmentGroup = em.find(FulfillmentGroupImpl.class, fulfillmentGroupId);
        assert fg.getAddress().getId().equals(fulfillmentGroup.getAddress().getId());
        assert fg.getOrder().equals(order);
        assert fg.getMethod().equals(fulfillmentGroup.getMethod());
        assert fg.getReferenceNumber().equals(fulfillmentGroup.getReferenceNumber());
    }
View Full Code Here

        Customer customer = customerService.readCustomerByUsername(userName);
        Address address = customerAddressService.readActiveCustomerAddressesByCustomerId(customer.getId()).get(0).getAddress();
        Order order = cartService.findOrderById(orderId);
        List<OrderItem> orderItems = order.getOrderItems();
        assert(orderItems.size() > 0);
        FulfillmentGroup newFg = new FulfillmentGroupImpl();
        newFg.setAddress(address);
        newFg.setMethod("standard");
        newFg.setService(ShippingServiceType.BANDED_SHIPPING.getType());
        try {
            newFg = cartService.addItemToFulfillmentGroup(orderItems.get(0), newFg, 1);
        } catch (PricingException e) {
            throw new RuntimeException(e);
        }
        order = cartService.findOrderById(orderId);
        FulfillmentGroup newNewFg = order.getFulfillmentGroups().get(order.getFulfillmentGroups().indexOf(newFg));
        assert(newNewFg.getFulfillmentGroupItems().size() == 1);
        assert(newNewFg.getFulfillmentGroupItems().get(0).getOrderItem().equals(orderItems.get(0)));

    }
View Full Code Here

     */
    @Test(groups = { "findDefaultFulFillmentGroupForOrderLegacy" }, dependsOnGroups = { "findCurrentCartForCustomerLegacy", "addFulfillmentGroupToOrderFirstLegacy" })
    @Transactional
    public void findDefaultFillmentGroupForOrder() {
        Order order = cartService.findOrderById(orderId);
        FulfillmentGroup fg = cartService.findDefaultFulfillmentGroupForOrder(order);
        assert fg != null;
        assert fg.getId() != null;
        FulfillmentGroup fulfillmentGroup = em.find(FulfillmentGroupImpl.class, fulfillmentGroupId);
        assert fg.getAddress().getId().equals(fulfillmentGroup.getAddress().getId());
        assert fg.getOrder().equals(order);
        assert fg.getMethod().equals(fulfillmentGroup.getMethod());
        assert fg.getReferenceNumber().equals(fulfillmentGroup.getReferenceNumber());
    }
View Full Code Here

        try {
            cartService.removeItemFromOrder(order, item);
        } catch (PricingException e) {
            throw new RuntimeException(e);
        }
        FulfillmentGroup fg = cartService.findDefaultFulfillmentGroupForOrder(order);
        for (FulfillmentGroupItem fulfillmentGroupItem : fg.getFulfillmentGroupItems()) {
            assert !fulfillmentGroupItem.getOrderItem().equals(item);
        }
    }
View Full Code Here

TOP

Related Classes of org.broadleafcommerce.core.order.domain.FulfillmentGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.