for(GenericValue shipGroup : orh.getOrderItemShipGroups()) {
if (!UtilValidate.isEmpty(shipGroup.getString("supplierPartyId"))) {
// This ship group is a drop shipment: we create a purchase order for it
String supplierPartyId = shipGroup.getString("supplierPartyId");
// create the cart
ShoppingCart cart = new ShoppingCart(delegator, orh.getProductStoreId(), null, orh.getCurrency());
cart.setOrderType("PURCHASE_ORDER");
cart.setBillToCustomerPartyId(cart.getBillFromVendorPartyId()); //Company
cart.setBillFromVendorPartyId(supplierPartyId);
cart.setOrderPartyId(supplierPartyId);
// Get the items associated to it and create po
List<GenericValue> items = orh.getValidOrderItems(shipGroup.getString("shipGroupSeqId"));
if (!UtilValidate.isEmpty(items)) {
for(GenericValue item : items) {
try {
int itemIndex = cart.addOrIncreaseItem(item.getString("productId"),
null, // amount
item.getBigDecimal("quantity"),
null, null, null, // reserv
item.getTimestamp("shipBeforeDate"),
item.getTimestamp("shipAfterDate"),
null, null, null,
null, null, null,
null, dispatcher);
ShoppingCartItem sci = cart.findCartItem(itemIndex);
sci.setAssociatedOrderId(orderId);
sci.setAssociatedOrderItemSeqId(item.getString("orderItemSeqId"));
sci.setOrderItemAssocTypeId("DROP_SHIPMENT");
} catch (Exception e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"OrderOrderCreatingDropShipmentsError",
UtilMisc.toMap("orderId", orderId, "errorString", e.getMessage()),
locale));
}
}
}
// If there are indeed items to drop ship, then create the purchase order
if (!UtilValidate.isEmpty(cart.items())) {
// set checkout options
cart.setDefaultCheckoutOptions(dispatcher);
// the shipping address is the one of the customer
cart.setShippingContactMechId(shipGroup.getString("contactMechId"));
// associate ship groups of sales and purchase orders
ShoppingCart.CartShipInfo cartShipInfo = cart.getShipGroups().get(0);
cartShipInfo.setAssociatedShipGroupSeqId(shipGroup.getString("shipGroupSeqId"));
// create the order
CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
coh.createOrder(userLogin);
} else {