Package org.broadleafcommerce.core.order.domain

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


        item.setOrder(order);
       
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
       
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(2);
        //fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
        }
       
        {
        DiscreteOrderItem item = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Product 2");
        sku.setRetailPrice(new Money(20D));
        sku.setDiscountable(true);
       
        sku = catalogService.saveSku(sku);
       
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
       
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
       
        order.addOrderItem(item);
       
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        //fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
        }
       
        order.addOfferCode(createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, "discreteOrderItem.sku.name==\"Test Sku\""));
View Full Code Here


       
        List<OrderItem> items = new ArrayList<OrderItem>();
        items.add(item);
        order.setOrderItems(items);
        for (OrderItem orderItem : items) {
            FulfillmentGroupItem fgi = new FulfillmentGroupItemImpl();
            fgi.setOrderItem(orderItem);
            fgi.setQuantity(orderItem.getQuantity());
            fgi.setFulfillmentGroup(group1);
            //fgi.setRetailPrice(new Money(15D));
            group1.addFulfillmentGroupItem(fgi);
        }
        order.setTotalShipping(new Money(0D));
       
View Full Code Here

       
        address.setState(state);
        address.setCountry(country);
       
        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);
View Full Code Here

       
        address.setState(state);
        address.setCountry(country);
       
        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);
View Full Code Here

       
        // 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
View Full Code Here

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

        // 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);
               
                if (matchingFgi == null) {
                    matchingFgi = fulfillmentGroupItemDao.create();
                    matchingFgi.setFulfillmentGroup(collapsedFg);
                    matchingFgi.setOrderItem(fgi.getOrderItem());
                    matchingFgi.setQuantity(fgi.getQuantity());
                    matchingFgi = fulfillmentGroupItemDao.save(matchingFgi);
                    collapsedFg.getFulfillmentGroupItems().add(matchingFgi);
                    fgOrderItemMap.put(orderItemId, matchingFgi);
                } else {
                    matchingFgi.setQuantity(matchingFgi.getQuantity() + fgi.getQuantity());
                }
               
                fulfillmentGroupItemDao.delete(fgi);
                fgItemIter.remove();
            }
View Full Code Here

                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());
                    fulfillmentGroupItemDao.save(fgi);
                }
            }
        }
View Full Code Here

        String fulfillmentTypeKey = (fulfillmentType == null) ? "-1" : fulfillmentType.getType();
        return addressKey + ":" + fulfillmentOptionKey + ":" + fulfillmentTypeKey;
    }
   
    protected FulfillmentGroupItem createFulfillmentGroupItemFromOrderItem(OrderItem orderItem, FulfillmentGroup fulfillmentGroup, int quantity) {
        FulfillmentGroupItem fgi = fulfillmentGroupItemDao.create();
        fgi.setFulfillmentGroup(fulfillmentGroup);
        fgi.setOrderItem(orderItem);
        fgi.setQuantity(quantity);
        return fgi;
    }
View Full Code Here

TOP

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

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.