Subversion Repositories SmartDukaan

Rev

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

Rev 6736 Rev 6903
Line 28... Line 28...
28
import org.apache.struts2.convention.annotation.InterceptorRef;
28
import org.apache.struts2.convention.annotation.InterceptorRef;
29
import org.apache.struts2.convention.annotation.InterceptorRefs;
29
import org.apache.struts2.convention.annotation.InterceptorRefs;
30
import org.apache.struts2.convention.annotation.Result;
30
import org.apache.struts2.convention.annotation.Result;
31
import org.apache.struts2.convention.annotation.Results;
31
import org.apache.struts2.convention.annotation.Results;
32
import org.apache.thrift.TException;
32
import org.apache.thrift.TException;
-
 
33
import org.apache.thrift.transport.TTransportException;
33
import org.apache.velocity.VelocityContext;
34
import org.apache.velocity.VelocityContext;
34
 
35
 
35
@SuppressWarnings("serial")
36
@SuppressWarnings("serial")
36
@InterceptorRefs({
37
@InterceptorRefs({
37
    @InterceptorRef("myDefault"),
38
    @InterceptorRef("myDefault"),
Line 57... Line 58...
57
	private String pincode;
58
	private String pincode;
58
	private String phone;
59
	private String phone;
59
	private String country;
60
	private String country;
60
	private String selectedTab = "myLocation";
61
	private String selectedTab = "myLocation";
61
	
62
	
-
 
63
	private String dob;
-
 
64
    private String guardianName;
-
 
65
 
-
 
66
    private boolean isAnyItemInsured = false;
-
 
67
	
62
	private static List<PickupStore> storeAddresses = new ArrayList<PickupStore>();
68
	private static List<PickupStore> storeAddresses = new ArrayList<PickupStore>();
63
	private static final List<String> allZones = new ArrayList<String>();
69
	private static final List<String> allZones = new ArrayList<String>();
64
	    
70
	    
65
    static {
71
    static {
66
        try {
72
        try {
Line 89... Line 95...
89
    	try {
95
    	try {
90
			UserContextService.Client userClient = (new UserClient()).getClient();
96
			UserContextService.Client userClient = (new UserClient()).getClient();
91
			userClient.checkOut(cartId);
97
			userClient.checkOut(cartId);
92
			Cart cart = userClient.getCart(cartId);
98
			Cart cart = userClient.getCart(cartId);
93
			itemIdString = Utils.getItemIdStringInCart(cart);
99
			itemIdString = Utils.getItemIdStringInCart(cart);
-
 
100
			for(Line line : cart.getLines()) {
-
 
101
			    if(line.getInsurer() > 0) {
-
 
102
			        setAnyItemInsured(true);
-
 
103
			    }
-
 
104
			}
94
			long defaultAddressId = cart.getAddressId();
105
			long defaultAddressId = cart.getAddressId();
95
			if (defaultAddressId == 0) {
106
			if (defaultAddressId == 0) {
96
			    defaultAddressId = userClient.getDefaultAddressId(userId);
107
			    defaultAddressId = userClient.getDefaultAddressId(userId);
97
			}
108
			}
98
			log.info("The default address id of this user is: " + defaultAddressId);
109
			log.info("The default address id of this user is: " + defaultAddressId);
Line 159... Line 170...
159
					}
170
					}
160
					if (this.pincode.isEmpty()) {
171
					if (this.pincode.isEmpty()) {
161
						addActionError("Pincode is empty.");
172
						addActionError("Pincode is empty.");
162
						invalidInput = true;
173
						invalidInput = true;
163
					}
174
					}
-
 
175
					
164
					if (!invalidInput) {
176
					if (!invalidInput) {
165
						Address address = new Address();
177
						Address address = new Address();
166
						address.setName(this.name);
178
						address.setName(this.name);
167
						address.setLine1(this.line1);
179
						address.setLine1(this.line1);
168
						address.setLine2(this.line2);
180
						address.setLine2(this.line2);
Line 174... Line 186...
174
						address.setEnabled(true);
186
						address.setEnabled(true);
175
						address.setType(AddressType.HOME);
187
						address.setType(AddressType.HOME);
176
						long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
188
						long addressId = userClient.addAddressForUser(userinfo.getUserId(), address, false);
177
						userClient.addAddressToCart(userinfo.getCartId(), addressId);
189
						userClient.addAddressToCart(userinfo.getCartId(), addressId);
178
						addActionMessage("Address added successfully.");
190
						addActionMessage("Address added successfully.");
-
 
191
						try {
-
 
192
    						if (this.guardianName != null &&
-
 
193
                                this.dob != null && !this.guardianName.isEmpty() && !this.dob.isEmpty()) {
-
 
194
                                userClient.storeInsuranceSpecificDetails(addressId, dob, guardianName);
-
 
195
                            }
-
 
196
						} catch(Exception e) {
-
 
197
						    log.error("Error while adding insurance specific details for address : " + addressId + ", DOB : " + dob + " GuardianName : " + guardianName, e);
-
 
198
						}
179
                        DataLogger.logData(EventType.SHIPPINIG_ADD_ADDRESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), address.getName(),
199
                        DataLogger.logData(EventType.SHIPPINIG_ADD_ADDRESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), address.getName(),
180
                                        address.getCity(), address.getPhone(), address.getPin());
200
                                        address.getCity(), address.getPhone(), address.getPin());
181
					}
201
					}
182
					return "redirect";				
202
					return "redirect";				
183
				}
203
				}
Line 200... Line 220...
200
		    log.error("Error while adding address to the cart", e);
220
		    log.error("Error while adding address to the cart", e);
201
			return "failure";
221
			return "failure";
202
		}
222
		}
203
		return null;
223
		return null;
204
	}
224
	}
-
 
225
	
-
 
226
	public String cancelInsurance() {
-
 
227
	    try {
-
 
228
            in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
229
            boolean result = userClient.cancelInsurance(userinfo.getCartId());
-
 
230
            if (result == false) {
-
 
231
                return "failure";
-
 
232
            }
-
 
233
        } catch (Exception e) {
-
 
234
            log.error("Unable to cancel insurance for cart : " + userinfo.getCartId(), e);
-
 
235
            return "failure";
-
 
236
        }
-
 
237
        return null;
-
 
238
	}
-
 
239
	
-
 
240
	public String storeInsuranceDetails() {
-
 
241
	    try {
-
 
242
	        in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
243
	        boolean result = userClient.storeInsuranceSpecificDetails(addressId, dob, guardianName);
-
 
244
	        if (result == false) {
-
 
245
                return "failure";
-
 
246
            }
-
 
247
	    } catch (Exception e) {
-
 
248
	        log.error("Unable to store dob and guradianName for addressId : " + addressId, e);
-
 
249
	        return "failure";
-
 
250
	    }
-
 
251
	    return null;
-
 
252
	}
205
 
253
 
206
	public String getShippingHeaderSnippet() {
254
	public String getShippingHeaderSnippet() {
207
		String htmlString = "";
255
		String htmlString = "";
208
		VelocityContext context = new VelocityContext();
256
		VelocityContext context = new VelocityContext();
209
		String templateFile = "templates/shippingheader.vm";
257
		String templateFile = "templates/shippingheader.vm";
Line 221... Line 269...
221
		double totalamount= 0.0;
269
		double totalamount= 0.0;
222
		List<Address> addresses = null;
270
		List<Address> addresses = null;
223
		long defaultAddressId = 0;
271
		long defaultAddressId = 0;
224
		long defaultStoreAddressId = 0;
272
		long defaultStoreAddressId = 0;
225
		String phoneNumber = "";
273
		String phoneNumber = "";
-
 
274
        double totalInsurance = 0.0;
-
 
275
        boolean isAnyItemInsured = false;
226
 
276
 
227
		CatalogClient catalogServiceClient  = null;
277
		CatalogClient catalogServiceClient  = null;
228
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = null;
278
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = null;
229
		UserClient userContextServiceClient = null;
279
		UserClient userContextServiceClient = null;
230
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
280
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
Line 240... Line 290...
240
			Cart cart = userClient.getCart(cartId);
290
			Cart cart = userClient.getCart(cartId);
241
			List<Line> lineItems = cart.getLines();
291
			List<Line> lineItems = cart.getLines();
242
			
292
			
243
			if( ! lineItems.isEmpty())	{
293
			if( ! lineItems.isEmpty())	{
244
				items = new ArrayList<Map<String,String>>();
294
				items = new ArrayList<Map<String,String>>();
245
				
-
 
246
				for (Line line : lineItems) {
295
				for (Line line : lineItems) {
247
					Map<String, String> itemdetail = new HashMap<String, String>();
296
					Map<String, String> itemdetail = new HashMap<String, String>();
248
					Item item = catalogClient.getItemForSource(line.getItemId(), sourceId);
297
					Item item = catalogClient.getItemForSource(line.getItemId(), sourceId);
249
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
298
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
250
                                    + ((item.getModelName() != null) ? item.getModelName() + " " : "") 
299
                                    + ((item.getModelName() != null) ? item.getModelName() + " " : "") 
Line 262... Line 311...
262
					itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
311
					itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
263
					itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
312
					itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
264
					itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice((item.getSellingPrice()*line.getQuantity())));
313
					itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice((item.getSellingPrice()*line.getQuantity())));
265
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
314
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
266
					itemdetail.put("BEST_DEAL_TEXT", item.getBestDealText());
315
					itemdetail.put("BEST_DEAL_TEXT", item.getBestDealText());
-
 
316
					itemdetail.put("INSURANCE_AMOUNT", line.getInsuranceAmount() + "");
-
 
317
					itemdetail.put("INSURER", line.getInsurer() + "");
267
					items.add(itemdetail);
318
					items.add(itemdetail);
-
 
319
					totalInsurance += line.getInsuranceAmount();
-
 
320
					if(line.getInsurer() > 0) {
-
 
321
					    isAnyItemInsured = true;
-
 
322
					}
268
				}
323
				}
269
			}
324
			}
270
			totalamount = cart.getTotalPrice();
325
			totalamount = cart.getTotalPrice();
271
			addresses = userClient.getAllAddressesForUser(userId);
326
			addresses = userClient.getAllAddressesForUser(userId);
272
			User user = userClient.getUserById(userId);
327
			User user = userClient.getUserById(userId);
Line 280... Line 335...
280
			
335
			
281
			if(cart.isSetPickupStoreId())    {
336
			if(cart.isSetPickupStoreId())    {
282
                defaultStoreAddressId = cart.getPickupStoreId();
337
                defaultStoreAddressId = cart.getPickupStoreId();
283
            }
338
            }
284
	        
339
	        
-
 
340
			/*
-
 
341
			 *  ============================= START =====================================
-
 
342
			 *  The following code snippet is for extra details that are required for insurance purpose,
-
 
343
			 *  like father's/husband's name and Date of birth. If any item is insured in cart then we check
-
 
344
			 *  whether the user has any shipping addresses stored. If he has no previous addresses we ask
-
 
345
			 *  for those details 'in-Form' i.e. along with the address form. If he does have previous addresses,
-
 
346
			 *  we ask the user service if he has already stored insurance details corresponding to that address.
-
 
347
			 *  If such info is not present we ask for such detail in a "stand-Alone" form.
-
 
348
			 */
-
 
349
			
-
 
350
			if(isAnyItemInsured) {
-
 
351
			    if(addresses.size() == 0) {
-
 
352
			        context.put("insuranceDetailsRequired", "inForm");
-
 
353
			    } else {
-
 
354
			        if (!userClient.isInsuranceDetailPresent(defaultAddressId)) {
-
 
355
			            context.put("insuranceDetailsRequired", "standAlone");
-
 
356
			        } else {
-
 
357
			            context.put("insuranceDetailsRequired", "");
-
 
358
			        }
-
 
359
			    }
-
 
360
			}
-
 
361
			/*
-
 
362
			 * ============================== END ===========================================
-
 
363
			 */
-
 
364
			
285
			String couponCode = cart.getCouponCode();
365
			String couponCode = cart.getCouponCode();
286
	        context.put("couponcode", couponCode == null ? "" : couponCode);
366
	        context.put("couponcode", couponCode == null ? "" : couponCode);
287
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
367
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
-
 
368
	        context.put("discount", formattingUtils.formatPrice(cart.getDiscountedPrice() - cart.getTotalPrice()));
288
	        
369
	        
289
		} catch (Exception e)	{
370
		} catch (Exception e)	{
290
			log.error("Unable to get the shipping details", e);
371
			log.error("Unable to get the shipping details", e);
291
		}
372
		}
292
        
373
        
293
		context.put("phonenumber", phoneNumber);
374
		context.put("phonenumber", phoneNumber);
294
		context.put("items", items);
375
		context.put("items", items);
295
		context.put("totalamount", formattingUtils.formatPrice(totalamount));
376
		context.put("totalamount", formattingUtils.formatPrice(totalamount));
-
 
377
		context.put("totalInsurance", formattingUtils.formatPrice(totalInsurance));
296
		context.put("addresses", addresses);
378
		context.put("addresses", addresses);
297
		context.put("defaultAddressId", defaultAddressId+"");
379
		context.put("defaultAddressId", defaultAddressId+"");
298
		context.put("defaultStoreAddressId", defaultStoreAddressId+"");
380
		context.put("defaultStoreAddressId", defaultStoreAddressId+"");
299
		context.put("errorMsg", errorMsg);
381
		context.put("errorMsg", errorMsg);
300
		context.put("selectedTab", selectedTab);
382
		context.put("selectedTab", selectedTab);
301
		context.put("storeAddresses", storeAddresses);
383
		context.put("storeAddresses", storeAddresses);
302
		context.put("allZones", allZones);
384
		context.put("allZones", allZones);
-
 
385
		context.put("isAnyItemInsured", isAnyItemInsured + "");
303
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
386
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
304
		return htmlString;
387
		return htmlString;
305
	}
388
	}
306
	
389
	
307
	public long getAddressId(){
390
	public long getAddressId(){
Line 374... Line 457...
374
 
457
 
375
	public void setPhone(String phone) {
458
	public void setPhone(String phone) {
376
		this.phone = phone;
459
		this.phone = phone;
377
	}
460
	}
378
 
461
 
379
	@Override
-
 
380
	public String getHeaderSnippet() {
-
 
381
		String url = request.getQueryString();
-
 
382
		if (url == null) {
-
 
383
			url = "";
-
 
384
		} else {
-
 
385
			url = "?" + url;
-
 
386
		}
-
 
387
		url = request.getRequestURI() + url;
-
 
388
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false);
-
 
389
	}
-
 
390
 
-
 
391
    public String getSelectedTab() {
462
    public String getSelectedTab() {
392
        return selectedTab;
463
        return selectedTab;
393
    }
464
    }
394
 
465
 
395
    public void setSelectedTab(String selectedTab) {
466
    public void setSelectedTab(String selectedTab) {
Line 401... Line 472...
401
    }
472
    }
402
 
473
 
403
    public static List<String> getAllZones() {
474
    public static List<String> getAllZones() {
404
        return allZones;
475
        return allZones;
405
    }
476
    }
-
 
477
 
-
 
478
    public void setAnyItemInsured(boolean isAnyItemInsured) {
-
 
479
        this.isAnyItemInsured = isAnyItemInsured;
-
 
480
    }
-
 
481
 
-
 
482
    public boolean isAnyItemInsured() {
-
 
483
        return isAnyItemInsured;
-
 
484
    }
-
 
485
 
-
 
486
    public String getDob() {
-
 
487
        return dob;
-
 
488
    }
-
 
489
 
-
 
490
    public void setDob(String dob) {
-
 
491
        this.dob = dob;
-
 
492
    }
-
 
493
 
-
 
494
    public String getGuardianName() {
-
 
495
        return guardianName;
-
 
496
    }
-
 
497
 
-
 
498
    public void setGuardianName(String guardianName) {
-
 
499
        this.guardianName = guardianName;
-
 
500
    }
-
 
501
 
-
 
502
    public void setAddressId(long addressId) {
-
 
503
        this.addressId = addressId;
-
 
504
    }
406
}
505
}
407
506