Subversion Repositories SmartDukaan

Rev

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

Rev 1034 Rev 1429
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.ArrayList;
3
import java.util.Collection;
4
import java.util.Collection;
-
 
5
import java.util.HashMap;
-
 
6
import java.util.List;
-
 
7
import java.util.Map;
4
 
8
 
-
 
9
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.user.Address;
10
import in.shop2020.model.v1.user.Address;
6
import in.shop2020.model.v1.user.AddressType;
11
import in.shop2020.model.v1.user.AddressType;
7
import in.shop2020.model.v1.user.Cart;
12
import in.shop2020.model.v1.user.Cart;
-
 
13
import in.shop2020.model.v1.user.Line;
8
import in.shop2020.model.v1.user.UserContextService;
14
import in.shop2020.model.v1.user.UserContextService;
9
import in.shop2020.serving.controllers.BaseController;
15
import in.shop2020.serving.controllers.BaseController;
10
import in.shop2020.serving.utils.Utils;
16
import in.shop2020.serving.utils.Utils;
-
 
17
import in.shop2020.thrift.clients.CatalogServiceClient;
11
import in.shop2020.thrift.clients.UserContextServiceClient;
18
import in.shop2020.thrift.clients.UserContextServiceClient;
12
 
19
 
13
 
20
 
14
import org.apache.log4j.Logger;
21
import org.apache.log4j.Logger;
15
import org.apache.struts2.convention.annotation.InterceptorRef;
22
import org.apache.struts2.convention.annotation.InterceptorRef;
16
import org.apache.struts2.convention.annotation.InterceptorRefs;
23
import org.apache.struts2.convention.annotation.InterceptorRefs;
17
import org.apache.struts2.convention.annotation.Result;
24
import org.apache.struts2.convention.annotation.Result;
18
import org.apache.struts2.convention.annotation.Results;
25
import org.apache.struts2.convention.annotation.Results;
19
import org.apache.thrift.TApplicationException;
26
import org.apache.thrift.TApplicationException;
-
 
27
import org.apache.velocity.VelocityContext;
20
 
28
 
21
@InterceptorRefs({
29
@InterceptorRefs({
22
    @InterceptorRef("myDefault"),
30
    @InterceptorRef("myDefault"),
23
    @InterceptorRef("login")
31
    @InterceptorRef("login")
24
})
32
})
Line 80... Line 88...
80
			for (String str : actionErrors) {
88
			for (String str : actionErrors) {
81
			    errorMsg += "<BR/>" + str;
89
			    errorMsg += "<BR/>" + str;
82
			}
90
			}
83
		}
91
		}
84
		
92
		
85
		htmlSnippets.put("SHIPPING_HEADER", pageLoader.getShippingHeaderHtml());
-
 
86
		htmlSnippets.put("SHIPPING_DETAILS", pageLoader.getShippingDetailsHtml(userinfo.getCartId(), errorMsg));
-
 
87
		
-
 
88
    	return "index";
93
    	return "index";
89
	 }
94
	 }
90
 
95
 
91
	// POST /entity
96
	// POST /entity
92
	public String create(){
97
	public String create(){
Line 156... Line 161...
156
			return "failure";
161
			return "failure";
157
		}
162
		}
158
		return null;
163
		return null;
159
	}
164
	}
160
 
165
 
161
	public String getShippingHeaderSnippet(){
166
	public String getShippingHeaderSnippet() {
-
 
167
		String htmlString = "";
162
		return htmlSnippets.get("SHIPPING_HEADER");
168
		VelocityContext context = new VelocityContext();
-
 
169
		String templateFile = "templates/shippingheader.vm";
-
 
170
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
-
 
171
		return htmlString;
163
	}
172
	}
164
	
173
	
165
	public String getShippingDetailsSnippet(){
174
	public String getShippingDetailsSnippet() {
-
 
175
 
-
 
176
		long cartId = userinfo.getCartId();
-
 
177
		String htmlString = "";
-
 
178
		VelocityContext context = new VelocityContext();
-
 
179
		String templateFile = "templates/shippingdetails.vm";
-
 
180
		List<Map<String,String>> items = null;
-
 
181
		double totalamount= 0.0;
-
 
182
		List<Address> addresses = null;
-
 
183
		long defaultAddressId = 0;
-
 
184
 
-
 
185
		CatalogServiceClient catalogServiceClient  = null;
-
 
186
		in.shop2020.model.v1.catalog.InventoryService.Client catalogClient = null;
-
 
187
		UserContextServiceClient userContextServiceClient = null;
-
 
188
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
189
		
-
 
190
		try {
-
 
191
			catalogServiceClient = new CatalogServiceClient();
-
 
192
			catalogClient = catalogServiceClient.getClient();
-
 
193
			userContextServiceClient = new UserContextServiceClient();
-
 
194
			userClient = userContextServiceClient.getClient();
-
 
195
			
-
 
196
			Cart cart = userClient.getCart(cartId);
-
 
197
			List<Line> lineItems = cart.getLines();
-
 
198
			
-
 
199
			if( ! lineItems.isEmpty())	{
-
 
200
				items = new ArrayList<Map<String,String>>();
-
 
201
				
-
 
202
				for (Line line : lineItems) {
-
 
203
					Map<String, String> itemdetail = new HashMap<String, String>();
166
		return htmlSnippets.get("SHIPPING_DETAILS");
204
					Item item = catalogClient.getItem(line.getItemId());
-
 
205
					String itemName = ((item.getBrand() != null) ? item.getBrand() + " " : "")
-
 
206
										+ ((item.getModelName() != null) ? item.getModelName() + " " : "") 
-
 
207
										+ (( item.getModelNumber() != null ) ? item.getModelNumber() + " " : "" )
-
 
208
										+ (( (item.getColor() != null && !item.getColor().trim().equals("NA"))) ? "("+item.getColor()+")" : "" );
-
 
209
					
-
 
210
					itemdetail.put("ITEM_NAME", itemName);
-
 
211
					itemdetail.put("ITEM_ID", line.getItemId()+"");
-
 
212
					itemdetail.put("ITEM_QUANTITY", ((int)line.getQuantity())+"");
-
 
213
					itemdetail.put("MRP", ((int)item.getMrp())+"");
-
 
214
					itemdetail.put("SELLING_PRICE", (int)item.getSellingPrice()+"");
-
 
215
					itemdetail.put("TOTAL_PRICE", (int)(item.getSellingPrice()*line.getQuantity())+"");
-
 
216
					itemdetail.put("SHIPPING_TIME", line.getEstimate()+"");
-
 
217
					totalamount = totalamount + line.getQuantity()*item.getSellingPrice();
-
 
218
					items.add(itemdetail);				
-
 
219
				}
-
 
220
			}
-
 
221
			
-
 
222
			addresses = userClient.getAllAddressesForUser(cart.getUserId());
-
 
223
 
-
 
224
			if(cart.isSetAddressId())	{
-
 
225
				defaultAddressId = cart.getAddressId();
-
 
226
			} else	{
-
 
227
				defaultAddressId = userClient.getDefaultAddressId(cart.getUserId());
-
 
228
			}
-
 
229
		} catch (Exception e)	{
-
 
230
			e.printStackTrace();
-
 
231
		}
-
 
232
		
-
 
233
		context.put("items", items);
-
 
234
		context.put("totalamount", (int)totalamount+"");
-
 
235
		context.put("addresses", addresses);
-
 
236
		context.put("defaultAddressId", defaultAddressId+"");
-
 
237
		context.put("errorMsg", errorMsg);
-
 
238
		htmlString = pageLoader.getHtmlFromVelocity(templateFile, context);
-
 
239
		return htmlString;
167
	}
240
	}
168
	
241
	
169
	public long getAddressId(){
242
	public long getAddressId(){
170
		return this.addressId;
243
		return this.addressId;
171
	}
244
	}
Line 235... Line 308...
235
	}
308
	}
236
 
309
 
237
	public void setPhone(String phone) {
310
	public void setPhone(String phone) {
238
		this.phone = phone;
311
		this.phone = phone;
239
	}
312
	}
240
}
313
}
241
314