Subversion Repositories SmartDukaan

Rev

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

Rev 650 Rev 762
Line 69... Line 69...
69
			long itemId = Long.parseLong(tokenizer.nextToken());
69
			long itemId = Long.parseLong(tokenizer.nextToken());
70
 
70
 
71
			try {
71
			try {
72
				UserContextServiceClient userServiceClient = new UserContextServiceClient();
72
				UserContextServiceClient userServiceClient = new UserContextServiceClient();
73
				UserContextService.Client userClient = userServiceClient.getClient();
73
				UserContextService.Client userClient = userServiceClient.getClient();
74
				if (cartId == 0)
74
				if (cartId == 0){
75
					cartId = userClient.createCart(userId);
75
					cartId = userClient.createCart(userId);
-
 
76
				}
76
				userClient.addItemToCart(cartId, itemId, 1);
77
				userClient.addItemToCart(cartId, itemId, 1);
77
 
-
 
78
			} catch (ShoppingCartException e) {
78
				userinfo.setCartId(cartId);
-
 
79
				int totalItems = userClient.getCart(cartId).getLinesSize();
79
				e.printStackTrace();
80
				userinfo.setTotalItems(totalItems);
80
			} catch (TException e) {
81
			} catch (TException e) {
81
				e.printStackTrace();
82
				e.printStackTrace();
82
			} catch (Exception e) {
83
			} catch (Exception e) {
83
				e.printStackTrace();
84
				e.printStackTrace();
84
			}
85
			}
85
 
86
 
86
		}
87
		}
87
 
88
 
88
		userinfo.setCartId(cartId);
-
 
89
		userinfo.setTotalItems(Utils.getNumberOfItemsInCart(cartId));
-
 
90
 
-
 
91
		return "success";
89
		return "success";
92
	}		
90
	}		
93
 
91
 
94
		// DELETE /entity
92
		// DELETE /entity
95
		public String destroy() {
93
		public String destroy() {
Line 99... Line 97...
99
			String itemIdString = this.request.getParameter("productid");
97
			String itemIdString = this.request.getParameter("productid");
100
			long itemId = Long.parseLong(itemIdString);
98
			long itemId = Long.parseLong(itemIdString);
101
			if(userinfo.getCartId() == -1){
99
			if(userinfo.getCartId() == -1){
102
				log.info("Cart does not exist. Nothing to delete.");
100
				log.info("Cart does not exist. Nothing to delete.");
103
			}else{
101
			}else{
104
				if(Utils.deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId())){
102
				if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId())){
105
					userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
103
					userinfo.setTotalItems(getNumberOfItemsInCart(userinfo.getCartId()));
106
					return "delsuccess";	
104
					return "delsuccess";	
107
				}
105
				}
108
			}
106
			}
109
			return "delfailure";
107
			return "delfailure";
110
		}
108
		}
Line 121... Line 119...
121
			long itemId = Long.parseLong(itemIdString);
119
			long itemId = Long.parseLong(itemIdString);
122
			long quantity = Long.parseLong(quantityString);
120
			long quantity = Long.parseLong(quantityString);
123
			if(quantity <= 0){
121
			if(quantity <= 0){
124
				log.info("Not valid item quantity. Unable to change item quantity.");
122
				log.info("Not valid item quantity. Unable to change item quantity.");
125
			}else{
123
			}else{
126
				if(Utils.updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity)){
124
				if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity)){
127
					return "delsuccess";	
125
					return "delsuccess";	
128
				}
126
				}
129
			}
127
			}
130
			return "delfailure";
128
			return "delfailure";
131
		}
129
		}
Line 137... Line 135...
137
    		log.info("param first is " + reqparams.get(param)[0]);
135
    		log.info("param first is " + reqparams.get(param)[0]);
138
    	}
136
    	}
139
    	log.info(this.reqparams);
137
    	log.info(this.reqparams);
140
    }
138
    }
141
 
139
 
-
 
140
	private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
-
 
141
		try {
-
 
142
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
143
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
144
 
-
 
145
			userClient.changeQuantity(cartId, itemId, quantity);
-
 
146
			return true;
-
 
147
		} catch (ShoppingCartException e) {
-
 
148
			e.printStackTrace();
-
 
149
		} catch (TException e) {
-
 
150
			e.printStackTrace();
-
 
151
		} catch (Exception e) {
-
 
152
			e.printStackTrace();
-
 
153
		}
-
 
154
		return false;
-
 
155
	}
-
 
156
	
-
 
157
	private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
-
 
158
		try {
-
 
159
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
160
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
161
 
-
 
162
			userClient.deleteItemFromCart(cartId, catalogItemId);
-
 
163
			return true;	
-
 
164
		} catch (ShoppingCartException e) {
-
 
165
			e.printStackTrace();
-
 
166
		} catch (TException e) {
-
 
167
			e.printStackTrace();
-
 
168
		} catch (Exception e) {
-
 
169
			e.printStackTrace();
-
 
170
		}
-
 
171
		
-
 
172
		return false;
-
 
173
	}
-
 
174
 
-
 
175
 
-
 
176
 
-
 
177
	private int getNumberOfItemsInCart(long cartId) {
-
 
178
		int numberOfItems = 0;
-
 
179
		UserContextServiceClient userContextServiceClient = null;
-
 
180
		try {
-
 
181
			userContextServiceClient = new UserContextServiceClient();
-
 
182
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
183
 
-
 
184
			numberOfItems = userClient.getCart(cartId).getLinesSize();
-
 
185
		} catch (ShoppingCartException e) {
-
 
186
			e.printStackTrace();
-
 
187
		} catch (TException e) {
-
 
188
			e.printStackTrace();
-
 
189
		} catch (Exception e) {
-
 
190
			e.printStackTrace();
-
 
191
		}
-
 
192
		return numberOfItems;
-
 
193
	}
-
 
194
 
-
 
195
 
142
	public String getCartHeaderSnippet(){
196
	public String getCartHeaderSnippet(){
143
		return htmlSnippets.get("CART_HEADER");
197
		return htmlSnippets.get("CART_HEADER");
144
	}
198
	}
145
	
199
	
146
	public String getCartDetailsSnippet(){
200
	public String getCartDetailsSnippet(){