Subversion Repositories SmartDukaan

Rev

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

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