Subversion Repositories SmartDukaan

Rev

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

Rev 11768 Rev 11823
Line 7... Line 7...
7
import in.shop2020.mobileapi.serving.utils.SnippetType;
7
import in.shop2020.mobileapi.serving.utils.SnippetType;
8
import in.shop2020.model.v1.catalog.CatalogService.Client;
8
import in.shop2020.model.v1.catalog.CatalogService.Client;
9
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.Item;
10
import in.shop2020.model.v1.user.Cart;
10
import in.shop2020.model.v1.user.Cart;
11
import in.shop2020.model.v1.user.CartPlus;
11
import in.shop2020.model.v1.user.CartPlus;
12
import in.shop2020.model.v1.user.Line;
-
 
13
import in.shop2020.model.v1.user.PromotionException;
12
import in.shop2020.model.v1.user.PromotionException;
14
import in.shop2020.model.v1.user.PromotionService;
13
import in.shop2020.model.v1.user.PromotionService;
15
import in.shop2020.model.v1.user.ShoppingCartException;
14
import in.shop2020.model.v1.user.ShoppingCartException;
16
import in.shop2020.model.v1.user.UserContextService;
15
import in.shop2020.model.v1.user.UserContextService;
17
import in.shop2020.thrift.clients.CatalogClient;
16
import in.shop2020.thrift.clients.CatalogClient;
Line 19... Line 18...
19
import in.shop2020.thrift.clients.UserClient;
18
import in.shop2020.thrift.clients.UserClient;
20
 
19
 
21
import java.util.List;
20
import java.util.List;
22
import java.util.Map;
21
import java.util.Map;
23
 
22
 
24
import org.apache.commons.lang.StringUtils;
-
 
25
import org.apache.log4j.Logger;
23
import org.apache.log4j.Logger;
26
import org.apache.struts2.interceptor.ParameterAware;
24
import org.apache.struts2.interceptor.ParameterAware;
27
import org.apache.thrift.TException;
25
import org.apache.thrift.TException;
28
import org.apache.thrift.transport.TTransportException;
-
 
29
 
26
 
30
import com.google.gson.Gson;
27
import com.google.gson.Gson;
31
 
28
 
32
public class CartController extends BaseController implements ParameterAware{
29
public class CartController extends BaseController implements ParameterAware{
33
    
30
    
Line 71... Line 68...
71
        if(id != -1){
68
        if(id != -1){
72
            try {
69
            try {
73
            	log.info("Before cart response--------");
70
            	log.info("Before cart response--------");
74
                CartPlus cartResponse  = getClient().validateCartPlus(id, -1);
71
                CartPlus cartResponse  = getClient().validateCartPlus(id, -1);
75
                log.info("After cart response--------");
72
                log.info("After cart response--------");
-
 
73
                if (errorMsg == null || errorMsg.equals("")) {
-
 
74
                	errorMsg = cartResponse.getValidateCartMessages().get(0);
-
 
75
                }
76
                cartPojoJson = new Gson().toJson(PojoPopulator.getCartPojo(cartResponse.getCart(), cartResponse.getValidateCartMessages().get(0), 
76
                cartPojoJson = new Gson().toJson(PojoPopulator.getCartPojo(cartResponse.getCart(), errorMsg, 
77
                		cartResponse.getPinCode(), cartResponse.isNeedInsuranceInfo()));
77
                		cartResponse.getPinCode(), cartResponse.isNeedInsuranceInfo()));
78
                log.info(cartPojoJson);
78
                log.info(cartPojoJson);
79
            } catch (Exception e) {
79
            } catch (Exception e) {
80
                /*TTransportException te = (TTransportException)e;
80
                /*TTransportException te = (TTransportException)e;
81
                log.warn(e.getLocalizedMessage() + " " + te.getType());*/
81
                log.warn(e.getLocalizedMessage() + " " + te.getType());*/
Line 213... Line 213...
213
                
213
                
214
                promotionServiceClient = new PromotionClient();
214
                promotionServiceClient = new PromotionClient();
215
                PromotionService.Client promotionClient = promotionServiceClient.getClient();
215
                PromotionService.Client promotionClient = promotionServiceClient.getClient();
216
                
216
                
217
                Cart cart = promotionClient.applyCoupon(couponCode, id);
217
                Cart cart = promotionClient.applyCoupon(couponCode, id);
218
                if (!(cart.getCouponCode() == null || cart.getCouponCode().equals(""))) {
-
 
219
                	errorMsg = "Coupon successfully applied";
218
            	errorMsg = "Coupon successfully applied";
220
                	for(Line l : cart.getLines()){
-
 
221
                		if (!(l.getDealText() == null || l.getDealText().equals(""))) {
219
            	if(cart.getMessage() != null && cart.getMessage().equals("")){
222
                			errorMsg += ", Your deal has been changed";
220
                	errorMsg = errorMsg +  ", " + cart.getMessage();
223
                		}
-
 
224
                	}
-
 
225
                }
221
                }
226
                
-
 
227
            }
222
            }
228
            else if (action.equals("removecoupon"))    {
223
            else if (action.equals("removecoupon"))    {
229
                getClient().removeCoupon(id);
224
                getClient().removeCoupon(id);
230
            }
225
            }
231
        } catch (PromotionException e) {
226
        } catch (PromotionException e) {
232
            log.info("Invalid coupon: " + e.getMessage());
227
            log.info("Invalid coupon: " + e.getMessage());
233
            errorMsg = "Invalid coupon : " + e.getMessage();
228
            errorMsg = e.getMessage();
234
        } catch (Exception e) {
229
        } catch (Exception e) {
235
            log.error("Unable to apply or remove coupon", e);
230
            log.error("Unable to apply or remove coupon", e);
236
            errorMsg = "Unable to apply or remove coupon";
231
            errorMsg = "Unable to apply or remove coupon";
237
        }
232
        }
238
        return index();
233
        return index();