Subversion Repositories SmartDukaan

Rev

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

Rev 4046 Rev 4217
Line 39... Line 39...
39
public class CartController extends BaseController implements ParameterAware{
39
public class CartController extends BaseController implements ParameterAware{
40
	
40
	
41
	private static final long serialVersionUID = 1L;
41
	private static final long serialVersionUID = 1L;
42
	private static Logger log = Logger.getLogger(Class.class);
42
	private static Logger log = Logger.getLogger(Class.class);
43
	Map<String, String[]> reqparams = null;
43
	Map<String, String[]> reqparams = null;
44
 
44
	
45
	private int variationId = 0;
45
	private int variationId = 0;
46
    private String totalamount;
46
    private String totalamount;
47
	
47
	
48
	private String errorMsg = "";
48
	private String errorMsg = "";
49
	private String cartMsg = "";
49
	private String cartMsg = "";
Line 147... Line 147...
147
                Long.toString(cartId), itemIds);
147
                Long.toString(cartId), itemIds);
148
		return "success";
148
		return "success";
149
	}		
149
	}		
150
 
150
 
151
 
151
 
152
		// DELETE /entity
152
	// DELETE /entity
153
		public String destroy() {
153
	public String destroy()	{
154
	    	log.info("CartController.destroy");
154
		log.info("CartController.destroy");
155
	    	printParams();
155
		printParams();
156
	    	log.info("item id is " + this.request.getParameter("productid"));
156
		log.info("item id is " + this.request.getParameter("productid"));
-
 
157
		
157
			String itemIdString = this.request.getParameter("productid");
158
		String itemIdString = this.request.getParameter("productid");
158
			itemId = Long.parseLong(itemIdString);
159
		itemId = Long.parseLong(itemIdString);
-
 
160
 
159
			if(userinfo.getCartId() == -1){
161
		if(userinfo.getCartId() == -1)	{
160
				log.info("Cart does not exist. Nothing to delete.");
162
			log.info("Cart does not exist. Nothing to delete.");
161
			}else{
163
		} else	{
162
				if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId()))
164
			if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId()))	{
163
				{
-
 
164
					updateUserSessionInfo(userinfo.getCartId());
165
				updateUserSessionInfo(userinfo.getCartId());
165
                DataLogger.logData(EventType.DELETE_FROM_CART, getSessionId(),
166
				DataLogger.logData(EventType.DELETE_FROM_CART, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
166
                        userinfo.getUserId(), userinfo.getEmail(),
-
 
167
                        Long.toString(userinfo.getCartId()), itemIdString);
167
                        Long.toString(userinfo.getCartId()), itemIdString);
168
					return "redirect";	
168
				return "redirect";
169
				}
-
 
170
			}
169
			}
171
			return "redirect";
-
 
172
		}
170
		}
-
 
171
		return "redirect";
173
		
172
	}
174
		
173
 
175
		// DELETE /entity
174
	// DELETE /entity
176
		public String update() {
175
	public String update() {
177
	    	log.info("CartController.update");
176
		log.info("CartController.update");
178
	    	printParams();
177
		printParams();
179
	    	log.info("item id is " + this.request.getParameter("productid"));
178
		log.info("item id is " + this.request.getParameter("productid"));
180
	    	log.info("item id is " + this.request.getParameter("quantity"));
179
		log.info("item quantity is " + this.request.getParameter("quantity"));
181
			String itemIdString = this.request.getParameter("productid");
180
		String itemIdString = this.request.getParameter("productid");
182
			String quantityString = this.request.getParameter("quantity");
181
		String quantityString = this.request.getParameter("quantity");
183
			long itemId = Long.parseLong(itemIdString);
182
		long itemId = Long.parseLong(itemIdString);
184
			long quantity = Long.parseLong(quantityString);
183
		long quantity = Long.parseLong(quantityString);
-
 
184
 
185
			if(quantity <= 0){
185
		if(quantity <= 0)	{
186
				log.info("Not valid item quantity. Unable to change item quantity.");
186
			log.info("Not valid item quantity. Unable to change item quantity.");
187
			}else{
187
		} else	{
188
				if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity)){
188
			if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity))	{
189
                DataLogger.logData(EventType.UPDATE_CART_QUANTITY, getSessionId(),
189
				DataLogger.logData(EventType.UPDATE_CART_QUANTITY, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
190
                        userinfo.getUserId(), userinfo.getEmail(),
-
 
191
                        Long.toString(userinfo.getCartId()),
-
 
192
                        Long.toString(itemId), Long.toString(quantity));
190
                        Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
193
					return "redirect";	
191
				return "redirect";
194
				}
-
 
195
			}
192
			}
196
			DataLogger.logData(EventType.UPDATE_CART_QUANTITY_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
-
 
197
                    Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
-
 
198
			addActionError("Unable to update the quantity");
-
 
199
			return "redirect";
-
 
200
		}
193
		}
-
 
194
		DataLogger.logData(EventType.UPDATE_CART_QUANTITY_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
-
 
195
                    Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
-
 
196
		addActionError("Unable to update the quantity");
-
 
197
		return "redirect";
-
 
198
	}
201
	
199
	
202
    public void printParams(){
200
    public void printParams(){
203
    	for(String param : reqparams.keySet()) {
201
    	for(String param : reqparams.keySet()) {
204
    		log.info("param name is " + param);
202
    		log.info("param name is " + param);
205
    		log.info("param first is " + reqparams.get(param)[0]);
203
    		log.info("param first is " + reqparams.get(param)[0]);
Line 226... Line 224...
226
	
224
	
227
	private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
225
	private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
228
		try {
226
		try {
229
			UserClient userContextServiceClient = new UserClient();
227
			UserClient userContextServiceClient = new UserClient();
230
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
228
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
231
 
229
			
232
			userClient.deleteItemFromCart(cartId, catalogItemId);
230
			userClient.deleteItemFromCart(cartId, catalogItemId);
233
			return true;	
231
			return true;
234
		} catch (ShoppingCartException e) {
232
		} catch (ShoppingCartException e) {
235
		    log.error("Unable to delete item from cart: ", e);
233
		    log.error("Unable to delete item from cart: ", e);
236
		} catch (TException e) {
234
		} catch (TException e) {
237
		    log.error("Unable to delete item from cart: ", e);
235
		    log.error("Unable to delete item from cart: ", e);
238
		} catch (Exception e) {
236
		} catch (Exception e) {
Line 302... Line 300...
302
                    itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity()) + "");
300
                    itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity()) + "");
303
                    itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
301
                    itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
304
                    itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
302
                    itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
305
                    itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice(((item.getSellingPrice() * line.getQuantity()))));
303
                    itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice(((item.getSellingPrice() * line.getQuantity()))));
306
                    itemdetail.put("SHIPPING_TIME", line.getEstimate() + "");
304
                    itemdetail.put("SHIPPING_TIME", line.getEstimate() + "");
-
 
305
					itemdetail.put("BEST_DEAL_TEXT", item.getBestDealText());
307
 
306
 
308
                    items.add(itemdetail);
307
                    items.add(itemdetail);
309
                }
308
                }
310
            }
309
            }
311
            
310