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; }
@Override public OrderItem findLastMatchingItem(Order order, Long skuId, Long productId) { if (order.getOrderItems() != null) { for (int i = (order.getOrderItems().size() - 1); i >= 0; i--) { OrderItem currentItem = (order.getOrderItems().get(i)); if (currentItem instanceof DiscreteOrderItem) { DiscreteOrderItem discreteItem = (DiscreteOrderItem) currentItem; if (skuId != null) { if (discreteItem.getSku() != null && skuId.equals(discreteItem.getSku().getId())) { return discreteItem; } } else if (productId != null && discreteItem.getProduct() != null && productId.equals(discreteItem.getProduct().getId())) { return discreteItem; } } else if (currentItem instanceof BundleOrderItem) { BundleOrderItem bundleItem = (BundleOrderItem) currentItem; if (skuId != null) { if (bundleItem.getSku() != null && skuId.equals(bundleItem.getSku().getId())) { return bundleItem; } } else if (productId != null && bundleItem.getProduct() != null && productId.equals(bundleItem.getProduct().getId())) { return bundleItem; } } } } return null; }
public void removeAllItemAdjustments() { for (OrderItem orderItem : getDelegate().getOrderItems()) { orderItem.removeAllAdjustments(); adjustmentPrice = null; resetTotalitarianOfferApplied(); if (orderItem instanceof BundleOrderItem) { for (DiscreteOrderItem discreteOrderItem : ((BundleOrderItem) orderItem).getDiscreteOrderItems()) { discreteOrderItem.setPrice(null); } } orderItem.setPrice(null); orderItem.assignFinalPrice(); } splitItems.clear(); }
protected OrderItem findMatchingItem(Order order, OrderItemRequestDTO itemToFind) { if (order == null) { return null; } for (OrderItem currentItem : order.getOrderItems()) { if (currentItem instanceof DiscreteOrderItem) { DiscreteOrderItem discreteItem = (DiscreteOrderItem) currentItem; if (itemMatches( discreteItem.getSku(), discreteItem.getProduct(), discreteItem.getOrderItemAttributes(), itemToFind)) { return discreteItem; } } else if (currentItem instanceof BundleOrderItem) { BundleOrderItem bundleItem = (BundleOrderItem) currentItem; if (itemMatches(bundleItem.getSku(), bundleItem.getProduct(), null, itemToFind)) { return bundleItem; } } } return null; }