Subversion Repositories SmartDukaan

Rev

Rev 10767 | Rev 11511 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10767 Rev 11386
Line 52... Line 52...
52
    
52
    
53
    private long id; //CartId
53
    private long id; //CartId
54
    private String cartPojoJson;
54
    private String cartPojoJson;
55
    private long quantity;
55
    private long quantity;
56
    private int insuranceType;
56
    private int insuranceType;
-
 
57
    UserContextService.Client userClient;
57
    
58
    
58
    public CartController(){
59
    public CartController() throws Exception{
59
        super();
60
        super();
-
 
61
        userClient = new UserClient().getClient();
60
    }
62
    }
61
    
63
    
62
    public String index() {
64
    public String index() {
63
        if(id != -1){
65
        if(id != -1){
64
            try {
66
            try {
65
                UserContextService.Client userClient = (new UserClient()).getClient();
-
 
66
                List<String> cartResponse  = userClient.validateCart(id, -1);
67
                List<String> cartResponse  = userClient.validateCart(id, -1);
67
                if (!"".equals(cartResponse.get(0))) {
68
                if (!"".equals(cartResponse.get(0))) {
68
                    errorMsg = cartResponse.get(0);
69
                    errorMsg = cartResponse.get(0);
69
                }
70
                }
70
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
71
                if(StringUtils.isNotEmpty(cartResponse.get(1))) {
Line 72... Line 73...
72
                }
73
                }
73
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
74
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
74
                
75
                
75
                Cart cart = userClient.getCurrentCart(userinfo.getUserId());
76
                Cart cart = userClient.getCurrentCart(userinfo.getUserId());
76
                String pincode = "110001";
77
                String pincode = "110001";
77
                UserClient usc = new UserClient();
-
 
78
                if(!cart.isSetAddressId()) {
78
                if(!cart.isSetAddressId()) {
79
                    try {
79
                    try {
80
                        pincode = usc.getClient().getDefaultPincode(userinfo.getUserId());
80
                        pincode = userClient.getDefaultPincode(userinfo.getUserId());
81
                    } catch(Exception e) {
81
                    } catch(Exception e) {
82
                        log.error("Unable to get default pincode for userId : " + userinfo.getUserId(), e);
82
                        log.error("Unable to get default pincode for userId : " + userinfo.getUserId(), e);
83
                    }
83
                    }
84
                } else {
84
                } else {
85
                    try {
85
                    try {
86
                        pincode = usc.getClient().getAddressById(cart.getAddressId()).getPin();
86
                        pincode = userClient.getAddressById(cart.getAddressId()).getPin();
87
                    } catch(Exception e) {
87
                    } catch(Exception e) {
88
                        log.error("Unable to get address for addressId : " + cart.getAddressId(), e);
88
                        log.error("Unable to get address for addressId : " + cart.getAddressId(), e);
89
                    }   
89
                    }   
90
                }
90
                }
91
                Boolean needInuranceInfo = false;
91
                Boolean needInuranceInfo = false;
92
                for(Line line : cart.getLines()) {
92
                for(Line line : cart.getLines()) {
93
                	log.info("Insurer is set: " + String.valueOf(line.getInsurer()>0));
93
                	log.info("Insurer is set: " + String.valueOf(line.getInsurer()>0));
94
                	if(line.getInsurer()>0){
94
                	if(line.getInsurer()>0){
95
                		long defaultAddressId = usc.getClient().getDefaultAddressId(userinfo.getUserId());
95
                		long defaultAddressId = userClient.getDefaultAddressId(userinfo.getUserId());
96
                		log.info(defaultAddressId);
96
                		log.info(defaultAddressId);
97
                		needInuranceInfo = !userClient.isInsuranceDetailPresent(defaultAddressId);
97
                		needInuranceInfo = !userClient.isInsuranceDetailPresent(defaultAddressId);
98
                		log.info("Need insurance: " + needInuranceInfo);
98
                		log.info("Need insurance: " + needInuranceInfo);
99
                		break;
99
                		break;
100
                	}
100
                	}
Line 272... Line 272...
272
        } else {
272
        } else {
273
            addressId = Long.parseLong(request.getParameter("addressId"));
273
            addressId = Long.parseLong(request.getParameter("addressId"));
274
        }
274
        }
275
         
275
         
276
        try {
276
        try {
277
            UserClient usc = new UserClient();
-
 
278
            if(request.getParameter("addressType").equalsIgnoreCase("store")) {
277
            if(request.getParameter("addressType").equalsIgnoreCase("store")) {
279
                usc.getClient().addStoreToCart(id, addressId);
278
                userClient.addStoreToCart(id, addressId);
280
            } else if (request.getParameter("addressType").equalsIgnoreCase("home")){
279
            } else if (request.getParameter("addressType").equalsIgnoreCase("home")){
281
                usc.getClient().addAddressToCart(id, addressId);
280
                userClient.addAddressToCart(id, addressId);
282
            } else {
281
            } else {
283
                errorMsg = "Invalid addressType. It can only be set to home or store.";
282
                errorMsg = "Invalid addressType. It can only be set to home or store.";
284
            }
283
            }
285
        } catch(Exception e) {
284
        } catch(Exception e) {
286
            log.error("Unable to change address", e);
285
            log.error("Unable to change address", e);