| Line 20... |
Line 20... |
| 20 |
import in.shop2020.thrift.clients.CatalogClient;
|
20 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 21 |
import in.shop2020.thrift.clients.PromotionClient;
|
21 |
import in.shop2020.thrift.clients.PromotionClient;
|
| 22 |
import in.shop2020.thrift.clients.UserClient;
|
22 |
import in.shop2020.thrift.clients.UserClient;
|
| 23 |
|
23 |
|
| 24 |
import java.util.ArrayList;
|
24 |
import java.util.ArrayList;
|
| - |
|
25 |
import java.util.Arrays;
|
| 25 |
import java.util.List;
|
26 |
import java.util.List;
|
| 26 |
import java.util.Map;
|
27 |
import java.util.Map;
|
| 27 |
|
28 |
|
| 28 |
import org.apache.commons.lang.StringUtils;
|
29 |
import org.apache.commons.lang.StringUtils;
|
| 29 |
import org.apache.log4j.Logger;
|
30 |
import org.apache.log4j.Logger;
|
| Line 437... |
Line 438... |
| 437 |
else {
|
438 |
else {
|
| 438 |
try{
|
439 |
try{
|
| 439 |
List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
|
440 |
List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
|
| 440 |
JSONObject jsonObj = new JSONObject(cartMap);
|
441 |
JSONObject jsonObj = new JSONObject(cartMap);
|
| 441 |
JSONArray cartItems = jsonObj.getJSONArray("cartItems");
|
442 |
JSONArray cartItems = jsonObj.getJSONArray("cartItems");
|
| - |
|
443 |
List<Integer> itemsList = new ArrayList<Integer>();
|
| 442 |
if (cartItems==null || cartItems.length()==0){
|
444 |
if (cartItems==null || cartItems.length()==0){
|
| 443 |
cartPojoJson = "{\"response\":\"error\", \"message\":\"Empty Cart.\"}";
|
445 |
cartPojoJson = "{\"response\":\"error\", \"message\":\"Empty Cart.\"}";
|
| 444 |
} else {
|
446 |
} else {
|
| 445 |
for (int i=0; i< cartItems.length(); i++) {
|
447 |
for (int i=0; i< cartItems.length(); i++) {
|
| 446 |
JSONObject obj = cartItems.getJSONObject(i);
|
448 |
JSONObject obj = cartItems.getJSONObject(i);
|
| 447 |
int itemId = obj.getInt("itemId");
|
449 |
int itemId = obj.getInt("itemId");
|
| 448 |
Integer quantity = obj.getInt("quantity");
|
450 |
Integer quantity = obj.getInt("quantity");
|
| 449 |
ItemQuantity iq = new ItemQuantity(itemId, quantity);
|
451 |
ItemQuantity iq = new ItemQuantity(itemId, quantity);
|
| 450 |
itemQuantities.add(iq);
|
452 |
itemQuantities.add(iq);
|
| - |
|
453 |
itemsList.add(itemId);
|
| 451 |
}
|
454 |
}
|
| 452 |
userClient = getClient();
|
455 |
userClient = getClient();
|
| 453 |
|
456 |
|
| 454 |
if (userClient.addItemsToCart(id, itemQuantities, jsonObj.has("couponCode")? jsonObj.getString("couponCode"):null)){
|
457 |
if (userClient.addItemsToCart(id, itemQuantities, jsonObj.has("couponCode")? jsonObj.getString("couponCode"):null)){
|
| 455 |
log.info("Items added to cart Successfully");
|
458 |
log.info("Items added to cart Successfully");
|
| Line 457... |
Line 460... |
| 457 |
String cartString = userClient.validateCartNew(id, userinfo.getPincode(), -1);
|
460 |
String cartString = userClient.validateCartNew(id, userinfo.getPincode(), -1);
|
| 458 |
JSONObject cartObj = new JSONObject(cartString);
|
461 |
JSONObject cartObj = new JSONObject(cartString);
|
| 459 |
JSONArray arr = cartObj.getJSONArray("cartItems");
|
462 |
JSONArray arr = cartObj.getJSONArray("cartItems");
|
| 460 |
int maxEstimate=0;
|
463 |
int maxEstimate=0;
|
| 461 |
boolean allSame=true;
|
464 |
boolean allSame=true;
|
| - |
|
465 |
int cartMessagesMerged = 0;
|
| 462 |
for (int j=0; j<arr.length(); j++){
|
466 |
for (int j=0; j<arr.length(); j++){
|
| 463 |
JSONObject itemObj = arr.getJSONObject(j);
|
467 |
JSONObject itemObj = arr.getJSONObject(j);
|
| - |
|
468 |
if(itemsList.contains(itemObj.getInt("itemId")) && itemObj.getInt("quantity")==0){
|
| - |
|
469 |
arr.remove(j);
|
| - |
|
470 |
if (itemObj.getInt("estimate")==-1){
|
| - |
|
471 |
cartObj.put("cartMessageUndeliverable", cartObj.getInt("cartMessageUndeliverable") - 1);
|
| - |
|
472 |
} else {
|
| - |
|
473 |
cartObj.put("cartMessageOOS", cartObj.getInt("cartMessageOOS") - 1);
|
| - |
|
474 |
}
|
| - |
|
475 |
continue;
|
| - |
|
476 |
} else {
|
| - |
|
477 |
JSONArray messagesArray = new JSONArray();
|
| - |
|
478 |
JSONObject message=new JSONObject();
|
| - |
|
479 |
message.put("type","info");
|
| - |
|
480 |
message.put("messageText","Merged from earlier cart");
|
| - |
|
481 |
messagesArray.put(message);
|
| - |
|
482 |
itemObj.put("cartItemMessages", messagesArray);
|
| - |
|
483 |
cartObj.put("cartMessagesMerged", cartMessagesMerged + 1);
|
| - |
|
484 |
|
| - |
|
485 |
}
|
| 464 |
ProductPojo pp = PojoPopulator.getShortContent(itemObj.getLong("catalogItemId"));
|
486 |
ProductPojo pp = PojoPopulator.getShortContent(itemObj.getLong("catalogItemId"));
|
| 465 |
if(allSame){
|
487 |
if(allSame){
|
| 466 |
allSame = maxEstimate==0 || maxEstimate==itemObj.getInt("estimate");
|
488 |
allSame = maxEstimate==0 || maxEstimate==itemObj.getInt("estimate");
|
| 467 |
}
|
489 |
}
|
| 468 |
if(itemObj.getInt("estimate")>maxEstimate){
|
490 |
if(itemObj.getInt("estimate")>maxEstimate){
|
| 469 |
maxEstimate = itemObj.getInt("estimate");
|
491 |
maxEstimate = itemObj.getInt("estimate");
|
| 470 |
}
|
492 |
}
|
| 471 |
itemObj.put("imageUrl", pp.getImageUrl());
|
493 |
itemObj.put("imageUrl", pp.getImageUrl());
|
| 472 |
itemObj.put("title", pp.getTitle());
|
494 |
itemObj.put("title", pp.getTitle());
|
| 473 |
}
|
495 |
}
|
| - |
|
496 |
JSONArray cartMessagesArray = new JSONArray();
|
| - |
|
497 |
for (String message :Arrays.asList("cartMessageOOS", "cartMessageUndeliverable", "cartMessageChanged","cartMessagesMerged")){
|
| - |
|
498 |
int count = cartObj.getInt(message);
|
| - |
|
499 |
if (count>0) {
|
| - |
|
500 |
String type="failed";
|
| - |
|
501 |
if (message.equals("cartMessagesMerged")) type = "info";
|
| - |
|
502 |
JSONObject cartMessage=new JSONObject();
|
| - |
|
503 |
cartMessage.put("type",type);
|
| - |
|
504 |
cartMessage.put("messageText","Merged from earlier cart");
|
| - |
|
505 |
cartMessagesArray.put(cartMessage);
|
| - |
|
506 |
}
|
| - |
|
507 |
}
|
| - |
|
508 |
cartObj.put("cartMessages", cartMessagesArray);
|
| - |
|
509 |
|
| 474 |
if (maxEstimate==-1){
|
510 |
if (maxEstimate==-1){
|
| 475 |
cartObj.put("estimateString", "Can't ship here");
|
511 |
cartObj.put("estimateString", "Can't ship here");
|
| 476 |
} else {
|
512 |
} else {
|
| 477 |
cartObj.put("estimateString", LogisticsService.getDeliveryDateString(maxEstimate,DeliveryType.COD));
|
513 |
cartObj.put("estimateString", LogisticsService.getDeliveryDateString(maxEstimate,DeliveryType.COD));
|
| 478 |
}
|
514 |
}
|