Subversion Repositories SmartDukaan

Rev

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

Rev 9713 Rev 9808
Line 55... Line 55...
55
    
55
    
56
    public CartController(){
56
    public CartController(){
57
        super();
57
        super();
58
    }
58
    }
59
    
59
    
60
    public String index()  {
60
    public String index() {
61
        if(id != -1){
61
        if(id != -1){
62
            try {
62
            try {
63
                UserContextService.Client userClient = (new UserClient()).getClient();
63
                UserContextService.Client userClient = (new UserClient()).getClient();
64
                List<String> cartResponse  = userClient.validateCart(id, -1);
64
                List<String> cartResponse  = userClient.validateCart(id, -1);
65
                if (!"".equals(cartResponse.get(0))) {
65
                if (!"".equals(cartResponse.get(0))) {
Line 69... Line 69...
69
                    addActionMessage(cartResponse.get(1));
69
                    addActionMessage(cartResponse.get(1));
70
                }
70
                }
71
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
71
                log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
72
                
72
                
73
                Cart cart = userClient.getCurrentCart(userinfo.getUserId());
73
                Cart cart = userClient.getCurrentCart(userinfo.getUserId());
-
 
74
                String pincode = "110001";
-
 
75
                UserClient usc = new UserClient();
-
 
76
                if(cart.getAddressId() < 1) {
-
 
77
                    try {
-
 
78
                        pincode = usc.getClient().getDefaultPincode(userinfo.getUserId());
-
 
79
                    } catch(Exception e) {
-
 
80
                        log.error("Unable to get default pincode for userId : " + userinfo.getUserId(), e);
-
 
81
                    }
-
 
82
                } else {
-
 
83
                    try {
-
 
84
                        pincode = usc.getClient().getAddressById(cart.getAddressId()).getPin();
-
 
85
                    } catch(Exception e) {
-
 
86
                        log.error("Unable to get address for addressId : " + cart.getAddressId(), e);
-
 
87
                    }   
-
 
88
                }
-
 
89
                
74
                cartPojoJson = new Gson().toJson(PojoPopulator.getCartPojo(cart, errorMsg));
90
                cartPojoJson = new Gson().toJson(PojoPopulator.getCartPojo(cart, errorMsg, pincode));
75
                
91
                
76
            } catch (Exception e) {
92
            } catch (Exception e) {
77
                // This exception can be ignored for showing the cart. Not so
93
                // This exception can be ignored for showing the cart. Not so
78
                // innocent when this occurs at the time of checkout or when the
94
                // innocent when this occurs at the time of checkout or when the
79
                // user is proceeding to pay.
95
                // user is proceeding to pay.
Line 210... Line 226...
210
            log.error("Unable to apply or remove coupon", e);
226
            log.error("Unable to apply or remove coupon", e);
211
            errorMsg = "Unable to apply or remove coupon";
227
            errorMsg = "Unable to apply or remove coupon";
212
        }
228
        }
213
        return index();
229
        return index();
214
    }
230
    }
-
 
231
    
-
 
232
    public String changeAddress() {
-
 
233
        long addressId;
-
 
234
        if(request.getParameter("addressId") == null || request.getParameter("addressId").isEmpty()) {
-
 
235
            errorMsg = "Null or empty addressId";
-
 
236
            return index();
-
 
237
        } else {
-
 
238
            addressId = Long.parseLong(request.getParameter("addressType"));
-
 
239
        }
-
 
240
         
-
 
241
        try {
-
 
242
            UserClient usc = new UserClient();
-
 
243
            if(request.getParameter("addressType").equals("store")) {
-
 
244
                usc.getClient().addStoreToCart(id, addressId);
-
 
245
            } else if (request.getParameter("addressType").equals("home")){
-
 
246
                usc.getClient().addAddressToCart(id, addressId);
-
 
247
            } else {
-
 
248
                errorMsg = "Invalid addressType. It can only be set to home or store.";
-
 
249
            }
-
 
250
        } catch(Exception e) {
-
 
251
            log.error("Unable to change address", e);
-
 
252
        }
-
 
253
        return index();
-
 
254
    }
215
 
255
 
216
    public long getItemId(){
256
    public long getItemId(){
217
        return this.itemId;
257
        return this.itemId;
218
    }
258
    }
219
    
259