Subversion Repositories SmartDukaan

Rev

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

Rev 6736 Rev 6903
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.datalogger.EventType;
3
import in.shop2020.datalogger.EventType;
4
import in.shop2020.model.v1.catalog.CatalogService.Client;
4
import in.shop2020.model.v1.catalog.CatalogService.Client;
-
 
5
import in.shop2020.model.v1.catalog.Insurer;
5
import in.shop2020.model.v1.catalog.Item;
6
import in.shop2020.model.v1.catalog.Item;
-
 
7
import in.shop2020.model.v1.catalog.ItemInsurerMapping;
6
import in.shop2020.model.v1.user.Cart;
8
import in.shop2020.model.v1.user.Cart;
7
import in.shop2020.model.v1.user.Line;
9
import in.shop2020.model.v1.user.Line;
8
import in.shop2020.model.v1.user.ShoppingCartException;
10
import in.shop2020.model.v1.user.ShoppingCartException;
9
import in.shop2020.model.v1.user.UserContextService;
11
import in.shop2020.model.v1.user.UserContextService;
10
import in.shop2020.serving.services.ContentServingService;
12
import in.shop2020.serving.services.ContentServingService;
Line 55... Line 57...
55
	private String couponCode = null;
57
	private String couponCode = null;
56
	
58
	
57
	private String discountedAmount;
59
	private String discountedAmount;
58
	
60
	
59
	private long itemId;
61
	private long itemId;
-
 
62
    private String insuranceResult;
-
 
63
    
-
 
64
    private boolean toInsure;
-
 
65
    private long productId;
60
	
66
	
61
	public CartController(){
67
	public CartController(){
62
		super();
68
		super();
63
	}
69
	}
64
	
70
	
Line 280... Line 286...
280
            userClient = userServiceClient.getClient();
286
            userClient = userServiceClient.getClient();
281
            
287
            
282
            pincode = userClient.getDefaultPincode(userinfo.getUserId());
288
            pincode = userClient.getDefaultPincode(userinfo.getUserId());
283
            Cart cart = userClient.getCart(userinfo.getCartId());
289
            Cart cart = userClient.getCart(userinfo.getCartId());
284
            List<Line> lineItems = cart.getLines();
290
            List<Line> lineItems = cart.getLines();
-
 
291
            double totalInsuranceAmount = 0.0;
285
            
292
            boolean isAnyItemInsured = false;
286
            if(lineItems.size() != 0)  {
293
            if(lineItems.size() != 0)  {
287
                items = new ArrayList<Map<String,String>>();
294
                items = new ArrayList<Map<String,String>>();
288
 
295
 
289
                for (Line line : lineItems)    {
296
                for (Line line : lineItems)    {
290
                    Map<String, String> itemdetail = new HashMap<String, String>();
297
                    Map<String, String> itemdetail = new HashMap<String, String>();
291
                    
298
                    
-
 
299
                    double insuranceAmount = 0;
292
                    Item item = catalogClient.getItemForSource(line.getItemId(), sourceId);
300
                    Item item = catalogClient.getItemForSource(line.getItemId(), sourceId);
-
 
301
                    Insurer insurer = null;
-
 
302
                    
-
 
303
                    if(line.getInsurer() != 0) {
-
 
304
                        insuranceAmount = line.getInsuranceAmount();
-
 
305
                        isAnyItemInsured = true;
-
 
306
                    } else if (item.getPreferredInsurer() != 0) {
-
 
307
                        insuranceAmount = catalogClient.getInsuranceAmount(item.getId(), item.getPreferredInsurer(), (long)line.getQuantity());
-
 
308
                        //Insurer insurer = catalogClient.getInsurer(item.getPreferredInsurer());
-
 
309
                    } else {
-
 
310
                        insuranceAmount = 0;
-
 
311
                    }
293
                    
312
                    
294
                    String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
313
                    String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
295
                                            + ((item.getModelName() != null) ? item.getModelName() + " " : "") 
314
                                            + ((item.getModelName() != null) ? item.getModelName() + " " : "") 
296
                                            + (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" );
315
                                            + (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" );
297
                    
316
                    
Line 307... Line 326...
307
                    itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
326
                    itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
308
                    itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
327
                    itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
309
                    itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice(((item.getSellingPrice() * line.getQuantity()))));
328
                    itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice(((item.getSellingPrice() * line.getQuantity()))));
310
                    itemdetail.put("SHIPPING_TIME", line.getEstimate() + "");
329
                    itemdetail.put("SHIPPING_TIME", line.getEstimate() + "");
311
					itemdetail.put("BEST_DEAL_TEXT", item.getBestDealText());
330
					itemdetail.put("BEST_DEAL_TEXT", item.getBestDealText());
-
 
331
					itemdetail.put("IS_INSURABLE", item.getPreferredInsurer() + "");
-
 
332
					itemdetail.put("IS_INSURED", (line.getInsurer() == 0 ? false : true) + "");
-
 
333
					itemdetail.put("INSURANCE_AMOUNT", insuranceAmount + "");
312
 
334
 
-
 
335
					totalInsuranceAmount += insuranceAmount;
313
                    items.add(itemdetail);
336
                    items.add(itemdetail);
314
                }
337
                }
315
            }
338
            }
316
            
339
            
-
 
340
//            if(isAnyItemInsured == false) {
-
 
341
//                totalamount = formattingUtils.formatPrice(cart.getTotalPrice() + totalInsuranceAmount);
-
 
342
//                discountedAmount = formattingUtils.formatPrice(cart.getDiscountedPrice() + totalInsuranceAmount);
-
 
343
//            } else {
317
            totalamount = formattingUtils.formatPrice(cart.getTotalPrice());
344
                totalamount = formattingUtils.formatPrice(cart.getTotalPrice());
-
 
345
                discountedAmount = formattingUtils.formatPrice(cart.getDiscountedPrice());
-
 
346
//            }
-
 
347
            
318
            couponCode = cart.getCouponCode() == null ? "" : cart.getCouponCode();
348
            couponCode = cart.getCouponCode() == null ? "" : cart.getCouponCode();
319
            discountedAmount = formattingUtils.formatPrice(cart.getDiscountedPrice());
-
 
320
        } catch (Exception e)  {
349
        } catch (Exception e){
321
            log.error("Unable to get the cart details becasue of: ", e);
350
            log.error("Unable to get the cart details becasue of: ", e);
322
        }
351
        }
323
        return items;
352
        return items;
324
	}
353
	}
-
 
354
	
-
 
355
	public String insureItem() {
-
 
356
	    //TODO : Call a method in userservice that insures the item.
-
 
357
	    insuranceResult = "";
-
 
358
	    try {
-
 
359
	        UserContextService.Client usc = new UserClient().getClient();
-
 
360
            if(usc.insureItem(productId, userinfo.getCartId(), toInsure)) {
-
 
361
                setInsuranceResult("SUCCESS");
-
 
362
            } else {
-
 
363
                setInsuranceResult("FAILURE");
-
 
364
            }
-
 
365
        } catch (Exception e) {
-
 
366
            log.error("Unable to insure item : " + productId + " for cart : " + userinfo.getCartId(), e);
-
 
367
            setInsuranceResult("FAILURE");
-
 
368
        }
-
 
369
	    return "insurance-result";
-
 
370
	}
325
 
371
 
326
	public long getItemId(){
372
	public long getItemId(){
327
		return this.itemId;
373
		return this.itemId;
328
	}
374
	}
329
	
375
	
Line 427... Line 473...
427
				log.error("Unable to get the offertext because of: ", e);
473
				log.error("Unable to get the offertext because of: ", e);
428
			}
474
			}
429
		}
475
		}
430
		return note;
476
		return note;
431
	}
477
	}
-
 
478
 
-
 
479
    public String getInsuranceResult() {
-
 
480
        return insuranceResult;
-
 
481
    }
-
 
482
 
-
 
483
    public void setInsuranceResult(String insuranceResult) {
-
 
484
        this.insuranceResult = insuranceResult;
-
 
485
    }
-
 
486
 
-
 
487
    public void setToInsure(boolean toInsure) {
-
 
488
        this.toInsure = toInsure;
-
 
489
    }
-
 
490
 
-
 
491
    public boolean getToInsure() {
-
 
492
        return toInsure;
-
 
493
    }
-
 
494
 
-
 
495
    public long getProductId() {
-
 
496
        return productId;
-
 
497
    }
-
 
498
 
-
 
499
    public void setProductId(long productId) {
-
 
500
        this.productId = productId;
-
 
501
    }
432
}
502
}