| Line 1... |
Line 1... |
| 1 |
package in.shop2020.serving.controllers;
|
1 |
package in.shop2020.serving.controllers;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.user.Cart;
|
- |
|
| 4 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
- |
|
| 5 |
import in.shop2020.model.v1.user.Address;
|
3 |
import in.shop2020.model.v1.user.Address;
|
| 6 |
import in.shop2020.model.v1.user.AddressType;
|
4 |
import in.shop2020.model.v1.user.AddressType;
|
| - |
|
5 |
import in.shop2020.model.v1.user.User;
|
| 7 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
6 |
import in.shop2020.model.v1.user.UserContextService;
|
| 8 |
import in.shop2020.serving.controllers.BaseController;
|
7 |
import in.shop2020.serving.controllers.BaseController;
|
| 9 |
import in.shop2020.serving.pages.PageContentKeys;
|
8 |
import in.shop2020.serving.pages.PageContentKeys;
|
| 10 |
import in.shop2020.serving.pages.PageEnum;
|
9 |
import in.shop2020.serving.pages.PageEnum;
|
| 11 |
import in.shop2020.serving.pages.PageManager;
|
10 |
import in.shop2020.serving.pages.PageManager;
|
| 12 |
import in.shop2020.serving.utils.Utils;
|
- |
|
| 13 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
11 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 14 |
|
12 |
|
| 15 |
import java.util.*;
|
13 |
import java.util.*;
|
| 16 |
|
14 |
|
| 17 |
import org.apache.juli.logging.Log;
|
15 |
import org.apache.juli.logging.Log;
|
| 18 |
import org.apache.juli.logging.LogFactory;
|
16 |
import org.apache.juli.logging.LogFactory;
|
| 19 |
import org.apache.struts2.convention.annotation.Result;
|
- |
|
| 20 |
import org.apache.struts2.convention.annotation.Results;
|
- |
|
| 21 |
import org.apache.struts2.interceptor.ParameterAware;
|
17 |
import org.apache.struts2.interceptor.ParameterAware;
|
| 22 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
18 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 23 |
import org.apache.struts2.rest.HttpHeaders;
|
19 |
import org.apache.struts2.rest.HttpHeaders;
|
| 24 |
import org.apache.thrift.TException;
|
20 |
import org.apache.thrift.TException;
|
| 25 |
|
21 |
|
| Line 30... |
Line 26... |
| 30 |
Map<String, String[]> reqparams = null;
|
26 |
Map<String, String[]> reqparams = null;
|
| 31 |
|
27 |
|
| 32 |
private Map<String,String> htmlSnippets;
|
28 |
private Map<String,String> htmlSnippets;
|
| 33 |
private PageManager pageManager = null;
|
29 |
private PageManager pageManager = null;
|
| 34 |
private long addressId = 0;
|
30 |
private long addressId = 0;
|
| - |
|
31 |
private String errorMsg = "";
|
| 35 |
|
32 |
|
| 36 |
public ShippingController(){
|
33 |
public ShippingController(){
|
| 37 |
super();
|
34 |
super();
|
| 38 |
pageManager = PageManager.getPageManager();
|
35 |
pageManager = PageManager.getPageManager();
|
| 39 |
}
|
36 |
}
|
| 40 |
|
37 |
|
| 41 |
// GET /shipping
|
38 |
// GET /shipping
|
| 42 |
public HttpHeaders index() {
|
39 |
public HttpHeaders index() {
|
| 43 |
long userId = userinfo.getUserId();
|
40 |
long userId = userinfo.getUserId();
|
| 44 |
boolean isLoggedIn = userinfo.isLoggedIn();
|
41 |
boolean isLoggedIn = userinfo.isLoggedIn();
|
| - |
|
42 |
|
| - |
|
43 |
|
| - |
|
44 |
try {
|
| - |
|
45 |
UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
|
| - |
|
46 |
User user = userClient.getUserById(userId);
|
| - |
|
47 |
log.info("The default address id of this user is: " + user.getDefaultAddressId());
|
| - |
|
48 |
if(user.getDefaultAddressId() > 0)
|
| - |
|
49 |
userClient.addAddressToCart(userinfo.getCartId(), user.getDefaultAddressId());
|
| - |
|
50 |
if(!userClient.validateCart(userinfo.getCartId()))
|
| - |
|
51 |
errorMsg = "Your cart has been updated.";
|
| - |
|
52 |
|
| - |
|
53 |
} catch (Exception e) {
|
| - |
|
54 |
// This exception can be ignored for showing the cart. Not so
|
| - |
|
55 |
// innocent when this occurs at the time of checkout or when the
|
| - |
|
56 |
// user is proceeding to pay.
|
| - |
|
57 |
e.printStackTrace();
|
| - |
|
58 |
}
|
| - |
|
59 |
|
| 45 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
60 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
| 46 |
|
61 |
|
| 47 |
params.put(PageContentKeys.CUSTOMER_ID, userId+"");
|
62 |
params.put(PageContentKeys.CUSTOMER_ID, userId+"");
|
| 48 |
params.put(PageContentKeys.IS_LOGGED_IN, isLoggedIn+"");
|
63 |
params.put(PageContentKeys.IS_LOGGED_IN, isLoggedIn+"");
|
| 49 |
params.put(PageContentKeys.CART_ID, userinfo.getCartId()+"");
|
64 |
params.put(PageContentKeys.CART_ID, userinfo.getCartId()+"");
|
| 50 |
params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
|
65 |
params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
|
| 51 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
66 |
params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
|
| 52 |
|
- |
|
| - |
|
67 |
params.put(PageContentKeys.ERROR_MSG, errorMsg);
|
| 53 |
htmlSnippets = pageManager.getPageContents(PageEnum.SHIPPING_PAGE, params);
|
68 |
htmlSnippets = pageManager.getPageContents(PageEnum.SHIPPING_PAGE, params);
|
| 54 |
|
69 |
|
| 55 |
return new DefaultHttpHeaders("index").disableCaching();
|
70 |
return new DefaultHttpHeaders("index").disableCaching();
|
| 56 |
}
|
71 |
}
|
| 57 |
|
72 |
|
| Line 170... |
Line 185... |
| 170 |
}
|
185 |
}
|
| 171 |
|
186 |
|
| 172 |
public long getAddressId(){
|
187 |
public long getAddressId(){
|
| 173 |
return this.addressId;
|
188 |
return this.addressId;
|
| 174 |
}
|
189 |
}
|
| - |
|
190 |
|
| - |
|
191 |
public String getErrorMsg(){
|
| - |
|
192 |
return this.errorMsg;
|
| - |
|
193 |
}
|
| 175 |
}
|
194 |
}
|