in ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreAutoPreferences.java [752:907]
public static Map<String, Object> runCombineOrders(DispatchContext dctx, Map<String, Object> context) {
Map<String, Object> result = new HashMap<>();
LocalDispatcher dispatcher = dctx.getDispatcher();
Delegator delegator = dctx.getDelegator();
Locale locale = (Locale) context.get("locale");
String productStoreId = (String) context.get("productStoreId");
try {
GenericValue userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", "system").queryOne();
ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
GetSellingManagerSoldListingsCall sellingManagerSoldListings = new GetSellingManagerSoldListingsCall(apiContext);
SellingManagerSoldOrderType[] sellingManagerSoldOrders = sellingManagerSoldListings.getSellingManagerSoldListings();
if (sellingManagerSoldOrders != null) {
int soldOrderLength = sellingManagerSoldOrders.length;
GenericValue ebayPref = EntityQuery.use(delegator).from("EbayProductStorePref").where("productStoreId", productStoreId, "autoPrefEnumId", "ENA_COMB_ORD").queryOne();
if (ebayPref != null) {
Timestamp beginDate = UtilDateTime.toTimestamp("01/01/2001 00:00:00");
Long daysCount = Long.parseLong(ebayPref.get("condition1").toString());
Hashtable<String, List<Map<String, Object>>> h = new Hashtable<>();
for (SellingManagerSoldOrderType sellingManagerSoldOrder : sellingManagerSoldOrders) {
String buyerId = sellingManagerSoldOrder.getBuyerID().toString();
List<Map<String, Object>> soldGroupList = new LinkedList<>();
Map<String, Object> mymap = new HashMap<>();
mymap.put("group", "");
mymap.put("soldorder", sellingManagerSoldOrder);
if (!h.isEmpty()) {
Enumeration<String> enums = h.keys();
String key = "";
while (enums.hasMoreElements()) {
key = enums.nextElement();
List<Map<String, Object>> tempList = h.get(key);
if (key.equals(buyerId)) {
key = buyerId;
tempList.add(mymap);
h.put(buyerId, tempList);
}
}
if (!key.equals(buyerId)) {
soldGroupList.clear();
soldGroupList.add(mymap);
h.put(buyerId, soldGroupList);
}
} else {
soldGroupList.add(mymap);
h.put(buyerId, soldGroupList);
}
}
Enumeration<String> enums = h.keys();
while (enums.hasMoreElements()) {
int groupRunning = 0;
String key = enums.nextElement();
List<Map<String, Object>> soldGroupList = h.get(key);
int maxItems = Integer.parseInt(ebayPref.get("condition2").toString());
if (soldGroupList.size() > 1) {
for (int j = 0; j < soldGroupList.size(); j++) {
Map<String, Object> myMap = soldGroupList.get(j);
SellingManagerSoldOrderType soldorder = (SellingManagerSoldOrderType) myMap.get("soldorder");
Timestamp createdate = UtilDateTime.toTimestamp(soldorder.getCreationTime().getTime());
if (myMap.get("group").toString().isEmpty()) {
beginDate = createdate;
}
beginDate = findStartDate(beginDate, soldGroupList);
runCheckAndGroup(groupRunning, beginDate, daysCount, soldGroupList);
groupRunning++;
}
int x = 0;
while (x < groupRunning) {
OrderType order = new OrderType();
order.setCreatingUserRole(TradingRoleCodeType.SELLER);
BuyerPaymentMethodCodeType[] buyerPayment = new BuyerPaymentMethodCodeType[1];
buyerPayment[0] = BuyerPaymentMethodCodeType.CASH_ON_PICKUP;
order.setPaymentMethods(buyerPayment);
TransactionArrayType transactionArr = new TransactionArrayType();
List<TransactionType> translist = new LinkedList<TransactionType>();
AmountType total = new AmountType();
double totalAmt = 0.0;
CurrencyCodeType currencyId = null;
int totalQty = 0;
for (Map<String, Object> myMap : soldGroupList) {
if (UtilValidate.isNotEmpty(myMap.get("group"))) {
if (x == Integer.parseInt(myMap.get("group").toString())) {
SellingManagerSoldOrderType sellingManagerSoldOrder = (SellingManagerSoldOrderType) myMap.get("soldorder");
String buyerId = sellingManagerSoldOrder.getBuyerID().toString();
int qty = sellingManagerSoldOrder.getTotalQuantity();
totalQty = totalQty + qty;
if (key.equals(buyerId) && (UtilValidate.isEmpty(sellingManagerSoldOrder.getOrderStatus().getPaidTime()))) {
double totalAmount = 0.0;
if (UtilValidate.isNotEmpty(sellingManagerSoldOrder.getTotalAmount())) {
totalAmount = sellingManagerSoldOrder.getTotalAmount().getValue();
currencyId = sellingManagerSoldOrder.getTotalAmount().getCurrencyID();
} else {
totalAmount = sellingManagerSoldOrder.getSalePrice().getValue();
currencyId = sellingManagerSoldOrder.getSalePrice().getCurrencyID();
}
//Combine
totalAmt = totalAmt + totalAmount;
SellingManagerSoldTransactionType[] sellingManagerSoldTransactions = sellingManagerSoldOrder.getSellingManagerSoldTransaction();
//set transaction
for (SellingManagerSoldTransactionType sellingManagerSoldTransaction : sellingManagerSoldTransactions) {
TransactionType transtype = new TransactionType();
ItemType itemtype = new ItemType();
if (UtilValidate.isNotEmpty(sellingManagerSoldTransaction.getItemID())) {
itemtype.setItemID(sellingManagerSoldTransaction.getItemID());
transtype.setItem(itemtype);
transtype.setTransactionID(sellingManagerSoldTransaction.getTransactionID().toString());
translist.add(transtype);
}
}
}
}
}
}
if (totalQty < maxItems) {
total.setValue(totalAmt);
total.setCurrencyID(currencyId);
TransactionType[] transArr = new TransactionType[translist.size()];
for (int counter = 0; counter < translist.size(); counter++) {
transArr[counter] = translist.get(counter);
}
transactionArr.setTransaction(transArr);
if (transactionArr.getTransactionLength() > 1) {
order.setTotal(total);
order.setTransactionArray(transactionArr);
AddOrderCall call = new AddOrderCall(apiContext);
AddOrderRequestType req = new AddOrderRequestType();
AddOrderResponseType resp = null;
req.setOrder(order);
resp = (AddOrderResponseType) call.execute(req);
if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
String orderId = resp.getOrderID();
Debug.logInfo(":: new order id is = " + orderId, MODULE);
} else {
EbayStoreHelper.createErrorLogMessage(userLogin, dispatcher, productStoreId, resp.getAck().toString(), "Add order : runCombineOrders", resp.getErrors(0).getLongMessage());
}
}
}
x++;
}
}
}
}
}
result = ServiceUtil.returnSuccess();
} catch (GenericEntityException | GenericServiceException e) {
result = ServiceUtil.returnError(e.getMessage());
} catch (Exception e) {
return ServiceUtil.returnError(e.getMessage());
}
return result;
}