Subversion Repositories SmartDukaan

Rev

Rev 413 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 413 Rev 416
Line 30... Line 30...
30
@Results({
30
@Results({
31
    @Result(name="success", type="redirectAction", 
31
    @Result(name="success", type="redirectAction", 
32
    		params = {"actionName" , "cart"})
32
    		params = {"actionName" , "cart"})
33
})
33
})
34
 
34
 
35
public class CartController extends BaseController implements ParameterAware, ServletRequestAware {
35
public class CartController extends BaseController implements ParameterAware {
36
	
36
	
37
	private static final long serialVersionUID = 1L;
37
	private static final long serialVersionUID = 1L;
38
	
38
	
39
	private Map<String, String[]> reqparams;
39
	private Map<String, String[]> reqparams;
40
	private Map<String, Object> sessions;
40
	private Map<String, Object> sessions;
41
	private String redirectURL;
41
	private String redirectURL;
42
	private static Log log = LogFactory.getLog(CartController.class);
42
	private static Log log = LogFactory.getLog(CartController.class);
43
	private String itemId;
43
	private String itemId;
44
	HttpServletRequest request;
44
	//HttpServletRequest request;
45
	private Map<String,String> htmlSnippets;
45
	private Map<String,String> htmlSnippets;
46
	
46
	
47
	public CartController(){
47
	public CartController(){
48
		
48
		
49
	}
49
	}
Line 59... Line 59...
59
    	log.info( "Cookies map is " + this.getCookiesMap());
59
    	log.info( "Cookies map is " + this.getCookiesMap());
60
    	log.info("CartController.index");
60
    	log.info("CartController.index");
61
    	
61
    	
62
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
62
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
63
 
63
 
-
 
64
    	long userId = 0;
-
 
65
    	boolean isSessionId = true;
-
 
66
		
-
 
67
    	if(this.session.getAttribute("loggedin").toString().equals("true")){
-
 
68
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
69
    		isSessionId = false;
-
 
70
    	}else{
-
 
71
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
72
    		isSessionId = true;
-
 
73
    	}
-
 
74
 
64
		params.put(PageContentKeys.CUSTOMER_ID, "4");
75
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
65
		params.put(PageContentKeys.IS_SESSION_ID, "1");
76
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
66
 
77
 
67
		
78
		
68
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
79
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
69
		
80
		
70
 
81
 
Line 83... Line 94...
83
    	}
94
    	}
84
    	log.info("item id is " + this.reqparams.get("item_id"));
95
    	log.info("item id is " + this.reqparams.get("item_id"));
85
    	itemId = this.reqparams.get("item_id")[0];
96
    	itemId = this.reqparams.get("item_id")[0];
86
    	
97
    	
87
    	addItemToCart(itemId);
98
    	addItemToCart(itemId);
-
 
99
    	long userId = 0;
-
 
100
    	boolean isSessionId = true;
-
 
101
    	if(this.session.getAttribute("loggedin").toString().equals("true")){
-
 
102
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
103
    		isSessionId = false;
-
 
104
    	}else{
-
 
105
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
106
    		isSessionId = true;
-
 
107
    	}
88
    	addItemToCart(Long.parseLong(itemId), 4);
108
    	addItemToCart(Long.parseLong(itemId), userId, isSessionId);
89
    	// Add data to the cart
109
    	// Add data to the cart
90
    	
110
    	
91
		return "success";
111
		return "success";
92
    }
112
    }
93
    
113
    
Line 104... Line 124...
104
    	log.info("Item Id is "  + itemId);
124
    	log.info("Item Id is "  + itemId);
105
    	return true;
125
    	return true;
106
    }
126
    }
107
    
127
    
108
    
128
    
109
	private	void addItemToCart(long catalogItemId, long userId){
129
	private	void addItemToCart(long catalogItemId, long userId, boolean isSessionId){
110
		UserContextServiceClient userContextServiceClient = null;
130
		UserContextServiceClient userContextServiceClient = null;
111
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
131
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
112
 
132
 
113
		ShoppingCartClient shoppingCartClient = null;
133
		ShoppingCartClient shoppingCartClient = null;
114
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
134
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
Line 118... Line 138...
118
			userContextServiceClient = new UserContextServiceClient();
138
			userContextServiceClient = new UserContextServiceClient();
119
			userClient = userContextServiceClient.getClient();
139
			userClient = userContextServiceClient.getClient();
120
 
140
 
121
			shoppingCartClient = new ShoppingCartClient();
141
			shoppingCartClient = new ShoppingCartClient();
122
			cartClient = shoppingCartClient.getClient();
142
			cartClient = shoppingCartClient.getClient();
-
 
143
			
123
			cartId = cartClient.createCart(userId, false);
144
			cartId = cartClient.createCart(userId, isSessionId);
124
			cartClient.addItemToCart(cartId, catalogItemId, 1);
145
			cartClient.addItemToCart(cartId, catalogItemId, 1);
125
		} catch (ShoppingCartException e) {
146
		} catch (ShoppingCartException e) {
126
			// TODO Auto-generated catch block
147
			// TODO Auto-generated catch block
127
			e.printStackTrace();
148
			e.printStackTrace();
128
		} catch (TException e) {
149
		} catch (TException e) {
Line 146... Line 167...
146
	public void setParameters(Map<String, String[]> reqmap) {
167
	public void setParameters(Map<String, String[]> reqmap) {
147
		log.info("setParameters:" + reqmap);
168
		log.info("setParameters:" + reqmap);
148
		
169
		
149
		this.reqparams = reqmap;
170
		this.reqparams = reqmap;
150
	}
171
	}
151
	
172
//	
152
	@Override
173
//	@Override
153
	public void setServletRequest(HttpServletRequest request) {
174
//	public void setServletRequest(HttpServletRequest request) {
154
		this.request = request;
175
//		this.request = request;
155
	}
176
//	}
156
    
177
//    
157
}
178
}