public Order setUpAnonymousCartWithBundleGiftWrapReferringItemsInAnotherBundle()
      throws PricingException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());

    Order order = cartService.createNewCartForCustomer(customer);

    BundleOrderItem newBundle =
        (BundleOrderItem) orderService.addBundleItemToOrder(order, createBundleOrderItemRequest());
    BundleOrderItem newBundle2 =
        (BundleOrderItem)
            orderService.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 = orderService.save(order, false);

    return order;
  }
  public Order setUpAnonymousCartWithBundleGiftWrap() throws PricingException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());

    Order order = cartService.createNewCartForCustomer(customer);

    BundleOrderItemRequest itemRequest = createBundleOrderItemRequestWithGiftWrap();

    BundleOrderItem newBundle =
        (BundleOrderItem) orderService.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 = orderService.save(order, false);

    return order;
  }
  public Order setUpAnonymousCartWithInactiveBundleGiftWrap() throws PricingException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());

    Order order = cartService.createNewCartForCustomer(customer);

    Sku newSku = addTestSku("Small Plastic Crate", "Plastic Crate", "Crates");
    Sku newInactiveSku = addTestSku("Small Red Plastic Crate", "Plastic Crate", "Crates", false);
    Sku giftWrapSku = addTestSku("Gift Box", "Gift Box", "Gift Wraps");
    Category category = newSku.getAllParentProducts().get(0).getDefaultCategory();

    List<DiscreteOrderItemRequest> discreteOrderItems = new ArrayList<DiscreteOrderItemRequest>();
    discreteOrderItems.add(createDiscreteOrderItemRequest(newSku, 1));
    discreteOrderItems.add(createDiscreteOrderItemRequest(newInactiveSku, 1));
    discreteOrderItems.add(
        createGiftWrapOrderItemRequest(giftWrapSku, 1, new ArrayList<OrderItem>()));

    BundleOrderItemRequest itemRequest = new BundleOrderItemRequest();
    itemRequest.setCategory(category);
    itemRequest.setName("test bundle " + bundleCount++);
    itemRequest.setQuantity(1);
    itemRequest.setDiscreteOrderItems(discreteOrderItems);

    BundleOrderItem newBundle =
        (BundleOrderItem) orderService.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 = orderService.save(order, false);

    return order;
  }
  public Order setUpAnonymousCartWithBundleGiftWrapReferringToRootItems() throws PricingException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());

    Order order = cartService.createNewCartForCustomer(customer);

    Sku newSku = addTestSku("Small Plastic Bowl", "Plastic Bowl", "Bowls");
    Sku newActiveSku = addTestSku("Small Red Plastic Bowl", "Plastic Bowl", "Bowls");

    Product newProduct = newSku.getAllParentProducts().get(0);
    Category newCategory = newProduct.getDefaultCategory();

    List<OrderItem> addedItems = new ArrayList<OrderItem>();
    addedItems.add(
        orderService.addSkuToOrder(
            order.getId(), newSku.getId(), newProduct.getId(), newCategory.getId(), 2));
    addedItems.add(
        orderService.addSkuToOrder(
            order.getId(), newActiveSku.getId(), newProduct.getId(), newCategory.getId(), 2));

    BundleOrderItem newBundle =
        (BundleOrderItem)
            orderService.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 = orderService.save(order, false);

    return order;
  }