Subversion Repositories SmartDukaan

Rev

Rev 9840 | Rev 11829 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
410 rajveer 1
package in.shop2020.serving.controllers;
2
 
2263 vikas 3
import in.shop2020.datalogger.EventType;
7839 rajveer 4
import in.shop2020.logistics.DeliveryType;
5945 mandeep.dh 5
import in.shop2020.model.v1.catalog.CatalogService.Client;
6903 anupam.sin 6
import in.shop2020.model.v1.catalog.Insurer;
9301 kshitij.so 7
import in.shop2020.model.v1.catalog.InsurerType;
1981 varun.gupt 8
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.user.Cart;
10
import in.shop2020.model.v1.user.Line;
555 chandransh 11
import in.shop2020.model.v1.user.ShoppingCartException;
572 chandransh 12
import in.shop2020.model.v1.user.UserContextService;
3599 rajveer 13
import in.shop2020.serving.services.ContentServingService;
2137 chandransh 14
import in.shop2020.serving.utils.FormattingUtils;
3599 rajveer 15
import in.shop2020.serving.utils.SnippetType;
3126 rajveer 16
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.UserClient;
2511 vikas 18
import in.shop2020.utils.DataLogger;
410 rajveer 19
 
2419 vikas 20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.List;
23
import java.util.Map;
24
import java.util.StringTokenizer;
25
 
6736 amit.gupta 26
import org.apache.commons.lang.StringUtils;
832 rajveer 27
import org.apache.log4j.Logger;
1614 rajveer 28
import org.apache.struts2.convention.annotation.Action;
4046 varun.gupt 29
import org.apache.struts2.convention.annotation.Actions;
1614 rajveer 30
import org.apache.struts2.convention.annotation.InterceptorRef;
801 rajveer 31
import org.apache.struts2.convention.annotation.Result;
1614 rajveer 32
import org.apache.struts2.convention.annotation.Results;
410 rajveer 33
import org.apache.struts2.interceptor.ParameterAware;
34
import org.apache.thrift.TException;
35
 
1614 rajveer 36
 
37
@Results({
9301 kshitij.so 38
	@Result(name = "index", location = "cart-index.vm"),
4046 varun.gupt 39
	@Result(name="redirect", type="redirectAction", params = {"actionName" , "cart"}),
1614 rajveer 40
	@Result(name="failure", location="cart-failure.vm"),
41
	@Result(name="success", location="cart-success.vm")
42
})
43
 
507 rajveer 44
public class CartController extends BaseController implements ParameterAware{
9301 kshitij.so 45
 
410 rajveer 46
	private static final long serialVersionUID = 1L;
1957 vikas 47
	private static Logger log = Logger.getLogger(Class.class);
507 rajveer 48
	Map<String, String[]> reqparams = null;
9301 kshitij.so 49
 
4046 varun.gupt 50
	private int variationId = 0;
9301 kshitij.so 51
	private String totalamount;
52
 
9840 amit.gupta 53
	private String errorMsg = null;
3970 varun.gupt 54
	private String cartMsg = "";
9301 kshitij.so 55
 
1981 varun.gupt 56
	private String pincode = "110001";
9301 kshitij.so 57
 
1981 varun.gupt 58
	private String couponCode = null;
9301 kshitij.so 59
 
2137 chandransh 60
	private String discountedAmount;
9301 kshitij.so 61
 
2810 rajveer 62
	private long itemId;
9301 kshitij.so 63
	private String insuranceResult;
64
 
65
	private boolean toInsure;
66
	private long productId;
67
 
68
	private int insurerType; 
69
 
410 rajveer 70
	public CartController(){
507 rajveer 71
		super();
72
	}
9301 kshitij.so 73
 
74
	// GET /cart
4046 varun.gupt 75
	@Actions({
76
		@Action(value="cart", interceptorRefs={@InterceptorRef("myDefault")}),
4453 varun.gupt 77
		@Action(value="cart1", interceptorRefs={@InterceptorRef("myDefault")})
4046 varun.gupt 78
	})
4344 anupam.sin 79
	public String index()  {
4046 varun.gupt 80
		this.setVariationId(request.getRequestURI());
81
		log.info(this.getVariationId());
1614 rajveer 82
 
4046 varun.gupt 83
		long cartId = userinfo.getCartId();
9301 kshitij.so 84
 
85
		if(cartId != -1){
86
			try {
87
				UserContextService.Client userClient = (new UserClient()).getClient();
88
				List<String> cartResponse  = userClient.validateCart(cartId, sourceId);
89
				errorMsg = cartResponse.get(0);
90
				if(StringUtils.isNotEmpty(cartResponse.get(1))) {
91
					addActionMessage(cartResponse.get(1));
92
				}
93
				log.info("Cart Change/EMI Message rcvd from the service is:" + errorMsg);
94
 
95
				// As per ticket #119 in trac
96
				Cart cart = userClient.getCart(cartId);
97
				int totalItems = cart.getLinesSize();
98
				double totalAmount = cart.getTotalPrice();
4046 varun.gupt 99
				userinfo.setTotalItems(totalItems);
100
				userinfo.setTotalAmount(totalAmount);
9301 kshitij.so 101
			} catch (Exception e) {
102
				// This exception can be ignored for showing the cart. Not so
103
				// innocent when this occurs at the time of checkout or when the
104
				// user is proceeding to pay.
105
				log.warn("Unable to validate the cart: ", e);
106
			}
107
		}
3970 varun.gupt 108
		return "index";
109
	}
4046 varun.gupt 110
 
572 chandransh 111
	// POST /entity
1614 rajveer 112
 
113
	@Action(value="addtocart",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
572 chandransh 114
	public String create() {
115
		log.info("CartController.create");
555 chandransh 116
 
572 chandransh 117
		printParams();
118
 
119
		long userId = userinfo.getUserId();
120
		long cartId = userinfo.getCartId();
121
 
1614 rajveer 122
		log.info("user id is " + userId);
123
		log.info("cart id is " + cartId);
9301 kshitij.so 124
 
572 chandransh 125
		log.info("item id is " + this.reqparams.get("productid"));
9301 kshitij.so 126
 
637 rajveer 127
		String itemIds = "";
572 chandransh 128
		if (this.reqparams.get("productid") != null) {
129
			itemIds = this.reqparams.get("productid")[0];
637 rajveer 130
		}else{
131
			return "failure";
572 chandransh 132
		}
9301 kshitij.so 133
 
572 chandransh 134
		StringTokenizer tokenizer = new StringTokenizer(itemIds, "_");
135
		while (tokenizer.hasMoreTokens()) {
2810 rajveer 136
			itemId = Long.parseLong(tokenizer.nextToken());
572 chandransh 137
 
138
			try {
3126 rajveer 139
				UserClient userServiceClient = new UserClient();
572 chandransh 140
				UserContextService.Client userClient = userServiceClient.getClient();
762 rajveer 141
				if (cartId == 0){
5342 rajveer 142
					cartId = userClient.getUserById(userId).getActiveCartId();
762 rajveer 143
				}
3561 rajveer 144
				// If we add multiple items to cart and get some message from service, 
145
				// first message to be preserved and presented to the user.
2099 rajveer 146
				if(cartMsg.equals("")){
9301 kshitij.so 147
					cartMsg = userClient.addItemToCart(cartId, itemId, 1, sourceId);
148
				}else{
149
					userClient.addItemToCart(cartId, itemId, 1, sourceId);
150
				}
762 rajveer 151
				userinfo.setCartId(cartId);
152
				int totalItems = userClient.getCart(cartId).getLinesSize();
153
				userinfo.setTotalItems(totalItems);
572 chandransh 154
			} catch (TException e) {
9301 kshitij.so 155
				log.error("Unable to create or add to cart because of: ", e);
572 chandransh 156
			} catch (Exception e) {
9301 kshitij.so 157
				log.error("Unable to create or add to cart because of: ", e);
507 rajveer 158
			}
159
 
572 chandransh 160
		}
9301 kshitij.so 161
		DataLogger.logData(EventType.ADD_TO_CART, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
162
				Long.toString(cartId), itemIds);
572 chandransh 163
		return "success";
164
	}		
165
 
1614 rajveer 166
 
4217 varun.gupt 167
	// DELETE /entity
168
	public String destroy()	{
169
		log.info("CartController.destroy");
170
		printParams();
171
		log.info("item id is " + this.request.getParameter("productid"));
9301 kshitij.so 172
 
4217 varun.gupt 173
		String itemIdString = this.request.getParameter("productid");
174
		itemId = Long.parseLong(itemIdString);
175
 
176
		if(userinfo.getCartId() == -1)	{
177
			log.info("Cart does not exist. Nothing to delete.");
178
		} else	{
179
			if(deleteItemFromCart(userinfo.getCartId(), itemId, userinfo.getUserId(), userinfo.isSessionId()))	{
180
				updateUserSessionInfo(userinfo.getCartId());
181
				DataLogger.logData(EventType.DELETE_FROM_CART, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
9301 kshitij.so 182
						Long.toString(userinfo.getCartId()), itemIdString);
4217 varun.gupt 183
				return "redirect";
507 rajveer 184
			}
185
		}
4217 varun.gupt 186
		return "redirect";
187
	}
188
 
189
	// DELETE /entity
190
	public String update() {
191
		log.info("CartController.update");
192
		printParams();
193
		log.info("item id is " + this.request.getParameter("productid"));
194
		log.info("item quantity is " + this.request.getParameter("quantity"));
195
		String itemIdString = this.request.getParameter("productid");
196
		String quantityString = this.request.getParameter("quantity");
197
		long itemId = Long.parseLong(itemIdString);
198
		long quantity = Long.parseLong(quantityString);
199
 
200
		if(quantity <= 0)	{
201
			log.info("Not valid item quantity. Unable to change item quantity.");
202
		} else	{
203
			if(updateItemQuantityInCart(userinfo.getCartId(), itemId, quantity))	{
204
				DataLogger.logData(EventType.UPDATE_CART_QUANTITY, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
9301 kshitij.so 205
						Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
4217 varun.gupt 206
				return "redirect";
507 rajveer 207
			}
4217 varun.gupt 208
		}
209
		DataLogger.logData(EventType.UPDATE_CART_QUANTITY_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
9301 kshitij.so 210
				Long.toString(userinfo.getCartId()), Long.toString(itemId), Long.toString(quantity));
4217 varun.gupt 211
		addActionError("Unable to update the quantity");
212
		return "redirect";
213
	}
507 rajveer 214
 
9301 kshitij.so 215
	public void printParams(){
216
		for(String param : reqparams.keySet()) {
217
			log.info("param name is " + param);
218
			log.info("param first is " + reqparams.get(param)[0]);
219
		}
220
		log.info(this.reqparams);
221
	}
222
 
762 rajveer 223
	private boolean updateItemQuantityInCart(long cartId, long itemId, long quantity){
224
		try {
3126 rajveer 225
			UserClient userContextServiceClient = new UserClient();
762 rajveer 226
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
227
 
3562 rajveer 228
			userClient.addItemToCart(cartId, itemId, quantity, sourceId);
762 rajveer 229
			return true;
230
		} catch (ShoppingCartException e) {
9301 kshitij.so 231
			log.error("Unable to update the item quantity in the cart: ", e);
762 rajveer 232
		} catch (TException e) {
9301 kshitij.so 233
			log.error("Unable to update the item quantity in the cart: ", e);
762 rajveer 234
		} catch (Exception e) {
9301 kshitij.so 235
			log.error("Unable to update the item quantity in the cart: ", e);
762 rajveer 236
		}
237
		return false;
238
	}
9301 kshitij.so 239
 
762 rajveer 240
	private boolean deleteItemFromCart(long cartId, long catalogItemId, long userId, boolean isSessionId){
241
		try {
3126 rajveer 242
			UserClient userContextServiceClient = new UserClient();
762 rajveer 243
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
9301 kshitij.so 244
 
762 rajveer 245
			userClient.deleteItemFromCart(cartId, catalogItemId);
4217 varun.gupt 246
			return true;
762 rajveer 247
		} catch (ShoppingCartException e) {
9301 kshitij.so 248
			log.error("Unable to delete item from cart: ", e);
762 rajveer 249
		} catch (TException e) {
9301 kshitij.so 250
			log.error("Unable to delete item from cart: ", e);
762 rajveer 251
		} catch (Exception e) {
9301 kshitij.so 252
			log.error("Unable to delete item from cart: ", e);
762 rajveer 253
		}
9301 kshitij.so 254
 
762 rajveer 255
		return false;
256
	}
257
 
3830 chandransh 258
	private void updateUserSessionInfo(long cartId) {
3126 rajveer 259
		UserClient userContextServiceClient = null;
762 rajveer 260
		try {
3126 rajveer 261
			userContextServiceClient = new UserClient();
762 rajveer 262
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
3830 chandransh 263
			Cart cart = userClient.getCart(cartId);
264
			userinfo.setTotalItems(cart.getLinesSize());
265
			userinfo.setTotalAmount(cart.getTotalPrice());
762 rajveer 266
		} catch (ShoppingCartException e) {
9301 kshitij.so 267
			log.error("Unable to get the cart from service: ", e);
762 rajveer 268
		} catch (TException e) {
9301 kshitij.so 269
			log.error("Unable to get the cart from service: ", e);
762 rajveer 270
		} catch (Exception e) {
9301 kshitij.so 271
			log.error("Unable to get the cart from service: ", e);
762 rajveer 272
		}
273
	}
9301 kshitij.so 274
 
1981 varun.gupt 275
	public List<Map<String,String>> getCartItems() {
9301 kshitij.so 276
		List<Map<String,String>> items = null;
762 rajveer 277
 
9301 kshitij.so 278
		UserClient userServiceClient = null;
279
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
280
		CatalogClient catalogServiceClient  = null;
281
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = null;
762 rajveer 282
 
9301 kshitij.so 283
		FormattingUtils formattingUtils = new FormattingUtils();
1981 varun.gupt 284
 
9301 kshitij.so 285
		try    {
286
			catalogServiceClient = new CatalogClient();
287
			catalogClient = catalogServiceClient.getClient();
288
			userServiceClient = new UserClient();
289
			userClient = userServiceClient.getClient();
290
 
291
			pincode = userClient.getDefaultPincode(userinfo.getUserId());
292
			Cart cart = userClient.getCart(userinfo.getCartId());
293
			List<Line> lineItems = cart.getLines();
294
			double totalInsuranceAmount = 0.0;
295
			boolean isAnyItemInsured = false;
296
			if(lineItems.size() != 0)  {
297
				items = new ArrayList<Map<String,String>>();
298
 
299
				for (Line line : lineItems)    {
300
					Map<String, String> itemdetail = new HashMap<String, String>();
301
 
302
					double insuranceAmount = 0;
303
					Item item = catalogClient.getItemForSource(line.getItemId(), sourceId);
304
					long prefferedInsurer  = catalogClient.getPrefferedInsurerForItem(line.getItemId(), InsurerType.DEVICE);
305
					long dataProtectionInsurer = catalogClient.getPrefferedInsurerForItem(line.getItemId(), InsurerType.DATA);
306
					Insurer insurer = null;
307
 
308
					if(line.getInsurer() != 0) {
309
						insuranceAmount = catalogClient.getInsuranceAmount(item.getId(), 
310
								(line.getDiscountedPrice() == 0 ? line.getActualPrice() : line.getDiscountedPrice()),
311
								prefferedInsurer, 
312
								(long)line.getQuantity());
313
						isAnyItemInsured = true;
314
					} else if (prefferedInsurer != 0) {
315
						insuranceAmount = catalogClient.getInsuranceAmount(item.getId(), 
316
								(line.getDiscountedPrice() == 0 ? line.getActualPrice() : line.getDiscountedPrice()),
317
								prefferedInsurer, 
318
								(long)line.getQuantity());
319
					} else {
320
						insuranceAmount = 0;
321
					}
322
 
323
					double oneAssistAmount = 0;
324
 
325
					if (line.getDataProtectionInsurer()!=0){
326
						/*
327
						 * We can call service to get amount for one assist.
328
                    	oneAssistAmount = catalogClient.getInsuranceAmount(item.getId(), 
329
								(line.getDiscountedPrice() == 0 ? line.getActualPrice() : line.getDiscountedPrice()),
330
								dataProtectionInsurer, 
331
								(long)line.getQuantity());*/
332
						oneAssistAmount =449.0 * line.getQuantity();
333
					}
334
					else if (dataProtectionInsurer != 0) {
335
						/*oneAssistAmount = catalogClient.getInsuranceAmount(item.getId(), 
336
								(line.getDiscountedPrice() == 0 ? line.getActualPrice() : line.getDiscountedPrice()),
337
								dataProtectionInsurer, 
338
								(long)line.getQuantity());
339
						 */
340
						oneAssistAmount =449.0 * line.getQuantity();
341
					} else {
342
						oneAssistAmount = 0;
343
					}
344
 
345
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
346
					+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
347
					+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" );
348
 
349
					String itemColor = "";
350
					if(item.getColor() != null && !item.getColor().trim().equals("NA"))
351
						itemColor = "Color - " + item.getColor();
352
 
353
					itemdetail.put("ITEM_NAME", itemName);
354
					itemdetail.put("ITEM_COLOR", itemColor);
355
					itemdetail.put("ITEM_ID", line.getItemId() + "");
356
					itemdetail.put("CATALOG_ID", item.getCatalogItemId() + "");
357
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity()) + "");
358
					itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
359
					itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
360
					itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice(((item.getSellingPrice() * line.getQuantity()))));
361
					itemdetail.put("SHIPPING_TIME", EstimateController.getDeliveryDateString(line.getEstimate(), DeliveryType.PREPAID));
362
					itemdetail.put("COD_SHIPPING_TIME", EstimateController.getDeliveryDateString(line.getEstimate(), DeliveryType.COD));
11653 amit.gupta 363
					itemdetail.put("BEST_DEAL_TEXT", line.isSetDealText()? line.getDealText() : item.getBestDealText());
9301 kshitij.so 364
					itemdetail.put("IS_INSURABLE", prefferedInsurer + "");
6903 anupam.sin 365
					itemdetail.put("IS_INSURED", (line.getInsurer() == 0 ? false : true) + "");
366
					itemdetail.put("INSURANCE_AMOUNT", insuranceAmount + "");
9301 kshitij.so 367
					itemdetail.put("DATA_PROTECTION_INSURER", dataProtectionInsurer + "");
368
					itemdetail.put("IS_DATA_PROTECTED", (line.getDataProtectionInsurer() == 0 ? false : true) + "");
369
					itemdetail.put("ONE_ASSIST_AMOUNT", oneAssistAmount + "");
1981 varun.gupt 370
 
6903 anupam.sin 371
					totalInsuranceAmount += insuranceAmount;
9301 kshitij.so 372
					items.add(itemdetail);
373
				}
374
			}
375
 
376
			//            if(isAnyItemInsured == false) {
377
			//                totalamount = formattingUtils.formatPrice(cart.getTotalPrice() + totalInsuranceAmount);
378
			//                discountedAmount = formattingUtils.formatPrice(cart.getDiscountedPrice() + totalInsuranceAmount);
379
			//            } else {
380
			totalamount = formattingUtils.formatPrice(cart.getTotalPrice());
381
			discountedAmount = formattingUtils.formatPrice(cart.getDiscountedPrice());
382
			//            }
383
 
384
			couponCode = cart.getCouponCode() == null ? "" : cart.getCouponCode();
385
		} catch (Exception e){
386
			log.error("Unable to get the cart details becasue of: ", e);
387
		}
388
		return items;
507 rajveer 389
	}
9301 kshitij.so 390
 
6903 anupam.sin 391
	public String insureItem() {
9301 kshitij.so 392
		//TODO : Call a method in userservice that insures the item.
393
		insuranceResult = "";
394
		try {
395
			UserContextService.Client usc = new UserClient().getClient();
396
			if(usc.insureItem(productId, userinfo.getCartId(), toInsure, insurerType)) {
397
				setInsuranceResult("SUCCESS");
398
			} else {
399
				setInsuranceResult("FAILURE");
400
			}
401
		} catch (Exception e) {
402
			log.error("Unable to insure item : " + productId + " for cart : " + userinfo.getCartId(), e);
403
			setInsuranceResult("FAILURE");
404
		}
405
		return "insurance-result";
6903 anupam.sin 406
	}
1981 varun.gupt 407
 
3080 rajveer 408
	public long getItemId(){
409
		return this.itemId;
410
	}
9301 kshitij.so 411
 
2137 chandransh 412
	public String getTotalAmount() {
9301 kshitij.so 413
		return totalamount;
1981 varun.gupt 414
	}
9301 kshitij.so 415
 
1981 varun.gupt 416
	public String getPinCode() {
9301 kshitij.so 417
		return pincode;
507 rajveer 418
	}
9301 kshitij.so 419
 
1981 varun.gupt 420
	public String getCouponCode()  {
9301 kshitij.so 421
		return couponCode;
1981 varun.gupt 422
	}
9301 kshitij.so 423
 
1981 varun.gupt 424
	public String getDiscountedAmount()   {
9301 kshitij.so 425
		return discountedAmount;
1981 varun.gupt 426
	}
9301 kshitij.so 427
 
1981 varun.gupt 428
	public String getErrorMsg()    {
9301 kshitij.so 429
		return errorMsg;
1981 varun.gupt 430
	}
9301 kshitij.so 431
 
507 rajveer 432
	public long getNumberOfItems(){
433
		return userinfo.getTotalItems();
434
	}
650 rajveer 435
 
2036 rajveer 436
	public String getCartMsg(){
9301 kshitij.so 437
		if(cartMsg.equals("")){
438
			return null;
439
		}
440
		return cartMsg;
2036 rajveer 441
	}
9301 kshitij.so 442
 
2810 rajveer 443
	public String getSnippets(){
9301 kshitij.so 444
		String snippets = "";
3126 rajveer 445
		CatalogClient csc;
2810 rajveer 446
		try {
3126 rajveer 447
			csc = new CatalogClient();
2810 rajveer 448
			List<Long> similarItems = csc.getClient().getSimilarItemsCatalogIds(0, 4, itemId);
449
			for(Long catalogId: similarItems){
3599 rajveer 450
				snippets = snippets + ContentServingService.getSnippet(SnippetType.WIDGET_SNIPPET, catalogId+"", sourceId);
2810 rajveer 451
			}
452
		} catch (Exception e) {
453
			log.error("Unable to initialise Catalogservice Client");
454
		}	    
9301 kshitij.so 455
		return snippets;
456
	}
457
 
650 rajveer 458
	@Override
459
	public void setParameters(Map<String, String[]> parameters) {
460
		this.reqparams = parameters;	
461
	}
9301 kshitij.so 462
 
3903 varun.gupt 463
	@Override
464
	public String getHeaderSnippet() {
465
		String url = request.getQueryString();
466
		if (url == null) {
467
			url = "";
468
		} else {
469
			url = "?" + url;
470
		}
471
		url = request.getRequestURI() + url;
6152 amit.gupta 472
		return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false);
3903 varun.gupt 473
	}
9301 kshitij.so 474
 
4222 varun.gupt 475
	public boolean isUserLoggedIn()	{
476
		return userinfo.isLoggedIn();
477
	}
9301 kshitij.so 478
 
4046 varun.gupt 479
	public void setVariationId(String uri)	{
480
		if (uri.equals("/cart1"))	{
481
			this.variationId = 1;
482
		}
3970 varun.gupt 483
	}
9301 kshitij.so 484
 
4046 varun.gupt 485
	public int getVariationId()	{
486
		return this.variationId;
3970 varun.gupt 487
	}
9301 kshitij.so 488
 
5228 amit.gupta 489
	public String getActionMessage(){
490
		if(cartMsg.contains("out of stock")){
491
			return "Notify me when this product is in stock.";
492
		}else {
493
			return "Notify me when this product is available.";
494
		}
495
	}
9301 kshitij.so 496
 
5228 amit.gupta 497
	public String getOfferNote(){
498
		String note = null;
499
		if(cartMsg.contains("out of stock")){
500
			return note;
501
		}
502
		else {
503
			try {
9301 kshitij.so 504
				CatalogClient catalogServiceClient = new CatalogClient();
505
				Client catalogClient = catalogServiceClient.getClient();
506
				Item it = catalogClient.getItem(itemId);
507
				note = it.getBestDealText();
5228 amit.gupta 508
			} catch (Exception e)  {
509
				log.error("Unable to get the offertext because of: ", e);
510
			}
511
		}
512
		return note;
513
	}
6903 anupam.sin 514
 
9301 kshitij.so 515
	public String getInsuranceResult() {
516
		return insuranceResult;
517
	}
6903 anupam.sin 518
 
9301 kshitij.so 519
	public void setInsuranceResult(String insuranceResult) {
520
		this.insuranceResult = insuranceResult;
521
	}
6903 anupam.sin 522
 
9301 kshitij.so 523
	public void setToInsure(boolean toInsure) {
524
		this.toInsure = toInsure;
525
	}
6903 anupam.sin 526
 
9301 kshitij.so 527
	public boolean getToInsure() {
528
		return toInsure;
529
	}
6903 anupam.sin 530
 
9301 kshitij.so 531
	public long getProductId() {
532
		return productId;
533
	}
6903 anupam.sin 534
 
9301 kshitij.so 535
	public void setProductId(long productId) {
536
		this.productId = productId;
537
	}
538
 
539
	public void setInsurerType(int insurerType) {
540
		log.info("set insurerType"+insurerType);
541
		this.insurerType = insurerType;
542
	}
543
 
544
	public long getInsurerType() {
545
		return insurerType;
546
	}
5228 amit.gupta 547
}