Subversion Repositories SmartDukaan

Rev

Rev 3970 | Rev 4217 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3970 Rev 4046
Line 19... Line 19...
19
import java.util.Map;
19
import java.util.Map;
20
import java.util.StringTokenizer;
20
import java.util.StringTokenizer;
21
 
21
 
22
import org.apache.log4j.Logger;
22
import org.apache.log4j.Logger;
23
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Action;
-
 
24
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.InterceptorRef;
25
import org.apache.struts2.convention.annotation.InterceptorRef;
25
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Results;
27
import org.apache.struts2.convention.annotation.Results;
27
import org.apache.struts2.interceptor.ParameterAware;
28
import org.apache.struts2.interceptor.ParameterAware;
28
import org.apache.thrift.TException;
29
import org.apache.thrift.TException;
29
 
30
 
30
 
31
 
31
@Results({
32
@Results({
32
	@Result(name="redirect", type="redirectAction", 
33
    @Result(name = "index", location = "cart-index.vm"),
33
	   		params = {"actionName" , "cart"}),
34
	@Result(name="redirect", type="redirectAction", params = {"actionName" , "cart"}),
34
	@Result(name="failure", location="cart-failure.vm"),
35
	@Result(name="failure", location="cart-failure.vm"),
35
	@Result(name="success", location="cart-success.vm")
36
	@Result(name="success", location="cart-success.vm")
36
})
37
})
37
 
38
 
38
 
-
 
39
public class CartController extends BaseController implements ParameterAware{
39
public class CartController extends BaseController implements ParameterAware{
40
	
40
	
41
	private static final long serialVersionUID = 1L;
41
	private static final long serialVersionUID = 1L;
42
	private static Logger log = Logger.getLogger(Class.class);
42
	private static Logger log = Logger.getLogger(Class.class);
43
	Map<String, String[]> reqparams = null;
43
	Map<String, String[]> reqparams = null;
44
 
44
 
45
	private String id = "0";
45
	private int variationId = 0;
46
    private String totalamount;
46
    private String totalamount;
47
	
47
	
48
	private String errorMsg = "";
48
	private String errorMsg = "";
49
	private String cartMsg = "";
49
	private String cartMsg = "";
50
	
50
	
Line 59... Line 59...
59
	public CartController(){
59
	public CartController(){
60
		super();
60
		super();
61
	}
61
	}
62
	
62
	
63
	 // GET /cart
63
	 // GET /cart
-
 
64
	@Actions({
-
 
65
		@Action(value="cart", interceptorRefs={@InterceptorRef("myDefault")}),
-
 
66
		@Action(value="cart1", interceptorRefs={@InterceptorRef("myDefault")})
-
 
67
	})
-
 
68
	public String index()	{
-
 
69
		this.setVariationId(request.getRequestURI());
-
 
70
		log.info(this.getVariationId());
64
 
71
 
65
	@Action(value="cart",interceptorRefs={@InterceptorRef("myDefault")})
72
		long cartId = userinfo.getCartId();
-
 
73
		
66
	 public String index() {
74
	    if(cartId != -1){
67
	    populateCartData();
75
        	try {
-
 
76
    			UserContextService.Client userClient = (new UserClient()).getClient();
68
    	return "index";
77
    			errorMsg = userClient.validateCart(cartId, sourceId);
-
 
78
    			log.info("Error Message rcvd from the service is:" + errorMsg);
69
	 }
79
    			
70
	
-
 
71
	//GET /cart/param
80
    			// As per ticket #119 in trac
72
 
-
 
73
	@Action(value="cart",interceptorRefs={@InterceptorRef("myDefault")})
81
    			Cart cart = userClient.getCart(cartId);
-
 
82
    			int totalItems = cart.getLinesSize();
-
 
83
    			double totalAmount = cart.getTotalPrice();
-
 
84
				userinfo.setTotalItems(totalItems);
-
 
85
				userinfo.setTotalAmount(totalAmount);
74
	public String show()	{
86
    		} catch (Exception e) {
-
 
87
    			// This exception can be ignored for showing the cart. Not so
-
 
88
    			// innocent when this occurs at the time of checkout or when the
75
	    populateCartData();
89
    			// user is proceeding to pay.
-
 
90
    		    log.warn("Unable to validate the cart: ", e);
-
 
91
    		}
-
 
92
	    }
76
		return "index";
93
		return "index";
77
	}
94
	}
78
	
95
 
79
	// POST /entity
96
	// POST /entity
80
 
97
 
81
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
98
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
82
	public String create() {
99
	public String create() {
83
		log.info("CartController.create");
100
		log.info("CartController.create");
Line 179... Line 196...
179
			DataLogger.logData(EventType.UPDATE_CART_QUANTITY_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
196
			DataLogger.logData(EventType.UPDATE_CART_QUANTITY_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
180
                    Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
197
                    Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
181
			addActionError("Unable to update the quantity");
198
			addActionError("Unable to update the quantity");
182
			return "redirect";
199
			return "redirect";
183
		}
200
		}
184
		
-
 
185
 
-
 
186
	private void populateCartData()	{
-
 
187
		long cartId = userinfo.getCartId();
-
 
188
	    if(cartId != -1){
-
 
189
        	try {
-
 
190
    			UserContextService.Client userClient = (new UserClient()).getClient();
-
 
191
    			errorMsg = userClient.validateCart(cartId, sourceId);
-
 
192
    			log.info("Error Message rcvd from the service is:" + errorMsg);
-
 
193
    			
-
 
194
    			// As per ticket #119 in trac
-
 
195
    			Cart cart = userClient.getCart(cartId);
-
 
196
    			int totalItems = cart.getLinesSize();
-
 
197
    			double totalAmount = cart.getTotalPrice();
-
 
198
				userinfo.setTotalItems(totalItems);
-
 
199
				userinfo.setTotalAmount(totalAmount);
-
 
200
    		} catch (Exception e) {
-
 
201
    			// This exception can be ignored for showing the cart. Not so
-
 
202
    			// innocent when this occurs at the time of checkout or when the
-
 
203
    			// user is proceeding to pay.
-
 
204
    		    log.warn("Unable to validate the cart: ", e);
-
 
205
    		}
-
 
206
	    }
-
 
207
	}
-
 
208
	
201
	
209
    public void printParams(){
202
    public void printParams(){
210
    	for(String param : reqparams.keySet()) {
203
    	for(String param : reqparams.keySet()) {
211
    		log.info("param name is " + param);
204
    		log.info("param name is " + param);
212
    		log.info("param first is " + reqparams.get(param)[0]);
205
    		log.info("param first is " + reqparams.get(param)[0]);
Line 358... Line 351...
358
	        return null;
351
	        return null;
359
	    }
352
	    }
360
	    return cartMsg;
353
	    return cartMsg;
361
	}
354
	}
362
	
355
	
363
	
-
 
364
	public String getSnippets(){
356
	public String getSnippets(){
365
    	String snippets = "";
357
    	String snippets = "";
366
		CatalogClient csc;
358
		CatalogClient csc;
367
		try {
359
		try {
368
			csc = new CatalogClient();
360
			csc = new CatalogClient();
Line 391... Line 383...
391
		}
383
		}
392
		url = request.getRequestURI() + url;
384
		url = request.getRequestURI() + url;
393
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getNameOfUser(), url , 0, false);
385
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getNameOfUser(), url , 0, false);
394
	}
386
	}
395
	
387
	
396
	public void setId(String id)	{
388
	public void setVariationId(String uri)	{
-
 
389
		if (uri.equals("/cart1"))	{
397
		this.id = id;
390
			this.variationId = 1;
-
 
391
		}
398
	}
392
	}
399
	
393
	
400
	public String getId()	{
394
	public int getVariationId()	{
401
		return this.id;
395
		return this.variationId;
402
	}
396
	}
403
}
397
}
404
398