String feedbackEventCode = null;
GenericValue ebayProductStorePref = null;
List<String> list = FastList.newInstance();
try {
ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
ebayProductStorePref = delegator.findByPrimaryKey("EbayProductStorePref", UtilMisc.toMap("productStoreId", productStoreId, "autoPrefEnumId", "EBAY_AUTO_PIT_FB"));
if (UtilValidate.isNotEmpty(ebayProductStorePref) && UtilValidate.isNotEmpty(ebayProductStorePref.getString("autoPrefJobId"))) {
isAutoPositiveFeedback = ebayProductStorePref.getString("enabled");
// if isAutoPositiveFeedback is N that means not start this job run service
if ("Y".equals(isAutoPositiveFeedback) && jobId.equals(ebayProductStorePref.getString("autoPrefJobId"))) {
feedbackEventCode = ebayProductStorePref.getString("condition1");
String storeComments = ebayProductStorePref.getString("condition2");
String comment = null;
if (UtilValidate.isNotEmpty(storeComments)) {
if (storeComments.indexOf("\\[,\\]") != -1) {
String[] strs = storeComments.split("\\[,\\]");
for (String str : strs) {
list.add(str);
}
}
}
// start getting sold item list from ebay follow your site
GetSellingManagerSoldListingsCall sellingManagerSoldListings = new GetSellingManagerSoldListingsCall(apiContext);
List<SellingManagerSoldOrderType> items = FastList.newInstance();
SellingManagerSoldOrderType[] sellingManagerSoldOrders = sellingManagerSoldListings.getSellingManagerSoldListings();
if (UtilValidate.isNotEmpty(sellingManagerSoldOrders)) {
for (SellingManagerSoldOrderType solditem : sellingManagerSoldOrders) {
SellingManagerOrderStatusType orderStatus = solditem.getOrderStatus();
if (orderStatus != null && !orderStatus.isFeedbackSent()) {
SellingManagerPaidStatusCodeType paidStatus = orderStatus.getPaidStatus();
CommentTypeCodeType commentType = orderStatus.getFeedbackReceived();
//Buyer has paid for this item.
if ("PAYMENT_RECEIVED".equals(feedbackEventCode) && SellingManagerPaidStatusCodeType.PAID.equals(paidStatus)) {
items.add(solditem);
}
//Buyer has paid for this item and left me positive feedback.
if ("POSITIVE_FEEDBACK_RECEIVED".equals(feedbackEventCode) && CommentTypeCodeType.POSITIVE.equals(commentType) && SellingManagerPaidStatusCodeType.PAID.equals(paidStatus)) {
items.add(solditem);
}
}
}
GetUserCall getUserCall = new GetUserCall(apiContext);
String commentingUser = getUserCall.getUser().getUserID();
for (SellingManagerSoldOrderType item : items) {
// start leave feedbacks
SellingManagerSoldTransactionType[] soldTrans = item.getSellingManagerSoldTransaction();
if (UtilValidate.isNotEmpty(soldTrans)) {
for (SellingManagerSoldTransactionType soldTran : soldTrans) {
LeaveFeedbackCall leaveFeedbackCall = new LeaveFeedbackCall(apiContext);
FeedbackDetailType detail = new FeedbackDetailType();
// ramdom comments
if (list.size() > 0) {
Collections.shuffle(list, new Random());
comment = list.get(0);
}
detail.setCommentText(comment);
detail.setCommentingUser(commentingUser);
//detail.setCommentingUserScore(value);
detail.setCommentType(CommentTypeCodeType.POSITIVE);
detail.setItemID(soldTran.getItemID());
detail.setItemPrice(soldTran.getItemPrice());
detail.setItemTitle(soldTran.getItemTitle());
leaveFeedbackCall.setFeedbackDetail(detail);
leaveFeedbackCall.setTargetUser(item.getBuyerID());
leaveFeedbackCall.setTransactionID(String.valueOf(soldTran.getTransactionID()));
leaveFeedbackCall.leaveFeedback();
Debug.logInfo("Auto leave feedback with site ".concat(apiContext.getSite().value()).concat("itemId ".concat(soldTran.getItemID())).concat(" comment is ".concat(comment)), module);
}
}
}
}
}