Subversion Repositories SmartDukaan

Rev

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

Rev 832 Rev 839
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.Collection;
-
 
4
 
3
import in.shop2020.model.v1.user.Address;
5
import in.shop2020.model.v1.user.Address;
4
import in.shop2020.model.v1.user.AddressType;
6
import in.shop2020.model.v1.user.AddressType;
5
import in.shop2020.model.v1.user.UserContextService;
7
import in.shop2020.model.v1.user.UserContextService;
6
import in.shop2020.serving.controllers.BaseController;
8
import in.shop2020.serving.controllers.BaseController;
-
 
9
import in.shop2020.serving.utils.Utils;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
10
import in.shop2020.thrift.clients.UserContextServiceClient;
8
 
11
 
9
 
12
 
10
import org.apache.juli.logging.Log;
-
 
11
import org.apache.juli.logging.LogFactory;
-
 
12
import org.apache.log4j.Logger;
13
import org.apache.log4j.Logger;
13
import org.apache.struts2.convention.annotation.InterceptorRef;
14
import org.apache.struts2.convention.annotation.InterceptorRef;
14
import org.apache.struts2.convention.annotation.InterceptorRefs;
15
import org.apache.struts2.convention.annotation.InterceptorRefs;
15
import org.apache.struts2.convention.annotation.Result;
16
import org.apache.struts2.convention.annotation.Result;
16
import org.apache.struts2.convention.annotation.Results;
17
import org.apache.struts2.convention.annotation.Results;
Line 34... Line 35...
34
	
35
	
35
	private String name;
36
	private String name;
36
	private String line1;
37
	private String line1;
37
	private String line2;
38
	private String line2;
38
	private String city;
39
	private String city;
39
	private String state;
40
	private String state = "";
40
	private String pincode;
41
	private String pincode;
41
	private String phone;
42
	private String phone;
42
	private String country;
43
	private String country;
43
	
44
	
44
	public ShippingController(){
45
	public ShippingController(){
Line 66... Line 67...
66
			// user is proceeding to pay.
67
			// user is proceeding to pay.
67
			e.printStackTrace();
68
			e.printStackTrace();
68
		}
69
		}
69
    	// in case this page is redirected from payment failure
70
    	// in case this page is redirected from payment failure
70
		
71
		
71
		if(getActionErrors()!=null){
72
		Collection<String> actionErrors = getActionErrors();
72
			this.errorMsg = getActionErrors().toArray()[0].toString();
73
		if(actionErrors != null && !actionErrors.isEmpty()){
-
 
74
			for (String str : actionErrors) {
-
 
75
			    errorMsg += "<BR/>" + str;
-
 
76
			}
73
		}
77
		}
74
		
78
		
75
		htmlSnippets.put("SHIPPING_HEADER", pageLoader.getShippingHeaderHtml());
79
		htmlSnippets.put("SHIPPING_HEADER", pageLoader.getShippingHeaderHtml());
76
		htmlSnippets.put("SHIPPING_DETAILS", pageLoader.getShippingDetailsHtml(userinfo.getCartId(), errorMsg));
80
		htmlSnippets.put("SHIPPING_DETAILS", pageLoader.getShippingDetailsHtml(userinfo.getCartId(), errorMsg));
77
		
81
		
Line 92... Line 96...
92
			userContextServiceClient = new UserContextServiceClient();
96
			userContextServiceClient = new UserContextServiceClient();
93
			userClient = userContextServiceClient.getClient();
97
			userClient = userContextServiceClient.getClient();
94
			
98
			
95
			if(action != null){
99
			if(action != null){
96
				if(action.equals("add")){
100
				if(action.equals("add")){
-
 
101
					boolean invalidInput = false;
-
 
102
					if (!Utils.validatePin(this.pincode)) {
-
 
103
						addActionError("Invalid pincode.");
-
 
104
						invalidInput = true;
-
 
105
					}
-
 
106
					if (!Utils.validatePhone(this.phone)) {
-
 
107
						addActionError("Invalid phone number.");
-
 
108
						invalidInput = true;
-
 
109
					}
-
 
110
					if (this.line1.isEmpty()) {
-
 
111
						addActionError("Address line1 is empty.");
-
 
112
						invalidInput = true;
-
 
113
					}
-
 
114
					if (this.city.isEmpty()) {
-
 
115
						addActionError("City name is empty.");
-
 
116
						invalidInput = true;
-
 
117
					}
-
 
118
					if (this.state.isEmpty()) {
-
 
119
						addActionError("State name is empty.");
-
 
120
						invalidInput = true;
-
 
121
					}
-
 
122
					if (!invalidInput) {
97
					Address address = new Address();
123
						Address address = new Address();
98
					address.setName(this.name);
124
						address.setName(this.name);
99
					address.setLine1(this.line1);
125
						address.setLine1(this.line1);
100
					address.setLine2(this.line2);
126
						address.setLine2(this.line2);
101
					address.setCity(this.city);
127
						address.setCity(this.city);
102
					address.setState(this.state);
128
						address.setState(this.state);
103
					address.setPin(this.pincode);
129
						address.setPin(this.pincode);
104
					address.setPhone(this.phone);
130
						address.setPhone(this.phone);
105
					address.setCountry(this.country);
131
						address.setCountry(this.country);
106
					address.setEnabled(true);
132
						address.setEnabled(true);
107
					address.setType(AddressType.HOME);
133
						address.setType(AddressType.HOME);
108
					long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
134
						long addressId = userClient.addAddressForUser(
-
 
135
								userinfo.getUserId(), address, false);
109
					userClient.addAddressToCart(userinfo.getCartId(), addressId);
136
						userClient.addAddressToCart(userinfo.getCartId(),
-
 
137
								addressId);
110
					addActionMessage("Address added successfully.");
138
						addActionMessage("Address added successfully.");
-
 
139
					}
111
					return "redirect";
140
					return "redirect";				
112
				}
141
				}
113
				
142
				
114
				if(action.equals("change")){
143
				if(action.equals("change")){
115
					long addressId = Long.parseLong(this.request.getParameter("addressid"));
144
					long addressId = Long.parseLong(this.request.getParameter("addressid"));
116
					userClient.addAddressToCart(userinfo.getCartId(), addressId);
145
					userClient.addAddressToCart(userinfo.getCartId(), addressId);