Package org.broadleafcommerce.core.order.domain

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


        return item;
    }

    @Override
    public GiftWrapOrderItem createGiftWrapOrderItem(final GiftWrapOrderItemRequest itemRequest) {
        final GiftWrapOrderItem item = (GiftWrapOrderItem) orderItemDao.create(OrderItemType.GIFTWRAP);
        item.setSku(itemRequest.getSku());
        item.setOrder(itemRequest.getOrder());
        item.setBundleOrderItem(itemRequest.getBundleOrderItem());
        item.setQuantity(itemRequest.getQuantity());
        item.setCategory(itemRequest.getCategory());
        item.setProduct(itemRequest.getProduct());
        item.setBaseSalePrice(itemRequest.getSku().getSalePrice());
        item.setBaseRetailPrice(itemRequest.getSku().getRetailPrice());
        item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());

        if (itemRequest.getSalePriceOverride() != null) {
            item.setSalePriceOverride(Boolean.TRUE);
            item.setSalePrice(itemRequest.getSalePriceOverride());
            item.setBaseSalePrice(itemRequest.getSalePriceOverride());
        }

        if (itemRequest.getRetailPriceOverride() != null) {
            item.setRetailPriceOverride(Boolean.TRUE);
            item.setRetailPrice(itemRequest.getRetailPriceOverride());
            item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
        }

        //item.updatePrices();
        item.updateSaleAndRetailPrices();
        item.assignFinalPrice();
        item.getWrappedItems().addAll(itemRequest.getWrappedItems());
        for (OrderItem orderItem : item.getWrappedItems()) {
            orderItem.setGiftWrapOrderItem(item);
        }

        return item;
    }
View Full Code Here


        //update any remaining gift wrap items with their cloned wrapped item values, instead of the originals
        Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
        while (addedItems.hasNext()) {
            OrderItem addedItem = addedItems.next();
            if (addedItem instanceof GiftWrapOrderItem) {
                GiftWrapOrderItem giftItem = (GiftWrapOrderItem) addedItem;
                List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
                Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
                while (wrappedItems.hasNext()) {
                    OrderItem wrappedItem = wrappedItems.next();
                    if (oldNewItemMap.containsKey(wrappedItem)) {
                        OrderItem newItem = oldNewItemMap.get(wrappedItem);
                        newItem.setGiftWrapOrderItem(giftItem);
                        itemsToAdd.add(newItem);
                        wrappedItem.setGiftWrapOrderItem(null);
                        wrappedItems.remove();
                    }
                }
                giftItem.getWrappedItems().addAll(itemsToAdd);
            } else if (addedItem instanceof BundleOrderItem) {
                //a GiftWrapOrderItem inside a BundleOrderItem can only wrap other members of that bundle
                //or root members of the order - not members of an entirely different bundle
                boolean isValidBundle = true;

                Map<String, DiscreteOrderItem> newItemsMap = new HashMap<String, DiscreteOrderItem>();
                for (DiscreteOrderItem newItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()){
                    newItemsMap.put(newItem.getSku().getId() + "_" + newItem.getPrice(), newItem);
                }

                checkBundle: {
                    for (DiscreteOrderItem itemFromBundle : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
                        if (itemFromBundle instanceof GiftWrapOrderItem) {
                            GiftWrapOrderItem giftItem = (GiftWrapOrderItem) itemFromBundle;
                            List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
                            Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
                            while (wrappedItems.hasNext()) {
                                OrderItem wrappedItem = wrappedItems.next();
                                if (oldNewItemMap.containsKey(wrappedItem)) {
                                    OrderItem newItem = oldNewItemMap.get(wrappedItem);
                                    newItem.setGiftWrapOrderItem(giftItem);
                                    itemsToAdd.add(newItem);
                                    wrappedItem.setGiftWrapOrderItem(null);
                                    wrappedItems.remove();
                                } else if (wrappedItem instanceof DiscreteOrderItem) {
                                    DiscreteOrderItem discreteWrappedItem = (DiscreteOrderItem) wrappedItem;
                                    String itemKey = discreteWrappedItem.getSku().getId() + "_" + discreteWrappedItem.getPrice();
                                    if (newItemsMap.containsKey(itemKey)) {
                                        OrderItem newItem = newItemsMap.get(itemKey);
                                        newItem.setGiftWrapOrderItem(giftItem);
                                        itemsToAdd.add(newItem);
                                        discreteWrappedItem.setGiftWrapOrderItem(null);
                                        wrappedItems.remove();
                                    } else {
                                        isValidBundle = false;
                                        break checkBundle;
                                    }
                                } else {
                                    isValidBundle = false;
                                    break checkBundle;
                                }
                            }
                            giftItem.getWrappedItems().addAll(itemsToAdd);
                        }
                    }
                }

                if (!isValidBundle) {
View Full Code Here

        //clear out any Gift Wrap items that contain one or more removed wrapped items
        Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
        while (addedItems.hasNext()) {
            OrderItem addedItem = addedItems.next();
            if (addedItem instanceof GiftWrapOrderItem) {
                GiftWrapOrderItem giftWrapOrderItem = (GiftWrapOrderItem) addedItem;
                boolean removeItem = false;
                for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
                    if (mergeCartResponse.getRemovedItems().contains(wrappedItem)) {
                        removeItem = true;
                        break;
                    }
                }
                if (removeItem) {
                    for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
                        wrappedItem.setGiftWrapOrderItem(null);
                    }
                    giftWrapOrderItem.getWrappedItems().clear();
                    for (OrderItem cartItem : customerCart.getOrderItems()) {
                        if (cartItem.getGiftWrapOrderItem() != null && oldNewItemMap.containsKey(cartItem.getGiftWrapOrderItem())) {
                            cartItem.setGiftWrapOrderItem(null);
                        }
                    }
View Full Code Here

    public void delete(OrderItem orderItem) {
        if (!em.contains(orderItem)) {
            orderItem = readOrderItemById(orderItem.getId());
        }
        if (GiftWrapOrderItem.class.isAssignableFrom(orderItem.getClass())) {
            final GiftWrapOrderItem giftItem = (GiftWrapOrderItem) orderItem;
            for (OrderItem wrappedItem : giftItem.getWrappedItems()) {
                wrappedItem.setGiftWrapOrderItem(null);
                wrappedItem = save(wrappedItem);
            }
        }
        em.remove(orderItem);
View Full Code Here

        //fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
        }

        {
        GiftWrapOrderItem item = new GiftWrapOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test GiftWrap");
        sku.setRetailPrice(new Money(1D));
        sku.setDiscountable(true);

        sku = catalogService.saveSku(sku);

        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.getWrappedItems().add(item1);
        item.setOrderItemType(OrderItemType.GIFTWRAP);

        item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);

        order.addOrderItem(item);
View Full Code Here

        //fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
        }

        {
        GiftWrapOrderItem item = new GiftWrapOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test GiftWrap");
        sku.setRetailPrice(new Money(1D));
        sku.setDiscountable(true);

        sku = catalogService.saveSku(sku);

        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.getWrappedItems().add(item1);
        item.setOrderItemType(OrderItemType.GIFTWRAP);

        item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);

        order.addOrderItem(item);
View Full Code Here

        itemRequest.setQuantity(1);
        itemRequest.setDiscreteOrderItems(discreteOrderItems);

        BundleOrderItem newBundle = (BundleOrderItem) cartService.addBundleItemToOrder(order, itemRequest);
        List<OrderItem> addedItems = new ArrayList<OrderItem>();
        GiftWrapOrderItem giftItem = null;
        for (DiscreteOrderItem addedItem : newBundle.getDiscreteOrderItems()) {
            if (addedItem instanceof GiftWrapOrderItem) {
                giftItem = (GiftWrapOrderItem) addedItem;
            } else {
                addedItems.add(addedItem);
            }
        }
        for (OrderItem addedItem : addedItems) {
            addedItem.setGiftWrapOrderItem(giftItem);
        }
        giftItem.getWrappedItems().addAll(addedItems);
        order = cartService.save(order, false);

        return order;
    }
View Full Code Here

        BundleOrderItemRequest itemRequest = createBundleOrderItemRequestWithGiftWrap();

        BundleOrderItem newBundle = (BundleOrderItem) cartService.addBundleItemToOrder(order, itemRequest);
        List<OrderItem> addedItems = new ArrayList<OrderItem>();
        GiftWrapOrderItem giftItem = null;
        for (DiscreteOrderItem addedItem : newBundle.getDiscreteOrderItems()) {
            if (addedItem instanceof GiftWrapOrderItem) {
                giftItem = (GiftWrapOrderItem) addedItem;
            } else {
                addedItems.add(addedItem);
            }
        }
        for (OrderItem addedItem : addedItems) {
            addedItem.setGiftWrapOrderItem(giftItem);
        }
        giftItem.getWrappedItems().addAll(addedItems);
        order = cartService.save(order, false);

        return order;
    }
View Full Code Here

                newProduct.getId(), newCategory.getId(), 2));
        addedItems.add(cartService.addSkuToOrder(order.getId(), newActiveProduct.getDefaultSku().getId(),
                newProduct.getId(), newCategory.getId(), 2));

        BundleOrderItem newBundle = (BundleOrderItem) cartService.addBundleItemToOrder(order, createBundleOrderItemRequestWithGiftWrap());
        GiftWrapOrderItem giftItem = null;
        for (DiscreteOrderItem addedItem : newBundle.getDiscreteOrderItems()) {
            if (addedItem instanceof GiftWrapOrderItem) {
                giftItem = (GiftWrapOrderItem) addedItem;
            }
        }
        for (OrderItem addedItem : addedItems) {
            addedItem.setGiftWrapOrderItem(giftItem);
        }
        giftItem.getWrappedItems().addAll(addedItems);
        order = cartService.save(order, false);

        return order;
    }
View Full Code Here

        Order order = cartService.createNewCartForCustomer(customer);

        BundleOrderItem newBundle = (BundleOrderItem) cartService.addBundleItemToOrder(order, createBundleOrderItemRequest());
        BundleOrderItem newBundle2 = (BundleOrderItem) cartService.addBundleItemToOrder(order, createBundleOrderItemRequestWithGiftWrap());
        GiftWrapOrderItem giftItem = null;
        for (DiscreteOrderItem addedItem : newBundle2.getDiscreteOrderItems()) {
            if (addedItem instanceof GiftWrapOrderItem) {
                giftItem = (GiftWrapOrderItem) addedItem;
            }
        }
        for (DiscreteOrderItem addedItem : newBundle.getDiscreteOrderItems()) {
            addedItem.setGiftWrapOrderItem(giftItem);
        }
        giftItem.getWrappedItems().addAll(newBundle.getDiscreteOrderItems());
        order = cartService.save(order, false);

        return order;
    }
View Full Code Here

TOP

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

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.