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