Subversion Repositories SmartDukaan

Rev

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

Rev 572 Rev 637
Line 66... Line 66...
66
		long userId = userinfo.getUserId();
66
		long userId = userinfo.getUserId();
67
		long cartId = userinfo.getCartId();
67
		long cartId = userinfo.getCartId();
68
 
68
 
69
		log.info("item id is " + this.reqparams.get("productid"));
69
		log.info("item id is " + this.reqparams.get("productid"));
70
 
70
 
71
		String itemIds = "1000008_1000005";
71
		String itemIds = "";
72
		if (this.reqparams.get("productid") != null) {
72
		if (this.reqparams.get("productid") != null) {
73
			itemIds = this.reqparams.get("productid")[0];
73
			itemIds = this.reqparams.get("productid")[0];
-
 
74
		}else{
-
 
75
			return "failure";
74
		}
76
		}
-
 
77
		
75
 
78
 
76
		StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
79
		StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
77
		while (tokenizer.hasMoreTokens()) {
80
		while (tokenizer.hasMoreTokens()) {
78
			long itemId = Long.parseLong(tokenizer.nextToken());
81
			long itemId = Long.parseLong(tokenizer.nextToken());
79
 
82
 
Line 198... Line 201...
198
	
201
	
199
	public long getNumberOfItems(){
202
	public long getNumberOfItems(){
200
		return userinfo.getTotalItems();
203
		return userinfo.getTotalItems();
201
	}
204
	}
202
}
205
}
203
/*
-
 
204
	 // GET /cart
-
 
205
	 public HttpHeaders index() {
-
 
206
    	 changed on 18 august
-
 
207
    	Cookie loginCookie = new Cookie("userId", "Rajveer");
-
 
208
    	Map cookiesMap = new HashMap();
-
 
209
    	cookiesMap.put("USER_ID", loginCookie);
-
 
210
    	setCookiesMap(cookiesMap);
-
 
211
    	
-
 
212
    	log.info( "Cookies map is " + this.getCookiesMap());
-
 
213
    	log.info("CartController.index");
-
 
214
    	
-
 
215
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
-
 
216
 
-
 
217
    	long userId = 0;
-
 
218
    	boolean isSessionId = true;
-
 
219
    	//if(this.session.getAttribute("loggedin")!=null){
-
 
220
	    	if(this.session.getAttribute("loggedin").toString().equals("true")){
-
 
221
	    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
222
	    		isSessionId = false;
-
 
223
	    	}else{
-
 
224
	    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
225
	    		isSessionId = true;
-
 
226
	    	}
-
 
227
//    	}else{
-
 
228
//    		System.out.println("No User is logged in. Redirect to login page.");
-
 
229
//    		return new DefaultHttpHeaders("fatal");
-
 
230
//
-
 
231
//    	}
-
 
232
    	
-
 
233
    	
-
 
234
    	
-
 
235
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
-
 
236
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
-
 
237
 
-
 
238
 
-
 
239
    	long userId = 0;
-
 
240
    	boolean isSessionId = true;
-
 
241
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
-
 
242
		
-
 
243
		if(userinfo.isLoggedIn()){
-
 
244
			userId = userinfo.getUserId();
-
 
245
			isSessionId = false;
-
 
246
		}
-
 
247
		else{
-
 
248
			userId = userinfo.getSessionId();
-
 
249
			isSessionId = true;
-
 
250
		}
-
 
251
		
-
 
252
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
-
 
253
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
-
 
254
 
-
 
255
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
-
 
256
		
-
 
257
 
-
 
258
    	
-
 
259
    	return new DefaultHttpHeaders("index").disableCaching();
-
 
260
    }
-
 
261
*/    
-
 
262
    // POST /entity
-
 
263
    /*
-
 
264
    public String create() {
-
 
265
    	
-
 
266
    	log.info("CartController.create");
-
 
267
    	printParams();
-
 
268
    	if(getCookiesMap() != null){
-
 
269
    		Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");
-
 
270
    		log.info("login cookie name is " + loginCookie.getName() );
-
 
271
    		log.info("login cookie value is " + loginCookie.getValue());
-
 
272
    	}
-
 
273
    	log.info("item id is " + this.reqparams.get("item_id"));
-
 
274
    	itemId = this.reqparams.get("item_id")[0];
-
 
275
    	
-
 
276
    	addItemToCart(itemId);
-
 
277
    	long userId = 0;
-
 
278
    	boolean isSessionId = true;
-
 
279
    	if(this.session.getAttribute("loggedin").toString().equals("true")){
-
 
280
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
281
    		isSessionId = false;
-
 
282
    	}else{
-
 
283
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
-
 
284
    		isSessionId = true;
-
 
285
    	}
-
 
286
    	addItemToCart(Long.parseLong(itemId), userId, isSessionId);
-
 
287
    	// Add data to the cart
-
 
288
    	
-
 
289
    	long userId = 0;
-
 
290
    	boolean isSessionId = true;
-
 
291
    	
-
 
292
    	log.info("item id is " + this.reqparams.get("productid"));
-
 
293
    	
-
 
294
    	String itemIds = "1000008_1000005"; 
-
 
295
    	if(this.reqparams.get("productid") != null){
-
 
296
    		itemIds = this.reqparams.get("productid")[0];
-
 
297
    	}
-
 
298
    	
-
 
299
 	
-
 
300
//    	log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
301
//		String itemIds = this.request.getParameter("productid");
-
 
302
		
-
 
303
		if(userinfo.isLoggedIn()){
-
 
304
			userId = userinfo.getUserId();
-
 
305
			isSessionId = false;
-
 
306
		}
-
 
307
		else{
-
 
308
			userId = userinfo.getSessionId();
-
 
309
			isSessionId = true;
-
 
310
		}
-
 
311
		long cartId = 0;
-
 
312
	
-
 
313
		StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
-
 
314
		int numberOfItems = tokenizer.countTokens();
-
 
315
		while(tokenizer.hasMoreTokens()){
-
 
316
			long itemId = Long.parseLong(tokenizer.nextToken());
-
 
317
			cartId = Utils.addItemToCart(itemId, userId, isSessionId);
-
 
318
		}
-
 
319
 
-
 
320
    	//long cartId = Utils.addItemToCart(Long.parseLong(itemId), userId, isSessionId);
-
 
321
    	
-
 
322
    	userinfo.setCartId(cartId);
-
 
323
    	userinfo.setTotalItems(Utils.getNumberOfItemsInCart(cartId) );
-
 
324
    	
-
 
325
    	this.session.setAttribute("userinfo", userinfo);
-
 
326
    	
-
 
327
		return "success";
-
 
328
    }
-
 
329
    
-
 
330
    
-
 
331
    public void printParams(){
-
 
332
    	for(String param : reqparams.keySet()) {
-
 
333
    		log.info("param name is " + param);
-
 
334
    		log.info("param first is " + reqparams.get(param)[0]);
-
 
335
    	}
-
 
336
    	log.info(this.reqparams);
-
 
337
    }
-
 
338
    
-
 
339
    private boolean addItemToCart(String itemId){
-
 
340
    	log.info("Session Id is "  + request.getSession().getId());
-
 
341
    	log.info("Item Id is "  + itemId);
-
 
342
    	return true;
-
 
343
    }
-
 
344
    
-
 
345
    
-
 
346
	private	void addItemToCart(long catalogItemId, long userId, boolean isSessionId){
-
 
347
		UserContextServiceClient userContextServiceClient = null;
-
 
348
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
349
 
-
 
350
		ShoppingCartClient shoppingCartClient = null;
-
 
351
		in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
-
 
352
		long cartId = -1;
-
 
353
		
-
 
354
		try {
-
 
355
			userContextServiceClient = new UserContextServiceClient();
-
 
356
			userClient = userContextServiceClient.getClient();
-
 
357
 
-
 
358
			shoppingCartClient = new ShoppingCartClient();
-
 
359
			cartClient = shoppingCartClient.getClient();
-
 
360
			
-
 
361
			cartId = cartClient.createCart(userId, isSessionId);
-
 
362
			cartClient.addItemToCart(cartId, catalogItemId, 1);
-
 
363
			
-
 
364
			int NumberOfLines = cartClient.getShadowCart(cartId).getLinesSize();
-
 
365
			this.session.setAttribute("totalitems", NumberOfLines+"");
-
 
366
 
-
 
367
			
-
 
368
		} catch (ShoppingCartException e) {
-
 
369
			e.printStackTrace();
-
 
370
		} catch (TException e) {
-
 
371
			e.printStackTrace();
-
 
372
		} catch (Exception e) {
-
 
373
			e.printStackTrace();
-
 
374
		}
-
 
375
		
-
 
376
		//if user is logged in create  new cart
-
 
377
		//if( userClient.getState(userId, false).isIsLoggedIn()){
-
 
378
	}
-
 
379
	
-
 
380
	public long getNumberOfItems(){
-
 
381
		return userinfo.getTotalItems();
-
 
382
	}
-
 
383
	
-
 
384
	public String getShoppingCartSnippets()
-
 
385
	{
-
 
386
		return htmlSnippets.get("SHOPPING_CART");
-
 
387
	}
-
 
388
	
-
 
389
	@Override
-
 
390
	public void setParameters(Map<String, String[]> reqmap) {
-
 
391
		log.info("setParameters:" + reqmap);
-
 
392
		
-
 
393
		this.reqparams = reqmap;
-
 
394
	}
-
 
395
	*/
-
 
396
//	
-
 
397
//	@Override
-
 
398
//	public void setServletRequest(HttpServletRequest request) {
-
 
399
//		this.request = request;
-
 
400
//	}
-
 
401
//    
-
 
402
 
-