Subversion Repositories SmartDukaan

Rev

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

Rev 1957 Rev 1981
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.HashMap;
-
 
5
import java.util.List;
3
import java.util.Map;
6
import java.util.Map;
4
import java.util.StringTokenizer;
7
import java.util.StringTokenizer;
5
 
8
 
-
 
9
import in.shop2020.model.v1.catalog.Item;
-
 
10
import in.shop2020.model.v1.user.Cart;
-
 
11
import in.shop2020.model.v1.user.Line;
6
import in.shop2020.model.v1.user.ShoppingCartException;
12
import in.shop2020.model.v1.user.ShoppingCartException;
7
import in.shop2020.model.v1.user.UserContextService;
13
import in.shop2020.model.v1.user.UserContextService;
8
import in.shop2020.serving.controllers.BaseController;
14
import in.shop2020.serving.controllers.BaseController;
-
 
15
 
-
 
16
import in.shop2020.thrift.clients.CatalogServiceClient;
9
import in.shop2020.serving.utils.DataLogger;
17
import in.shop2020.serving.utils.DataLogger;
10
import in.shop2020.serving.utils.DataLogger.Event;
18
import in.shop2020.serving.utils.DataLogger.Event;
11
import in.shop2020.thrift.clients.UserContextServiceClient;
19
import in.shop2020.thrift.clients.UserContextServiceClient;
12
 
20
 
13
import org.apache.commons.lang.StringUtils;
21
import org.apache.commons.lang.StringUtils;
Line 33... Line 41...
33
	
41
	
34
	private static final long serialVersionUID = 1L;
42
	private static final long serialVersionUID = 1L;
35
	private static Logger log = Logger.getLogger(Class.class);
43
	private static Logger log = Logger.getLogger(Class.class);
36
	private static Logger dataLog = DataLogger.getLogger();
44
	private static Logger dataLog = DataLogger.getLogger();
37
	Map<String, String[]> reqparams = null;
45
	Map<String, String[]> reqparams = null;
38
	
46
 
-
 
47
    private double totalamount = 0.0;
39
	
48
	
40
	private String errorMsg = "";
49
	private String errorMsg = "";
41
	
50
	
-
 
51
	private String pincode = "110001";
-
 
52
	
-
 
53
	private String couponCode = null;
-
 
54
	
-
 
55
	private double discountedAmount;
-
 
56
	
42
	public CartController(){
57
	public CartController(){
43
		super();
58
		super();
44
	}
59
	}
45
	
60
	
46
	 // GET /cart
61
	 // GET /cart
Line 54... Line 69...
54
			// This exception can be ignored for showing the cart. Not so
69
			// This exception can be ignored for showing the cart. Not so
55
			// innocent when this occurs at the time of checkout or when the
70
			// innocent when this occurs at the time of checkout or when the
56
			// user is proceeding to pay.
71
			// user is proceeding to pay.
57
			e.printStackTrace();
72
			e.printStackTrace();
58
		}
73
		}
59
		
-
 
60
		htmlSnippets.put("CART_HEADER", pageLoader.getCartHeaderHtml());
-
 
61
		htmlSnippets.put("CART_DETAILS", pageLoader.getCartDetailsHtml(userinfo.getUserId(), userinfo.getCartId(), errorMsg));
-
 
62
    	return "index";
74
    	return "index";
63
	 }
75
	 }
64
 
-
 
65
	
-
 
66
 
-
 
67
	// POST /entity
76
	// POST /entity
68
 
77
 
69
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
78
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
70
	public String create() {
79
	public String create() {
71
		log.info("CartController.create");
80
		log.info("CartController.create");
Line 209... Line 218...
209
		}
218
		}
210
		
219
		
211
		return false;
220
		return false;
212
	}
221
	}
213
 
222
 
214
 
-
 
215
 
-
 
216
	private int getNumberOfItemsInCart(long cartId) {
223
	private int getNumberOfItemsInCart(long cartId) {
217
		int numberOfItems = 0;
224
		int numberOfItems = 0;
218
		UserContextServiceClient userContextServiceClient = null;
225
		UserContextServiceClient userContextServiceClient = null;
219
		try {
226
		try {
220
			userContextServiceClient = new UserContextServiceClient();
227
			userContextServiceClient = new UserContextServiceClient();
Line 228... Line 235...
228
		} catch (Exception e) {
235
		} catch (Exception e) {
229
			e.printStackTrace();
236
			e.printStackTrace();
230
		}
237
		}
231
		return numberOfItems;
238
		return numberOfItems;
232
	}
239
	}
-
 
240
	
-
 
241
	public List<Map<String,String>> getCartItems() {
-
 
242
	    List<Map<String,String>> items = null;
233
 
243
 
-
 
244
        UserContextServiceClient userServiceClient = null;
-
 
245
        in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
246
        CatalogServiceClient catalogServiceClient  = null;
-
 
247
        in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
-
 
248
 
-
 
249
        try    {
-
 
250
            catalogServiceClient = new CatalogServiceClient();
-
 
251
            catalogClient = catalogServiceClient.getClient();
-
 
252
            userServiceClient = new UserContextServiceClient();
-
 
253
            userClient = userServiceClient.getClient();
-
 
254
            
-
 
255
            pincode = userClient.getDefaultPincode(userinfo.getUserId());
-
 
256
            Cart cart = userClient.getCart(userinfo.getCartId());
-
 
257
            List<Line> lineItems = cart.getLines();
-
 
258
            
-
 
259
            if(lineItems.size() != 0)  {
-
 
260
                items = new ArrayList<Map<String,String>>();
-
 
261
 
-
 
262
                for (Line line : lineItems)    {
-
 
263
                    Map<String, String> itemdetail = new HashMap<String, String>();
-
 
264
                    Item item = catalogClient.getItem(line.getItemId());
-
 
265
 
-
 
266
                    String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
-
 
267
                                            + ((item.getModelName() != null) ? item.getModelName() + " " : "") 
-
 
268
                                            + (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
-
 
269
                                            + (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
-
 
270
                    
-
 
271
                    itemdetail.put("ITEM_NAME", itemName);
-
 
272
                    itemdetail.put("ITEM_ID", line.getItemId() + "");
-
 
273
                    itemdetail.put("CATALOG_ID", item.getCatalogItemId() + "");
-
 
274
                    itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity()) + "");
-
 
275
                    itemdetail.put("MRP", ((int)item.getMrp()) + "");
-
 
276
                    itemdetail.put("SELLING_PRICE", ((int)item.getSellingPrice()) + "");
-
 
277
                    itemdetail.put("TOTAL_PRICE", ((int)((item.getSellingPrice() * line.getQuantity()))) + "");
-
 
278
                    itemdetail.put("SHIPPING_TIME", line.getEstimate() + "");
-
 
279
 
-
 
280
                    totalamount = totalamount + line.getQuantity() * item.getSellingPrice();
-
 
281
                    items.add(itemdetail);
-
 
282
                }
-
 
283
            }
-
 
284
            couponCode = cart.getCouponCode() == null ? "" : cart.getCouponCode();
-
 
285
            discountedAmount = cart.getDiscountedPrice();
-
 
286
        } catch (Exception e)  {
-
 
287
            e.printStackTrace();
-
 
288
        }
-
 
289
        return items;
-
 
290
	}
234
 
291
 
-
 
292
	public double getTotalAmount() {
-
 
293
	    return totalamount;
-
 
294
	}
-
 
295
	
-
 
296
	public String getPinCode() {
-
 
297
	    return pincode;
-
 
298
	}
-
 
299
	
235
	public String getCartHeaderSnippet(){
300
	public String getCouponCode()  {
-
 
301
	    return couponCode;
-
 
302
	}
-
 
303
	
-
 
304
	public String getDiscountedAmount()   {
236
		return htmlSnippets.get("CART_HEADER");
305
	    return discountedAmount + "";
237
	}
306
	}
238
	
307
	
239
	public String getCartDetailsSnippet(){
308
	public String getErrorMsg()    {
240
		return htmlSnippets.get("CART_DETAILS");
309
	    return errorMsg;
241
	}
310
	}
242
	
311
	
243
	public long getNumberOfItems(){
312
	public long getNumberOfItems(){
244
		return userinfo.getTotalItems();
313
		return userinfo.getTotalItems();
245
	}
314
	}