コード例 #1
0
  @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;
  }
コード例 #2
0
 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;
 }