getBestOfferCall.getBestOffers();
BestOfferType[] bestOffers = getBestOfferCall.getReturnedBestOffers();
List<String> acceptBestOfferIndexId = FastList.newInstance();
SortedMap<String, Object> acceptBestOfferIDs = new TreeMap<String, Object>();
//Loop for get data best offer from buyer
RespondToBestOfferCall respondToBestOfferCall = new RespondToBestOfferCall(apiContext);
respondToBestOfferCall.setItemID(itemID);
for (int offerCount = 0; offerCount < bestOffers.length; offerCount++) {
BestOfferType bestOfferType = bestOffers[offerCount];
BestOfferStatusCodeType bestOfferStatusCodeType = bestOfferType.getStatus();
//Check status of best offer
if (bestOfferStatusCodeType == BestOfferStatusCodeType.PENDING) {
String bestOfferID = bestOfferType.getBestOfferID();
UserType buyer = bestOfferType.getBuyer();
String buyerUserID = buyer.getUserID();
AmountType price = bestOfferType.getPrice();
String offerPrice = new Double(price.getValue()).toString();
Double doCerrentPrice = Double.parseDouble(offerPrice);
int offerQuantity = bestOfferType.getQuantity();
String[] bestOfferIDs = { bestOfferID };
respondToBestOfferCall.setBestOfferIDs(bestOfferIDs);
if (rejectOffer.equals("Y")) {
if (offerQuantity > inventoryQuantityItem) {
respondToBestOfferCall.setSellerResponse("Your order is more than inventory item's Buy-It-Now price.");
respondToBestOfferCall.setBestOfferAction(BestOfferActionCodeType.DECLINE);
respondToBestOfferCall.respondToBestOffer();
continue;
}
}
String buyerMessage = bestOfferType.getBuyerMessage();
if (ignoreOfferMessage.equals("Y") && UtilValidate.isNotEmpty(buyerMessage)) {
GenericValue userOfferCheck = delegator.findByPrimaryKey("EbayUserBestOffer", UtilMisc.toMap("itemId", itemID, "userId", buyerUserID));
if (UtilValidate.isEmpty(userOfferCheck)) {
GenericValue ebayUserBestOffer = delegator.makeValue("EbayUserBestOffer");
ebayUserBestOffer.put("productStoreId", productStoreId);
ebayUserBestOffer.put("itemId", itemID);
ebayUserBestOffer.put("userId", buyerUserID);
ebayUserBestOffer.put("bestOfferId", bestOfferID);
ebayUserBestOffer.put("contactStatus", "NOT_CONTACT");
ebayUserBestOffer.create();
}
continue;
}
BigDecimal cerrentPrice = new BigDecimal(doCerrentPrice);
if (cerrentPrice.compareTo(acceptPrice) >= 0) {
acceptBestOfferIndexId.add(bestOfferID);
String Quantity = String.valueOf(offerQuantity);
acceptBestOfferIDs.put(bestOfferID, Quantity);
} else if ((cerrentPrice.compareTo(greaterPrice) >= 0) && (cerrentPrice.compareTo(lessThanPrice) <= 0 ) && rejectGreaterEnable.equals("Y")) {
respondToBestOfferCall.setBestOfferAction(BestOfferActionCodeType.DECLINE);
respondToBestOfferCall.setSellerResponse(rejectGreaterMsg);
respondToBestOfferCall.respondToBestOffer();
} else if ((cerrentPrice.compareTo(rejectPrice) <= 0 && rejectLessEnable.equals("Y"))) {
respondToBestOfferCall.setBestOfferAction(BestOfferActionCodeType.DECLINE);
respondToBestOfferCall.setSellerResponse(rejectLessMsg);
respondToBestOfferCall.respondToBestOffer();
} else {
respondToBestOfferCall.setBestOfferAction(BestOfferActionCodeType.DECLINE);
respondToBestOfferCall.respondToBestOffer();
}
}
}
if (acceptBestOfferIndexId.size() > 0) {
int quantityAvailable = inventoryQuantityItem;
Collections.sort(acceptBestOfferIndexId);
RespondToBestOfferCall respondAcceptBestOfferCall = new RespondToBestOfferCall(apiContext);
respondAcceptBestOfferCall.setItemID(itemID);
for (String bestOfferIdIndex : acceptBestOfferIndexId) {
if (quantityAvailable <= 0) break;
Integer offerQuantity = Integer.parseInt(acceptBestOfferIDs.get(bestOfferIdIndex).toString());
String[] bestOfferID = { bestOfferIdIndex };
respondAcceptBestOfferCall.setBestOfferIDs(bestOfferID);
//respondAcceptBestOfferCall.setBestOfferIDs(bestOfferID);
if (offerQuantity <= quantityAvailable) {
respondAcceptBestOfferCall.setBestOfferAction(BestOfferActionCodeType.ACCEPT);
quantityAvailable = quantityAvailable - offerQuantity;
} else {
respondAcceptBestOfferCall.setBestOfferAction(BestOfferActionCodeType.DECLINE);
}
respondAcceptBestOfferCall.respondToBestOffer();
}
}
}
}
}