Subversion Repositories SmartDukaan

Rev

Rev 416 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 416 Rev 419
Line 4... Line 4...
4
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
4
import in.shop2020.model.v1.shoppingcart.ShoppingCartException;
5
import in.shop2020.serving.controllers.BaseController;
5
import in.shop2020.serving.controllers.BaseController;
6
import in.shop2020.serving.pages.PageContentKeys;
6
import in.shop2020.serving.pages.PageContentKeys;
7
import in.shop2020.serving.pages.PageEnum;
7
import in.shop2020.serving.pages.PageEnum;
8
import in.shop2020.serving.pages.PageManager;
8
import in.shop2020.serving.pages.PageManager;
-
 
9
import in.shop2020.serving.utils.Utils;
9
import in.shop2020.thrift.clients.ShoppingCartClient;
10
import in.shop2020.thrift.clients.ShoppingCartClient;
10
import in.shop2020.thrift.clients.UserContextServiceClient;
11
import in.shop2020.thrift.clients.UserContextServiceClient;
11
 
12
 
12
import java.util.*;
13
import java.util.*;
13
 
14
 
Line 27... Line 28...
27
 
28
 
28
import com.opensymphony.xwork2.ValidationAwareSupport;
29
import com.opensymphony.xwork2.ValidationAwareSupport;
29
 
30
 
30
@Results({
31
@Results({
31
    @Result(name="success", type="redirectAction", 
32
    @Result(name="success", type="redirectAction", 
32
    		params = {"actionName" , "cart"})
33
    		params = {"actionName" , "cart"}),
-
 
34
    @Result(name="redirect", location="${url}", type="redirect")
33
})
35
})
34
 
36
 
35
public class CartController extends BaseController implements ParameterAware {
37
public class CartController extends BaseController implements ParameterAware {
36
	
38
	
37
	private static final long serialVersionUID = 1L;
39
	private static final long serialVersionUID = 1L;
Line 47... Line 49...
47
	public CartController(){
49
	public CartController(){
48
		
50
		
49
	}
51
	}
50
	
52
	
51
	
53
	
52
	 // GET /entity
54
	 // GET /cart
53
    public HttpHeaders index() {
55
    public HttpHeaders index() {
-
 
56
    	/* changed on 18 august
54
    	Cookie loginCookie = new Cookie("userId", "Rajveer");
57
    	Cookie loginCookie = new Cookie("userId", "Rajveer");
55
    	Map cookiesMap = new HashMap();
58
    	Map cookiesMap = new HashMap();
56
    	cookiesMap.put("USER_ID", loginCookie);
59
    	cookiesMap.put("USER_ID", loginCookie);
57
    	setCookiesMap(cookiesMap);
60
    	setCookiesMap(cookiesMap);
58
    	
61
    	
Line 61... Line 64...
61
    	
64
    	
62
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
65
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
63
 
66
 
64
    	long userId = 0;
67
    	long userId = 0;
65
    	boolean isSessionId = true;
68
    	boolean isSessionId = true;
66
		
-
 
-
 
69
    	//if(this.session.getAttribute("loggedin")!=null){
67
    	if(this.session.getAttribute("loggedin").toString().equals("true")){
70
	    	if(this.session.getAttribute("loggedin").toString().equals("true")){
68
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
71
	    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
69
    		isSessionId = false;
72
	    		isSessionId = false;
70
    	}else{
73
	    	}else{
71
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
74
	    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
72
    		isSessionId = true;
75
	    		isSessionId = true;
73
    	}
76
	    	}
-
 
77
//    	}else{
-
 
78
//    		System.out.println("No User is logged in. Redirect to login page.");
-
 
79
//    		return new DefaultHttpHeaders("fatal");
74
 
80
//
-
 
81
//    	}
-
 
82
    	
-
 
83
    	
-
 
84
    	
75
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
85
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
76
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
86
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
-
 
87
*/
77
 
88
 
-
 
89
    	long userId = 0;
-
 
90
    	boolean isSessionId = true;
-
 
91
		Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
-
 
92
		
-
 
93
		if(userinfo.isLoggedIn()){
-
 
94
			userId = userinfo.getUserId();
-
 
95
			isSessionId = false;
-
 
96
		}
-
 
97
		else{
-
 
98
			userId = userinfo.getSessionId();
-
 
99
			isSessionId = true;
-
 
100
		}
78
		
101
		
-
 
102
		params.put(PageContentKeys.CUSTOMER_ID, userId+"");
-
 
103
		params.put(PageContentKeys.IS_SESSION_ID, isSessionId+"");
-
 
104
 
79
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
105
		htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.SHOPPING_CART_PAGE, params);
80
		
106
		
81
 
107
 
82
    	
108
    	
83
    	return new DefaultHttpHeaders("index").disableCaching();
109
    	return new DefaultHttpHeaders("index").disableCaching();
84
    }
110
    }
85
    
111
    
86
    // POST /entity
112
    // POST /entity
87
    public String create() {
113
    public String create() {
-
 
114
    	/*
88
    	log.info("CartController.create");
115
    	log.info("CartController.create");
89
    	printParams();
116
    	printParams();
90
    	if(getCookiesMap() != null){
117
    	if(getCookiesMap() != null){
91
    		Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");
118
    		Cookie loginCookie = (Cookie)getCookiesMap().get("USER_ID");
92
    		log.info("login cookie name is " + loginCookie.getName() );
119
    		log.info("login cookie name is " + loginCookie.getName() );
Line 105... Line 132...
105
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
132
    		userId = Long.parseLong(this.session.getAttribute("userid").toString());
106
    		isSessionId = true;
133
    		isSessionId = true;
107
    	}
134
    	}
108
    	addItemToCart(Long.parseLong(itemId), userId, isSessionId);
135
    	addItemToCart(Long.parseLong(itemId), userId, isSessionId);
109
    	// Add data to the cart
136
    	// Add data to the cart
-
 
137
    	*/
-
 
138
    	long userId = 0;
-
 
139
    	boolean isSessionId = true;
-
 
140
    	
-
 
141
    	log.info("item id is " + this.reqparams.get("item_id"));
-
 
142
    	itemId = this.reqparams.get("item_id")[0];
-
 
143
    	
-
 
144
		if(userinfo.isLoggedIn()){
-
 
145
			userId = userinfo.getUserId();
-
 
146
			isSessionId = false;
-
 
147
		}
-
 
148
		else{
-
 
149
			userId = userinfo.getSessionId();
-
 
150
			isSessionId = true;
-
 
151
		}
-
 
152
    	
-
 
153
    	long cartId = Utils.addItemToCart(Long.parseLong(itemId), userId, isSessionId);
-
 
154
    	
-
 
155
    	userinfo.setCartId(cartId);
-
 
156
    	userinfo.setTotalItems(userinfo.getTotalItems() + 1 );
-
 
157
    	
-
 
158
    	this.session.setAttribute("userinfo", userinfo);
110
    	
159
    	
111
		return "success";
160
		return "success";
112
    }
161
    }
113
    
162
    
114
    public void printParams(){
163
    public void printParams(){
Line 141... Line 190...
141
			shoppingCartClient = new ShoppingCartClient();
190
			shoppingCartClient = new ShoppingCartClient();
142
			cartClient = shoppingCartClient.getClient();
191
			cartClient = shoppingCartClient.getClient();
143
			
192
			
144
			cartId = cartClient.createCart(userId, isSessionId);
193
			cartId = cartClient.createCart(userId, isSessionId);
145
			cartClient.addItemToCart(cartId, catalogItemId, 1);
194
			cartClient.addItemToCart(cartId, catalogItemId, 1);
-
 
195
			
-
 
196
			int NumberOfLines = cartClient.getShadowCart(cartId).getLinesSize();
-
 
197
			this.session.setAttribute("totalitems", NumberOfLines+"");
-
 
198
 
-
 
199
			
146
		} catch (ShoppingCartException e) {
200
		} catch (ShoppingCartException e) {
147
			// TODO Auto-generated catch block
201
			// TODO Auto-generated catch block
148
			e.printStackTrace();
202
			e.printStackTrace();
149
		} catch (TException e) {
203
		} catch (TException e) {
150
			// TODO Auto-generated catch block
204
			// TODO Auto-generated catch block