Subversion Repositories SmartDukaan

Rev

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

Rev 3076 Rev 3101
Line 9... Line 9...
9
import in.shop2020.model.v1.user.User;
9
import in.shop2020.model.v1.user.User;
10
import in.shop2020.model.v1.user.UserContextService;
10
import in.shop2020.model.v1.user.UserContextService;
11
import in.shop2020.serving.utils.FormattingUtils;
11
import in.shop2020.serving.utils.FormattingUtils;
12
import in.shop2020.serving.utils.Utils;
12
import in.shop2020.serving.utils.Utils;
13
import in.shop2020.thrift.clients.CatalogServiceClient;
13
import in.shop2020.thrift.clients.CatalogServiceClient;
14
import in.shop2020.thrift.clients.LogisticsServiceClient;
-
 
15
import in.shop2020.thrift.clients.UserContextServiceClient;
14
import in.shop2020.thrift.clients.UserContextServiceClient;
16
import in.shop2020.utils.DataLogger;
15
import in.shop2020.utils.DataLogger;
17
 
16
 
18
import java.util.ArrayList;
17
import java.util.ArrayList;
19
import java.util.Collection;
18
import java.util.Collection;
20
import java.util.HashMap;
19
import java.util.HashMap;
21
import java.util.List;
20
import java.util.List;
22
import java.util.Map;
21
import java.util.Map;
23
import java.util.ResourceBundle;
-
 
24
 
22
 
25
import org.apache.log4j.Logger;
23
import org.apache.log4j.Logger;
26
import org.apache.struts2.convention.annotation.InterceptorRef;
24
import org.apache.struts2.convention.annotation.InterceptorRef;
27
import org.apache.struts2.convention.annotation.InterceptorRefs;
25
import org.apache.struts2.convention.annotation.InterceptorRefs;
28
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Result;
Line 39... Line 37...
39
    @Result(name="redirect", type="redirectAction", 
37
    @Result(name="redirect", type="redirectAction", 
40
    		params = {"actionName" , "shipping"})
38
    		params = {"actionName" , "shipping"})
41
})
39
})
42
public class ShippingController extends BaseController{
40
public class ShippingController extends BaseController{
43
	
41
	
44
	private static Logger log = Logger.getLogger(Class.class);
42
	private static Logger log = Logger.getLogger(ShippingController.class);
45
	
-
 
46
	private static final ResourceBundle resource = ResourceBundle.getBundle(ShippingController.class.getName());
-
 
47
	private static final double COD_CUTOFF_AMOUNT = Double.parseDouble(resource.getString("cod_cutoff_amount")); 
-
 
48
	private static final String RECAPTCHA_PUBLIC_KEY = resource.getString("recaptcha_public_key");
-
 
49
    
43
    
50
	private long addressId = 0;
44
	private long addressId = 0;
51
	private String errorMsg = "";
45
	private String errorMsg = "";
52
	
46
	
53
	private String name;
47
	private String name;
Line 57... Line 51...
57
	private String state = "";
51
	private String state = "";
58
	private String pincode;
52
	private String pincode;
59
	private String phone;
53
	private String phone;
60
	private String country;
54
	private String country;
61
	
55
	
62
	private boolean showCodOption = true;
-
 
63
	
-
 
64
	public ShippingController(){
56
	public ShippingController(){
65
		super();
57
		super();
66
	}
58
	}
67
	
59
	
68
	 // GET /shipping
60
	 // GET /shipping
Line 228... Line 220...
228
					itemdetail.put("ITEM_NAME", itemName);
220
					itemdetail.put("ITEM_NAME", itemName);
229
					itemdetail.put("ITEM_ID", line.getItemId()+"");
221
					itemdetail.put("ITEM_ID", line.getItemId()+"");
230
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
222
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
231
					itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
223
					itemdetail.put("MRP", formattingUtils.formatPrice(item.getMrp()));
232
					itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
224
					itemdetail.put("SELLING_PRICE", formattingUtils.formatPrice(item.getSellingPrice()));
233
					if(item.getSellingPrice() > COD_CUTOFF_AMOUNT)
-
 
234
					    showCodOption = false;
-
 
235
					itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice((item.getSellingPrice()*line.getQuantity())));
225
					itemdetail.put("TOTAL_PRICE", formattingUtils.formatPrice((item.getSellingPrice()*line.getQuantity())));
236
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
226
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
237
					items.add(itemdetail);
227
					items.add(itemdetail);
238
				}
228
				}
239
			}
229
			}
Line 247... Line 237...
247
			if(cart.isSetAddressId())	{
237
			if(cart.isSetAddressId())	{
248
				defaultAddressId = cart.getAddressId();
238
				defaultAddressId = cart.getAddressId();
249
			} else	{
239
			} else	{
250
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
240
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
251
			}
241
			}
252
			
-
 
253
	        for(Address address : addresses){
-
 
254
	            if(address.getId() == defaultAddressId){
-
 
255
	                try {
-
 
256
	                    LogisticsServiceClient lClient = new LogisticsServiceClient();
-
 
257
	                    showCodOption = showCodOption && lClient.getClient().isCodAllowed(address.getPin());
-
 
258
	                } catch(Exception e) {
-
 
259
	                    log.error("Error while checking if COD is available for: " + showCodOption, e);
-
 
260
	                    showCodOption = false; //Defaulting to defensive behaviour
-
 
261
	                }
-
 
262
	            }
-
 
263
	        }
-
 
264
	        
242
	        
265
			String couponCode = cart.getCouponCode();
243
			String couponCode = cart.getCouponCode();
266
	        context.put("couponcode", couponCode == null ? "" : couponCode);
244
	        context.put("couponcode", couponCode == null ? "" : couponCode);
267
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
245
	        context.put("discountedamount", formattingUtils.formatPrice(cart.getDiscountedPrice()));
268
	        
246
	        
Line 352... Line 330...
352
	}
330
	}
353
 
331
 
354
	public void setPhone(String phone) {
332
	public void setPhone(String phone) {
355
		this.phone = phone;
333
		this.phone = phone;
356
	}
334
	}
357
 
-
 
358
    public boolean shouldShowCodOption() {
-
 
359
        return showCodOption;
-
 
360
    }
-
 
361
    
-
 
362
    public String getPublicKey(){
-
 
363
        return RECAPTCHA_PUBLIC_KEY;
-
 
364
    }
-
 
365
}
335
}
366
336