Subversion Repositories SmartDukaan

Rev

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

Rev 5614 Rev 5716
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.datalogger.EventType;
3
import in.shop2020.datalogger.EventType;
-
 
4
import in.shop2020.logistics.LogisticsService.Client;
-
 
5
import in.shop2020.logistics.PickupStore;
-
 
6
 
4
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.user.Address;
8
import in.shop2020.model.v1.user.Address;
6
import in.shop2020.model.v1.user.AddressType;
9
import in.shop2020.model.v1.user.AddressType;
7
import in.shop2020.model.v1.user.Cart;
10
import in.shop2020.model.v1.user.Cart;
8
import in.shop2020.model.v1.user.Line;
11
import in.shop2020.model.v1.user.Line;
9
import in.shop2020.model.v1.user.User;
12
import in.shop2020.model.v1.user.User;
10
import in.shop2020.model.v1.user.UserContextService;
13
import in.shop2020.model.v1.user.UserContextService;
11
import in.shop2020.serving.utils.FormattingUtils;
14
import in.shop2020.serving.utils.FormattingUtils;
12
import in.shop2020.serving.utils.Utils;
15
import in.shop2020.serving.utils.Utils;
13
import in.shop2020.thrift.clients.CatalogClient;
16
import in.shop2020.thrift.clients.CatalogClient;
-
 
17
import in.shop2020.thrift.clients.LogisticsClient;
14
import in.shop2020.thrift.clients.UserClient;
18
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.utils.DataLogger;
19
import in.shop2020.utils.DataLogger;
16
 
20
 
17
import java.util.ArrayList;
21
import java.util.ArrayList;
18
import java.util.Collection;
22
import java.util.Collection;
Line 33... Line 37...
33
    @InterceptorRef("login")
37
    @InterceptorRef("login")
34
})
38
})
35
 
39
 
36
@Results({
40
@Results({
37
    @Result(name="redirect", type="redirectAction", 
41
    @Result(name="redirect", type="redirectAction", 
38
    		params = {"actionName" , "shipping"})
42
    		params = {"actionName" , "shipping", "st", "${selectedTab}"})
39
})
43
})
40
public class ShippingController extends BaseController{
44
public class ShippingController extends BaseController{
41
	
45
	
42
	private static Logger log = Logger.getLogger(ShippingController.class);
46
	private static Logger log = Logger.getLogger(ShippingController.class);
43
    
47
    
Line 50... Line 54...
50
	private String city;
54
	private String city;
51
	private String state = "";
55
	private String state = "";
52
	private String pincode;
56
	private String pincode;
53
	private String phone;
57
	private String phone;
54
	private String country;
58
	private String country;
-
 
59
	private String selectedTab = "myLocation";
55
	
60
	
56
	public ShippingController(){
61
	public ShippingController(){
57
		super();
62
		super();
58
	}
63
	}
59
	
64
	
Line 158... Line 163...
158
					return "redirect";				
163
					return "redirect";				
159
				}
164
				}
160
				
165
				
161
				if(action.equals("change"))	{
166
				if(action.equals("change"))	{
162
					addressId = Long.parseLong(this.request.getParameter("addressid"));
167
					addressId = Long.parseLong(this.request.getParameter("addressid"));
-
 
168
					if(request.getParameter("selectedTab").equals("HotSpot")) {
-
 
169
					    userClient.addStoreToCart(userinfo.getCartId(), addressId);
-
 
170
					} else {
163
					userClient.addAddressToCart(userinfo.getCartId(), addressId);
171
					    userClient.addAddressToCart(userinfo.getCartId(), addressId);
-
 
172
					}
164
					
173
					
165
					errorMsg = userClient.validateCart(userinfo.getCartId(), sourceId);
174
					errorMsg = userClient.validateCart(userinfo.getCartId(), sourceId);
166
                    DataLogger.logData(EventType.SHIPPINIG_ADD_CHANGE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
175
                    DataLogger.logData(EventType.SHIPPINIG_ADD_CHANGE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
167
                            Long.toString(userinfo.getCartId()), Long.toString(addressId));
176
                            Long.toString(userinfo.getCartId()), Long.toString(addressId));
168
					return "index";
177
					return "index";
Line 191... Line 200...
191
		String templateFile = "templates/shippingdetails.vm";
200
		String templateFile = "templates/shippingdetails.vm";
192
		List<Map<String,String>> items = null;
201
		List<Map<String,String>> items = null;
193
		double totalamount= 0.0;
202
		double totalamount= 0.0;
194
		List<Address> addresses = null;
203
		List<Address> addresses = null;
195
		long defaultAddressId = 0;
204
		long defaultAddressId = 0;
-
 
205
		long defaultStoreAddressId = 0;
196
		String phoneNumber = "";
206
		String phoneNumber = "";
-
 
207
		List<PickupStore> storeAddresses = null;
197
 
208
 
198
		CatalogClient catalogServiceClient  = null;
209
		CatalogClient catalogServiceClient  = null;
199
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
210
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
200
		UserClient userContextServiceClient = null;
211
		UserClient userContextServiceClient = null;
201
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
212
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
Line 240... Line 251...
240
			}
251
			}
241
			totalamount = cart.getTotalPrice();
252
			totalamount = cart.getTotalPrice();
242
			addresses = userClient.getAllAddressesForUser(userId);
253
			addresses = userClient.getAllAddressesForUser(userId);
243
			User user = userClient.getUserById(userId);
254
			User user = userClient.getUserById(userId);
244
			phoneNumber = user.getMobileNumber();
255
			phoneNumber = user.getMobileNumber();
-
 
256
			
-
 
257
			LogisticsClient logisticsServiceClient = new LogisticsClient();
-
 
258
            Client logisticsClient = logisticsServiceClient.getClient();
-
 
259
            storeAddresses = logisticsClient.getAllPickupStores();
-
 
260
            
-
 
261
            
245
 
262
 
246
			if(cart.isSetAddressId())	{
263
			if(cart.isSetAddressId())	{
247
				defaultAddressId = cart.getAddressId();
264
				defaultAddressId = cart.getAddressId();
248
			} else	{
265
			} else	{
249
				defaultAddressId = userClient.getDefaultAddressId(userId);
266
				defaultAddressId = userClient.getDefaultAddressId(userId);
250
			}
267
			}
-
 
268
			
-
 
269
			if(cart.isSetPickupStoreId())    {
-
 
270
                defaultStoreAddressId = cart.getPickupStoreId();
-
 
271
            }
251
	        
272
	        
252
			String couponCode = cart.getCouponCode();
273
			String couponCode = cart.getCouponCode();
253
	        context.put("couponcode", couponCode == null ? "" : couponCode);
274
	        context.put("couponcode", couponCode == null ? "" : couponCode);
254
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
275
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
255
	        
276
	        
Line 260... Line 281...
260
		context.put("phonenumber", phoneNumber);
281
		context.put("phonenumber", phoneNumber);
261
		context.put("items", items);
282
		context.put("items", items);
262
		context.put("totalamount", formattingUtils.formatPrice(totalamount));
283
		context.put("totalamount", formattingUtils.formatPrice(totalamount));
263
		context.put("addresses", addresses);
284
		context.put("addresses", addresses);
264
		context.put("defaultAddressId", defaultAddressId+"");
285
		context.put("defaultAddressId", defaultAddressId+"");
-
 
286
		context.put("defaultStoreAddressId", defaultStoreAddressId+"");
265
		context.put("errorMsg", errorMsg);
287
		context.put("errorMsg", errorMsg);
-
 
288
		context.put("selectedTab", selectedTab);
-
 
289
		context.put("storeAddresses", storeAddresses);
266
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
290
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
267
		return htmlString;
291
		return htmlString;
268
	}
292
	}
269
	
293
	
270
	public long getAddressId(){
294
	public long getAddressId(){
Line 348... Line 372...
348
			url = "?" + url;
372
			url = "?" + url;
349
		}
373
		}
350
		url = request.getRequestURI() + url;
374
		url = request.getRequestURI() + url;
351
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), url , 0, false);
375
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), url , 0, false);
352
	}
376
	}
-
 
377
 
-
 
378
    public String getSelectedTab() {
-
 
379
        return selectedTab;
-
 
380
    }
-
 
381
 
-
 
382
    public void setSelectedTab(String selectedTab) {
-
 
383
        this.selectedTab = selectedTab;
-
 
384
    }
-
 
385
    
-
 
386
    public void setSt(String selectedTab) {
-
 
387
        this.selectedTab = selectedTab;
-
 
388
    }
353
}
389
}
354
390