Subversion Repositories SmartDukaan

Rev

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

Rev 507 Rev 517
Line 30... Line 30...
30
	private static Log log = LogFactory.getLog(ShippingController.class);
30
	private static Log log = LogFactory.getLog(ShippingController.class);
31
	Map<String, String[]> reqparams = null;
31
	Map<String, String[]> reqparams = null;
32
	
32
	
33
	private Map<String,String> htmlSnippets;
33
	private Map<String,String> htmlSnippets;
34
	private PageManager pageManager = null;
34
	private PageManager pageManager = null;
-
 
35
	private long addressId = 0;
35
	
36
	
36
	public ShippingController(){
37
	public ShippingController(){
37
		super();
38
		super();
38
		pageManager = PageManager.getPageManager();	
39
		pageManager = PageManager.getPageManager();	
39
	}
40
	}
Line 63... Line 64...
63
    	return new DefaultHttpHeaders("index").disableCaching();
64
    	return new DefaultHttpHeaders("index").disableCaching();
64
	 }
65
	 }
65
 
66
 
66
	// POST /entity
67
	// POST /entity
67
	public HttpHeaders create(){
68
	public HttpHeaders create(){
-
 
69
		UserContextServiceClient userContextServiceClient;
-
 
70
		ShoppingCartClient shoppingCartClient;
-
 
71
 
68
    	printParams();
72
    	printParams();
69
 
73
 
70
		log.info("list of item ids is " + this.request.getParameter("productid"));
-
 
71
		
-
 
72
		Address address = new Address();
-
 
73
		address.setName(this.request.getParameter("customername"));
-
 
74
		address.setLine1(this.request.getParameter("line1"));
-
 
75
		address.setLine2(this.request.getParameter("line2"));
-
 
76
		address.setCity(this.request.getParameter("city"));
74
		String action = this.request.getParameter("action");
77
		address.setState(this.request.getParameter("state"));
-
 
78
		address.setPin(this.request.getParameter("pincode"));
-
 
79
		address.setPhone(this.request.getParameter("mobilenumber"));
-
 
80
		address.setCountry(this.request.getParameter("country"));
-
 
81
		address.setEnabled(true);
75
		if(action == null){
82
		address.setType(AddressType.HOME);
76
			return new DefaultHttpHeaders("failure");
83
		
-
 
84
		
77
		}
85
		
78
		
-
 
79
		if(action.equals("addnew")){
86
		    	
80
			
87
		if(userinfo.isLoggedIn()){
81
			Address address = new Address();
-
 
82
			address.setName(this.request.getParameter("customername"));
-
 
83
			address.setLine1(this.request.getParameter("line1"));
-
 
84
			address.setLine2(this.request.getParameter("line2"));
88
			UserContextServiceClient userContextServiceClient;
85
			address.setCity(this.request.getParameter("city"));
-
 
86
			address.setState(this.request.getParameter("state"));
-
 
87
			address.setPin(this.request.getParameter("pincode"));
-
 
88
			address.setPhone(this.request.getParameter("mobilenumber"));
-
 
89
			address.setCountry(this.request.getParameter("country"));
-
 
90
			address.setEnabled(true);
89
			ShoppingCartClient shoppingCartClient;
91
			address.setType(AddressType.HOME);
-
 
92
			
-
 
93
			if(userinfo.isLoggedIn()){
90
			try {
94
				try {
91
				userContextServiceClient = new UserContextServiceClient();
95
					userContextServiceClient = new UserContextServiceClient();
92
				Client userClient = userContextServiceClient.getClient();
96
					Client userClient = userContextServiceClient.getClient();
93
				userClient.addAddressForUser(address, userinfo.getUserId(), (new Date()).getTime());
97
					userClient.addAddressForUser(address, userinfo.getUserId(), (new Date()).getTime(), false);
-
 
98
					List<Address> addresses = userClient.getPrimaryInfo(userinfo.getUserId(), userinfo.isSessionId()).getAddresses();
-
 
99
					long maxAddressId = 0;
-
 
100
					for(Address tempaddress: addresses){
-
 
101
						if(tempaddress.getId() > maxAddressId){
-
 
102
							maxAddressId = tempaddress.getId();
-
 
103
						}
-
 
104
					}
-
 
105
					this.addressId = maxAddressId;
-
 
106
					// to set the address in cart
-
 
107
					shoppingCartClient = new ShoppingCartClient();
-
 
108
					in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
109
					cartClient.addAddressToCart(userinfo.getCartId(), maxAddressId);
-
 
110
	
-
 
111
				} catch (Exception e) {
-
 
112
					e.printStackTrace();
-
 
113
					return new DefaultHttpHeaders("failure");
-
 
114
				}
94
				
115
				
-
 
116
				return new DefaultHttpHeaders("success");
-
 
117
			}else{
95
				/* to set the address in cart
118
				return new DefaultHttpHeaders("failure");
-
 
119
			}
-
 
120
		}
-
 
121
		if(action.equals("change")){
-
 
122
			try {
96
				shoppingCartClient = new ShoppingCartClient();
123
				shoppingCartClient = new ShoppingCartClient();
97
				in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
124
				in.shop2020.model.v1.shoppingcart.ShoppingCartService.Client cartClient = shoppingCartClient.getClient();
-
 
125
				long addressId = Long.parseLong(this.request.getParameter("addressid"));
98
				Cart cart = cartClient.getCurrentCart(userinfo.getUserId(), false);
126
				cartClient.addAddressToCart(userinfo.getCartId(), addressId);
99
				cart.setAddressId(addressId);
127
			} catch (TException e) {
100
				*/
128
				e.printStackTrace();
101
			} catch (Exception e) {
129
			} catch (Exception e) {
-
 
130
				// TODO Auto-generated catch block
102
				e.printStackTrace();
131
				e.printStackTrace();
103
				return new DefaultHttpHeaders("failure");
-
 
104
			}
132
			}
105
			
-
 
106
			return new DefaultHttpHeaders("success");
133
			return new DefaultHttpHeaders("success");
107
		}else{
-
 
108
			return new DefaultHttpHeaders("failure");
-
 
109
		}
134
		}
110
		
-
 
-
 
135
		return new DefaultHttpHeaders("failure");
111
	}
136
	}
112
 
137
 
113
    public void printParams(){
138
    public void printParams(){
114
    	for(String param : reqparams.keySet()) {
139
    	for(String param : reqparams.keySet()) {
115
    		log.info("param name is " + param);
140
    		log.info("param name is " + param);
Line 159... Line 184...
159
	}
184
	}
160
	
185
	
161
	public String getCssFileSnippet(){
186
	public String getCssFileSnippet(){
162
		return htmlSnippets.get("CSS_FILES");
187
		return htmlSnippets.get("CSS_FILES");
163
	}
188
	}
-
 
189
 
-
 
190
	public long getAddressId(){
-
 
191
		return this.addressId;
-
 
192
	}
164
}
193
}