| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
4 |
import in.shop2020.model.v1.order.OrderInfo;
|
|
|
5 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
6 |
import in.shop2020.model.v1.shoppingcart.Cart;
|
|
|
7 |
import in.shop2020.model.v1.shoppingcart.Line;
|
|
|
8 |
import in.shop2020.model.v1.shoppingcart.ShadowCart;
|
|
|
9 |
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
|
|
|
10 |
import in.shop2020.serving.controllers.BaseController;
|
|
|
11 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
12 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
13 |
import in.shop2020.serving.pages.PageManager;
|
|
|
14 |
import in.shop2020.thrift.clients.ShoppingCartClient;
|
|
|
15 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
16 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
17 |
|
|
|
18 |
import java.util.*;
|
|
|
19 |
|
|
|
20 |
import javax.servlet.http.Cookie;
|
|
|
21 |
import javax.servlet.http.HttpServletRequest;
|
|
|
22 |
|
|
|
23 |
import org.apache.commons.lang.StringUtils;
|
|
|
24 |
import org.apache.juli.logging.Log;
|
|
|
25 |
import org.apache.juli.logging.LogFactory;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
27 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
28 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
29 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
30 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
31 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
32 |
import org.apache.thrift.TException;
|
|
|
33 |
|
|
|
34 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
35 |
|
|
|
36 |
@Results({
|
|
|
37 |
@Result(name="success", type="redirectAction",
|
|
|
38 |
params = {"actionName" , "order"})
|
|
|
39 |
})
|
|
|
40 |
|
|
|
41 |
public class OrderController extends BaseController implements ParameterAware {
|
|
|
42 |
|
|
|
43 |
private static final long serialVersionUID = 1L;
|
|
|
44 |
|
|
|
45 |
private Map<String, String[]> reqparams;
|
|
|
46 |
private Map<String, Object> sessions;
|
|
|
47 |
private String redirectURL;
|
|
|
48 |
private static Log log = LogFactory.getLog(OrderController.class);
|
|
|
49 |
private String cartId;
|
|
|
50 |
//HttpServletRequest request;
|
|
|
51 |
private Map<String,String> htmlSnippets;
|
|
|
52 |
|
|
|
53 |
public OrderController(){
|
|
|
54 |
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
// GET /entity
|
|
|
59 |
public HttpHeaders index() {
|
|
|
60 |
return new DefaultHttpHeaders("index").disableCaching();
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// POST /entity
|
|
|
64 |
public String create() {
|
|
|
65 |
log.info("OrderController.create");
|
| 424 |
rajveer |
66 |
if(!userinfo.isLoggedIn()){
|
|
|
67 |
//redirect to the login or signIn page and it should be redirected back once user is logged in
|
|
|
68 |
}else{
|
|
|
69 |
//Display the cart, amount, payment options and address along with pay button
|
|
|
70 |
|
|
|
71 |
long userId = this.userinfo.getUserId();
|
|
|
72 |
createOrderFromCart(userId);
|
|
|
73 |
}
|
| 419 |
rajveer |
74 |
|
|
|
75 |
return "success";
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
private void createOrderFromCart(long userId){
|
|
|
81 |
ShoppingCartClient shoppingCartClient = null;
|
|
|
82 |
in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = null;
|
|
|
83 |
try{
|
|
|
84 |
shoppingCartClient = new ShoppingCartClient();
|
|
|
85 |
cartClient = shoppingCartClient.getClient();
|
|
|
86 |
|
|
|
87 |
long cartId = cartClient.getCurrentCart(userId, false).getId();
|
|
|
88 |
|
|
|
89 |
cartClient.commitCart(cartId);
|
|
|
90 |
} catch (ShoppingCartException e) {
|
|
|
91 |
// TODO Auto-generated catch block
|
|
|
92 |
e.printStackTrace();
|
|
|
93 |
} catch (TException e) {
|
|
|
94 |
// TODO Auto-generated catch block
|
|
|
95 |
e.printStackTrace();
|
|
|
96 |
} catch (Exception e) {
|
|
|
97 |
// TODO Auto-generated catch block
|
|
|
98 |
e.printStackTrace();
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
@Override
|
|
|
104 |
public void setParameters(Map<String, String[]> reqmap) {
|
|
|
105 |
log.info("setParameters:" + reqmap);
|
|
|
106 |
|
|
|
107 |
this.reqparams = reqmap;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
// @Override
|
|
|
111 |
// public void setServletRequest(HttpServletRequest request) {
|
|
|
112 |
// this.request = request;
|
|
|
113 |
// }
|
|
|
114 |
//
|
|
|
115 |
}
|