Subversion Repositories SmartDukaan

Rev

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