Subversion Repositories SmartDukaan

Rev

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

Rev 419 Rev 449
Line 27... Line 27...
27
import org.apache.thrift.TException;
27
import org.apache.thrift.TException;
28
 
28
 
29
import com.opensymphony.xwork2.ValidationAwareSupport;
29
import com.opensymphony.xwork2.ValidationAwareSupport;
30
 
30
 
31
@Results({
31
@Results({
32
    @Result(name="success", type="redirectAction", 
32
    @Result(name="fail", type="redirectAction", 
33
    		params = {"actionName" , "cart"}),
33
    		params = {"actionName" , "cart"}),
34
    @Result(name="redirect", location="${url}", type="redirect")
34
    @Result(name="redirect", location="${url}", type="redirect")
35
})
35
})
36
 
36
 
37
public class CartController extends BaseController implements ParameterAware {
37
public class CartController extends BaseController implements ParameterAware {
Line 40... Line 40...
40
	
40
	
41
	private Map<String, String[]> reqparams;
41
	private Map<String, String[]> reqparams;
42
	private Map<String, Object> sessions;
42
	private Map<String, Object> sessions;
43
	private String redirectURL;
43
	private String redirectURL;
44
	private static Log log = LogFactory.getLog(CartController.class);
44
	private static Log log = LogFactory.getLog(CartController.class);
45
	private String itemId;
45
	//private String itemId;
46
	//HttpServletRequest request;
46
	//HttpServletRequest request;
47
	private Map<String,String> htmlSnippets;
47
	private Map<String,String> htmlSnippets;
48
	
48
	
49
	public CartController(){
49
	public CartController(){
50
		
50
		
Line 136... Line 136...
136
    	// Add data to the cart
136
    	// Add data to the cart
137
    	*/
137
    	*/
138
    	long userId = 0;
138
    	long userId = 0;
139
    	boolean isSessionId = true;
139
    	boolean isSessionId = true;
140
    	
140
    	
141
    	log.info("item id is " + this.reqparams.get("item_id"));
141
    	log.info("item id is " + this.reqparams.get("productid"));
-
 
142
    	
-
 
143
    	String itemIds = "1000008_1000005"; 
-
 
144
    	if(this.reqparams.get("productid") != null){
142
    	itemId = this.reqparams.get("item_id")[0];
145
    		itemIds = this.reqparams.get("productid")[0];
-
 
146
    	}
143
    	
147
    	
-
 
148
 	
-
 
149
//    	log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
150
//		String itemIds = this.request.getParameter("productid");
-
 
151
		
144
		if(userinfo.isLoggedIn()){
152
		if(userinfo.isLoggedIn()){
145
			userId = userinfo.getUserId();
153
			userId = userinfo.getUserId();
146
			isSessionId = false;
154
			isSessionId = false;
147
		}
155
		}
148
		else{
156
		else{
149
			userId = userinfo.getSessionId();
157
			userId = userinfo.getSessionId();
150
			isSessionId = true;
158
			isSessionId = true;
151
		}
159
		}
-
 
160
		long cartId = 0;
152
    	
161
	
-
 
162
		StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
-
 
163
		int numberOfItems = tokenizer.countTokens();
-
 
164
		while(tokenizer.hasMoreTokens()){
-
 
165
			long itemId = Long.parseLong(tokenizer.nextToken());
-
 
166
			cartId = Utils.addItemToCart(itemId, userId, isSessionId);
-
 
167
		}
-
 
168
 
153
    	long cartId = Utils.addItemToCart(Long.parseLong(itemId), userId, isSessionId);
169
    	//long cartId = Utils.addItemToCart(Long.parseLong(itemId), userId, isSessionId);
154
    	
170
    	
155
    	userinfo.setCartId(cartId);
171
    	userinfo.setCartId(cartId);
156
    	userinfo.setTotalItems(userinfo.getTotalItems() + 1 );
172
    	userinfo.setTotalItems(Utils.getNumberOfItemsInCart(cartId) );
157
    	
173
    	
158
    	this.session.setAttribute("userinfo", userinfo);
174
    	this.session.setAttribute("userinfo", userinfo);
159
    	
175
    	
160
		return "success";
176
		return "success";
161
    }
177
    }
Line 210... Line 226...
210
		
226
		
211
		//if user is logged in create  new cart
227
		//if user is logged in create  new cart
212
		//if( userClient.getState(userId, false).isIsLoggedIn()){
228
		//if( userClient.getState(userId, false).isIsLoggedIn()){
213
	}
229
	}
214
	
230
	
-
 
231
	public double getNumberOfItems(){
-
 
232
		return userinfo.getTotalItems();
-
 
233
	}
-
 
234
	
215
	public String getShoppingCartSnippets()
235
	public String getShoppingCartSnippets()
216
	{
236
	{
217
		return htmlSnippets.get("SHOPPING_CART");
237
		return htmlSnippets.get("SHOPPING_CART");
218
	}
238
	}
219
	
239