| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 517 |
rajveer |
3 |
import in.shop2020.model.v1.order.Order;
|
| 419 |
rajveer |
4 |
import in.shop2020.serving.controllers.BaseController;
|
| 517 |
rajveer |
5 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
6 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
7 |
|
| 419 |
rajveer |
8 |
import java.util.*;
|
|
|
9 |
|
|
|
10 |
import org.apache.juli.logging.Log;
|
|
|
11 |
import org.apache.juli.logging.LogFactory;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
13 |
import org.apache.struts2.convention.annotation.Results;
|
| 517 |
rajveer |
14 |
import org.apache.thrift.TException;
|
| 419 |
rajveer |
15 |
|
|
|
16 |
@Results({
|
| 681 |
rajveer |
17 |
@Result(name="redirect", type="redirectAction",
|
|
|
18 |
params = {"actionName" , "login"}),
|
|
|
19 |
@Result(name="payredirect", location="${url}", type="redirect")
|
|
|
20 |
|
| 419 |
rajveer |
21 |
})
|
| 650 |
rajveer |
22 |
public class OrderController extends BaseController {
|
| 419 |
rajveer |
23 |
|
|
|
24 |
private static final long serialVersionUID = 1L;
|
|
|
25 |
|
|
|
26 |
private static Log log = LogFactory.getLog(OrderController.class);
|
| 507 |
rajveer |
27 |
private String id;
|
| 650 |
rajveer |
28 |
|
| 517 |
rajveer |
29 |
private String message;
|
| 419 |
rajveer |
30 |
|
| 681 |
rajveer |
31 |
private String paymentUrl="hdfc-pay";
|
|
|
32 |
|
| 419 |
rajveer |
33 |
public OrderController(){
|
| 507 |
rajveer |
34 |
super();
|
| 419 |
rajveer |
35 |
}
|
|
|
36 |
|
| 507 |
rajveer |
37 |
// GET /order/ orderid
|
|
|
38 |
public String show() {
|
|
|
39 |
log.info("id=" + id);
|
| 424 |
rajveer |
40 |
if(!userinfo.isLoggedIn()){
|
| 650 |
rajveer |
41 |
setRedirectUrl();
|
| 507 |
rajveer |
42 |
return "redirect";
|
| 424 |
rajveer |
43 |
}
|
| 650 |
rajveer |
44 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
45 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getOrderDetailsHtml(Long.parseLong(id)));
|
| 507 |
rajveer |
46 |
return "show";
|
| 419 |
rajveer |
47 |
}
|
| 517 |
rajveer |
48 |
|
| 572 |
chandransh |
49 |
// POST /order/
|
|
|
50 |
public String create(){
|
| 650 |
rajveer |
51 |
if(!userinfo.isLoggedIn()){
|
|
|
52 |
setRedirectUrl();
|
|
|
53 |
return "redirect";
|
|
|
54 |
}
|
| 572 |
chandransh |
55 |
long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
|
|
56 |
long currentCartId = userinfo.getCartId();
|
|
|
57 |
List<Order> orders = null;
|
|
|
58 |
try {
|
|
|
59 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
60 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
61 |
|
|
|
62 |
userClient.addAddressToCart(currentCartId, addressId);
|
|
|
63 |
Long txn_id = userClient.commitCart(currentCartId);
|
|
|
64 |
|
|
|
65 |
TransactionServiceClient tsc = new TransactionServiceClient();
|
|
|
66 |
orders = tsc.getClient().getOrdersForTransaction(txn_id);
|
|
|
67 |
|
|
|
68 |
long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
|
|
|
69 |
userinfo.setCartId(newCartId);
|
|
|
70 |
userinfo.setTotalItems(0);
|
|
|
71 |
} catch (TException e) {
|
|
|
72 |
e.printStackTrace();
|
|
|
73 |
} catch (Exception e) {
|
|
|
74 |
e.printStackTrace();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
this.message = "Your order numbers are as below:";
|
|
|
78 |
|
|
|
79 |
for(Order order: orders){
|
|
|
80 |
this.message = this.message + "<br> <a href=\"./order/" + order.getId() + "\">" + order.getId() + "</a>";
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
return "success";
|
|
|
84 |
}
|
|
|
85 |
|
| 507 |
rajveer |
86 |
public String getId(){
|
|
|
87 |
return id;
|
|
|
88 |
}
|
| 419 |
rajveer |
89 |
|
| 507 |
rajveer |
90 |
public void setId(String id){
|
|
|
91 |
this.id = id;
|
|
|
92 |
}
|
| 419 |
rajveer |
93 |
|
| 507 |
rajveer |
94 |
public String getMyaccountHeaderSnippet(){
|
|
|
95 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public String getOrderDetailsSnippet(){
|
|
|
99 |
return htmlSnippets.get("ORDER_DETAILS");
|
|
|
100 |
}
|
|
|
101 |
|
| 681 |
rajveer |
102 |
public String getUrl(){
|
|
|
103 |
return this.paymentUrl;
|
|
|
104 |
}
|
| 507 |
rajveer |
105 |
|
| 517 |
rajveer |
106 |
public String getMessage(){
|
|
|
107 |
return this.message;
|
|
|
108 |
}
|
|
|
109 |
|
| 419 |
rajveer |
110 |
}
|