| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import in.shop2020.datalogger.EventType;
|
3 |
import in.shop2020.datalogger.EventType;
|
| 4 |
import in.shop2020.model.v1.user.PromotionException;
|
4 |
import in.shop2020.model.v1.user.PromotionException;
|
| 5 |
import in.shop2020.model.v1.user.PromotionService;
|
5 |
import in.shop2020.model.v1.user.PromotionService;
|
| 6 |
import in.shop2020.model.v1.user.UserContextService;
|
6 |
import in.shop2020.model.v1.user.UserContextService;
|
| - |
|
7 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
| 7 |
import in.shop2020.thrift.clients.PromotionClient;
|
8 |
import in.shop2020.thrift.clients.PromotionClient;
|
| 8 |
import in.shop2020.thrift.clients.UserClient;
|
9 |
import in.shop2020.thrift.clients.UserClient;
|
| 9 |
import in.shop2020.utils.DataLogger;
|
10 |
import in.shop2020.utils.DataLogger;
|
| 10 |
|
11 |
|
| 11 |
import org.apache.log4j.Logger;
|
12 |
import org.apache.log4j.Logger;
|
| - |
|
13 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| - |
|
14 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 12 |
import org.apache.struts2.convention.annotation.Result;
|
15 |
import org.apache.struts2.convention.annotation.Result;
|
| 13 |
import org.apache.struts2.convention.annotation.Results;
|
16 |
import org.apache.struts2.convention.annotation.Results;
|
| 14 |
|
17 |
|
| 15 |
@SuppressWarnings("serial")
|
18 |
@SuppressWarnings("serial")
|
| - |
|
19 |
|
| - |
|
20 |
@InterceptorRefs({
|
| - |
|
21 |
@InterceptorRef("myDefault")
|
| - |
|
22 |
})
|
| - |
|
23 |
|
| 16 |
@Results({
|
24 |
@Results({
|
| 17 |
@Result(name = "redirect", type = "redirectAction", params = {"actionName" , "cart"})
|
25 |
@Result(name = "redirect", type = "redirectAction", params = {"actionName" , "cart"})
|
| 18 |
})
|
26 |
})
|
| 19 |
public class PromotionController extends BaseController {
|
27 |
public class PromotionController extends BaseController {
|
| 20 |
|
28 |
|
| Line 37... |
Line 45... |
| 37 |
addActionError("Invalid Request Action");
|
45 |
addActionError("Invalid Request Action");
|
| 38 |
return "redirect";
|
46 |
return "redirect";
|
| 39 |
}
|
47 |
}
|
| 40 |
String couponCode = request.getParameter("coupon_code");
|
48 |
String couponCode = request.getParameter("coupon_code");
|
| 41 |
|
49 |
|
| 42 |
if (action.equals("applycoupon")) {
|
50 |
if (action.equalsIgnoreCase("applycoupon")) {
|
| 43 |
if (couponCode == null || couponCode.isEmpty()) {
|
51 |
if (couponCode == null || couponCode.isEmpty()) {
|
| 44 |
addActionError("Coupon Code field cannot be left empty");
|
52 |
addActionError("Coupon Code field cannot be left empty");
|
| 45 |
return "redirect";
|
53 |
return "redirect";
|
| 46 |
}
|
54 |
}
|
| - |
|
55 |
|
| - |
|
56 |
boolean qualifiesForCoupon = true;
|
| - |
|
57 |
|
| - |
|
58 |
if(couponCode.equalsIgnoreCase("SGalaxy")) {
|
| - |
|
59 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
| - |
|
60 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
| - |
|
61 |
|
| - |
|
62 |
//TODO: Affiliate based qualification should be inside service
|
| - |
|
63 |
if (affId != 5) { //For MySmartPrice
|
| - |
|
64 |
qualifiesForCoupon = false;
|
| - |
|
65 |
}
|
| - |
|
66 |
} else {
|
| - |
|
67 |
qualifiesForCoupon = false;
|
| - |
|
68 |
}
|
| - |
|
69 |
}
|
| - |
|
70 |
if(qualifiesForCoupon) {
|
| 47 |
promotionServiceClient = new PromotionClient();
|
71 |
promotionServiceClient = new PromotionClient();
|
| 48 |
PromotionService.Client promotionClient = promotionServiceClient.getClient();
|
72 |
PromotionService.Client promotionClient = promotionServiceClient.getClient();
|
| - |
|
73 |
|
| 49 |
promotionClient.applyCoupon(couponCode, cartId);
|
74 |
promotionClient.applyCoupon(couponCode, cartId);
|
| 50 |
DataLogger.logData(EventType.COUPON_APPLIED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);
|
75 |
DataLogger.logData(EventType.COUPON_APPLIED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);
|
| - |
|
76 |
} else {
|
| - |
|
77 |
addActionError("You are not eligible for this coupon");
|
| - |
|
78 |
}
|
| 51 |
}
|
79 |
}
|
| 52 |
else if (action.equals("removecoupon")) {
|
80 |
else if (action.equals("removecoupon")) {
|
| 53 |
userServiceClient = new UserClient();
|
81 |
userServiceClient = new UserClient();
|
| 54 |
UserContextService.Client userClient = userServiceClient.getClient();
|
82 |
UserContextService.Client userClient = userServiceClient.getClient();
|
| 55 |
userClient.removeCoupon(cartId);
|
83 |
userClient.removeCoupon(cartId);
|