| 1981 |
varun.gupt |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 2752 |
varun.gupt |
3 |
import in.shop2020.datalogger.EventType;
|
| 1981 |
varun.gupt |
4 |
import in.shop2020.model.v1.user.PromotionException;
|
| 3224 |
vikas |
5 |
import in.shop2020.model.v1.user.PromotionService;
|
| 1981 |
varun.gupt |
6 |
import in.shop2020.model.v1.user.UserContextService;
|
| 3224 |
vikas |
7 |
import in.shop2020.thrift.clients.PromotionClient;
|
| 3126 |
rajveer |
8 |
import in.shop2020.thrift.clients.UserClient;
|
| 3224 |
vikas |
9 |
import in.shop2020.utils.DataLogger;
|
| 1981 |
varun.gupt |
10 |
|
| 3224 |
vikas |
11 |
import org.apache.log4j.Logger;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
13 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
14 |
|
| 2145 |
chandransh |
15 |
@SuppressWarnings("serial")
|
| 1981 |
varun.gupt |
16 |
@Results({
|
|
|
17 |
@Result(name = "redirect", type = "redirectAction", params = {"actionName" , "cart"})
|
|
|
18 |
})
|
|
|
19 |
public class PromotionController extends BaseController {
|
|
|
20 |
|
|
|
21 |
public PromotionController() {
|
|
|
22 |
super();
|
|
|
23 |
}
|
|
|
24 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
25 |
|
|
|
26 |
public String create() {
|
|
|
27 |
String action = request.getParameter("action");
|
|
|
28 |
log.info("Action is: " + action);
|
|
|
29 |
|
| 3126 |
rajveer |
30 |
UserClient userServiceClient = null;
|
|
|
31 |
PromotionClient promotionServiceClient = null;
|
| 1981 |
varun.gupt |
32 |
|
|
|
33 |
try {
|
|
|
34 |
long cartId = userinfo.getCartId();
|
|
|
35 |
|
|
|
36 |
if(action == null || action.isEmpty()) {
|
|
|
37 |
addActionError("Invalid Request Action");
|
|
|
38 |
return "redirect";
|
|
|
39 |
}
|
| 2752 |
varun.gupt |
40 |
String couponCode = request.getParameter("coupon_code");
|
|
|
41 |
|
| 1981 |
varun.gupt |
42 |
if (action.equals("applycoupon")) {
|
|
|
43 |
if (couponCode == null || couponCode.isEmpty()) {
|
|
|
44 |
addActionError("Coupon Code field cannot be left empty");
|
|
|
45 |
return "redirect";
|
|
|
46 |
}
|
| 3126 |
rajveer |
47 |
promotionServiceClient = new PromotionClient();
|
| 1981 |
varun.gupt |
48 |
PromotionService.Client promotionClient = promotionServiceClient.getClient();
|
| 2145 |
chandransh |
49 |
promotionClient.applyCoupon(couponCode, cartId);
|
| 3224 |
vikas |
50 |
DataLogger.logData(EventType.COUPON_APPLIED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);
|
| 1981 |
varun.gupt |
51 |
}
|
|
|
52 |
else if (action.equals("removecoupon")) {
|
| 3126 |
rajveer |
53 |
userServiceClient = new UserClient();
|
| 1981 |
varun.gupt |
54 |
UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
55 |
userClient.removeCoupon(cartId);
|
| 3224 |
vikas |
56 |
DataLogger.logData(EventType.COUPON_REMOVED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), couponCode);
|
| 1981 |
varun.gupt |
57 |
}
|
|
|
58 |
} catch (PromotionException e) {
|
| 3171 |
rajveer |
59 |
log.info("Invalid coupon: " + e.getMessage());
|
| 1981 |
varun.gupt |
60 |
addActionError(e.getMessage());
|
|
|
61 |
} catch (Exception e) {
|
| 2949 |
chandransh |
62 |
log.error("Unable to apply or remove coupon", e);
|
| 1981 |
varun.gupt |
63 |
}
|
|
|
64 |
return "redirect";
|
|
|
65 |
}
|
|
|
66 |
}
|