1 package org.apache.tapestry.pets; 2 3 import java.io.Serializable ; 4 import java.math.BigDecimal ; 5 import java.util.Hashtable ; 6 7 import johnmammen.betterpetshop.service.PetshopManager; 8 9 import org.apache.tapestry.IRequestCycle; 10 import org.apache.tapestry.listener.ListenerMap; 11 import org.apache.tapestry.pets.domain.model.ICustomer; 12 import org.apache.tapestry.pets.domain.model.IItem; 13 import org.apache.tapestry.pets.domain.model.IShoppingCart; 14 import org.apache.tapestry.pets.domain.model.pojo.BasketItem; 15 import org.apache.tapestry.pets.domain.model.pojo.ShoppingCart; 16 import org.springframework.web.context.WebApplicationContext; 17 import org.springframework.web.context.support.WebApplicationContextUtils; 18 19 public class Visit implements Serializable { 20 21 private transient Hashtable orderInformation; 22 23 private transient ListenerMap listeners = null; 24 25 private IShoppingCart userCart; 26 27 private ICustomer customer; 28 29 private String bannerpath; 30 31 public ListenerMap getListeners() { 32 if (listeners == null) { 33 listeners = new ListenerMap(this); 34 } 35 36 return listeners; 37 } 38 39 public boolean isUserLoggedIn() { 40 return customer != null; 41 } 42 43 public IShoppingCart getUserCart() { 44 return userCart; 45 } 46 47 public void setUserCart(IShoppingCart userCart) { 48 this.userCart = userCart; 49 } 50 51 public void directAddItemToCart(IRequestCycle cycle) { 52 Object [] parameters = cycle.getServiceParameters(); 53 String itemToAdd = ((String ) parameters[0]); 54 PetshopManager petManager=null; 56 try { 57 WebApplicationContext appcontext = WebApplicationContextUtils 58 .getWebApplicationContext( cycle.getRequestContext().getServlet() 60 .getServletContext()); 61 petManager = (PetshopManager) appcontext.getBean("petshopService"); 62 }catch(Exception e){ 63 64 } 65 66 IItem item = petManager.getItem(itemToAdd); 68 70 BigDecimal price = item.getListprice(); 72 int qty = item.getQty(); 73 String itemName = item.getProduct().getProductdetail().getName(); 74 boolean inStock = (qty > 0) ? true : false; 75 76 if (userCart == null) { 78 userCart = new ShoppingCart(); 79 } 80 81 userCart.add(new BasketItem(itemToAdd, itemName, inStock, 1, price)); 82 83 cycle.activate("Cart"); 85 } 86 87 public Hashtable getOrderInformation() { 88 return orderInformation; 89 } 90 91 public void setOrderInformation(Hashtable shoppingAddressSession) { 92 this.orderInformation = shoppingAddressSession; 93 } 94 95 public String getLanguage() { 96 return PetConstants.DEFAULT_LANGUAGE; 97 } 98 99 public boolean getListOptions() { 100 return false ; 101 } 102 103 public boolean getBannerOptions() { 104 return false; 105 } 108 109 public String getFavoriteCategory() { 110 return null; 111 } 114 115 public ICustomer getCustomer() { 116 return customer; 117 } 118 119 public void setCustomer(ICustomer customer) { 120 this.customer = customer; 121 } 122 123 public String getBannerpath() { 124 return bannerpath; 125 } 126 127 public void setBannerpath(String bannerpath) { 128 this.bannerpath = bannerpath; 129 } 130 131 } | Popular Tags |