[pal-cvs 2804] [548] display products in cart.

svnno****@sourc***** svnno****@sourc*****
2007年 9月 7日 (金) 18:18:28 JST


Revision: 548
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=548
Author:   shinsuke
Date:     2007-09-07 18:18:28 +0900 (Fri, 07 Sep 2007)

Log Message:
-----------
display products in cart.

Modified Paths:
--------------
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CartService.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CartServiceImpl.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListAction.java
    pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/cart/productList.html


-------------- next part --------------
Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CartService.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CartService.java	2007-09-07 09:17:25 UTC (rev 547)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CartService.java	2007-09-07 09:18:28 UTC (rev 548)
@@ -2,6 +2,7 @@
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.List;
 
 import jp.sf.pal.pompei.exentity.CustomersBasket;
 
@@ -10,6 +11,9 @@
     public abstract CustomersBasket getCustomersBasket(BigDecimal customersId,
             BigDecimal productsId);
 
+    public abstract List<CustomersBasket> getCustomersBasket(
+            BigDecimal customersId);
+
     public abstract void addCustomersBasket(CustomersBasket customersBasket);
 
     public abstract void updateCustomersBasket(CustomersBasket customersBasket);

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CartServiceImpl.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CartServiceImpl.java	2007-09-07 09:17:25 UTC (rev 547)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CartServiceImpl.java	2007-09-07 09:18:28 UTC (rev 548)
@@ -74,4 +74,13 @@
             getCustomersBasketBhv().deleteList(customersBasketList);
         }
     }
+
+    public List<CustomersBasket> getCustomersBasket(BigDecimal customersId) {
+        CustomersBasketCB cb = new CustomersBasketCB();
+        // TODO needed?
+        cb.setupSelect_Customers();
+        cb.setupSelect_Products();
+        cb.query().setCustomersId_Equal(customersId);
+        return getCustomersBasketBhv().selectList(cb);
+    }
 }

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListAction.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListAction.java	2007-09-07 09:17:25 UTC (rev 547)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListAction.java	2007-09-07 09:18:28 UTC (rev 548)
@@ -8,9 +8,20 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.faces.context.FacesContext;
+
+import jp.sf.pal.common.util.FacesMessageUtil;
 import jp.sf.pal.pompei.dxo.ProductDxo;
 import jp.sf.pal.pompei.entity.Cart;
+import jp.sf.pal.pompei.exentity.Customers;
+import jp.sf.pal.pompei.exentity.CustomersBasket;
+import jp.sf.pal.pompei.exentity.Manufacturers;
+import jp.sf.pal.pompei.exentity.ManufacturersInfo;
 import jp.sf.pal.pompei.exentity.ProductsDescription;
+import jp.sf.pal.pompei.service.CartService;
+import jp.sf.pal.pompei.service.CustomerService;
+import jp.sf.pal.pompei.service.ManufacturerService;
+import jp.sf.pal.pompei.service.ProductService;
 import jp.sf.pal.pompei.util.SessionUtil;
 
 /**
@@ -27,9 +38,73 @@
      */
     private static final long serialVersionUID = -7622016737871221829L;
 
+    private ManufacturerService manufacturerService;
+
+    private ProductService productService;
+
+    private CartService cartService;
+
+    private CustomerService customerService;
+
     private ProductDxo productDxo;
 
     /**
+     * @return manufacturerService
+     */
+    public ManufacturerService getManufacturerService() {
+        return manufacturerService;
+    }
+
+    /**
+     * @param manufacturerService 設定する manufacturerService
+     */
+    public void setManufacturerService(ManufacturerService manufacturerService) {
+        this.manufacturerService = manufacturerService;
+    }
+
+    /**
+     * @return productService
+     */
+    public ProductService getProductService() {
+        return productService;
+    }
+
+    /**
+     * @param productService 設定する productService
+     */
+    public void setProductService(ProductService productService) {
+        this.productService = productService;
+    }
+
+    /**
+     * @return customerService
+     */
+    public CustomerService getCustomerService() {
+        return customerService;
+    }
+
+    /**
+     * @param customerService 設定する customerService
+     */
+    public void setCustomerService(CustomerService customerService) {
+        this.customerService = customerService;
+    }
+
+    /**
+     * @return cartService
+     */
+    public CartService getCartService() {
+        return cartService;
+    }
+
+    /**
+     * @param cartService 設定する cartService
+     */
+    public void setCartService(CartService cartService) {
+        this.cartService = cartService;
+    }
+
+    /**
     * @return productDxo
     */
     public ProductDxo getProductDxo() {
@@ -48,26 +123,55 @@
     }
 
     public Class<?> prerender() {
-        Cart cart = (Cart) SessionUtil.getFromApplicationScope("cart");
+        // check login
+        String remoteUser = FacesContext.getCurrentInstance()
+                .getExternalContext().getRemoteUser();
+        if (remoteUser == null) {
+            // TODO put message
+            return null;
+        }
+
+        Customers customers = getCustomerService().getCustomer(remoteUser);
+        if (customers == null) {
+            // TODO put message
+            return null;
+        }
+
+        // TODO delete
+
+        getCartService().cleanupCustomersBasket(customers.getCustomersId());
+
+        List<CustomersBasket> baskets = getCartService().getCustomersBasket(
+                customers.getCustomersId());
+
+        BigDecimal totalPrice = new BigDecimal(0);
         List<Map<String, Object>> products = new ArrayList<Map<String, Object>>();
-        BigDecimal totalPrice = new BigDecimal(0);
-        if (cart != null) {
-            Map<ProductsDescription, Integer> details = cart.getOrderdetails();
-            for (Iterator<Map.Entry<ProductsDescription, Integer>> itr = details
-                    .entrySet().iterator(); itr.hasNext();) {
-                Map.Entry<ProductsDescription, Integer> entry = itr.next();
-                Map<String, Object> map = new HashMap<String, Object>();
-                getProductDxo().convert(entry.getKey(), map);
-                map.put("itemCount", entry.getValue());
-                products.add(map);
-                totalPrice = totalPrice.add(entry.getKey().getProducts()
-                        .getProductsPrice().multiply(
-                                new BigDecimal(entry.getValue())));
-            }
+        // TODO Dxo... it may be difficult..
+        for (CustomersBasket basket : baskets) {
+            totalPrice = totalPrice.add(basket.getProducts().getProductsPrice()
+                    .multiply(basket.getCustomersBasketQuantity()));
+            ProductsDescription pd = getProductService()
+                    .getProdcutsDescription(basket.getProductsId());
+            ManufacturersInfo mi = getManufacturerService()
+                    .getManufacturesInfo(
+                            basket.getProducts().getManufacturersId());
+            Map<String, Object> map = new HashMap<String, Object>();
+            map.put("customersBasketId", basket.getCustomersBasketId());
+            map.put("productsName", pd.getProductsName());
+            map.put("productsUrl", pd.getProductsUrl());
+            map.put("productsModel", basket.getProducts().getProductsModel());
+            map.put("manufacturersName", mi.getManufacturers()
+                    .getManufacturersName());
+            map.put("quantity", basket.getCustomersBasketQuantity());
+            map.put("productsPrice", basket.getProducts().getProductsPrice());
+            map.put("finalPrice", basket.getFinalPrice());
+            products.add(map);
         }
         getProductListPage().setTotalPrice(totalPrice);
         getProductListPage().setProductsItems(products);
 
+        // render FacesMessages
+        FacesMessageUtil.renderMessages();
         return null;
     }
 

Modified: pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/cart/productList.html
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/cart/productList.html	2007-09-07 09:17:25 UTC (rev 547)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/cart/productList.html	2007-09-07 09:18:28 UTC (rev 548)
@@ -24,11 +24,11 @@
 			<td><span id="productsCount">1</span></td>
 			<td><span id="productsName">XXX 01MAX</span></td>
 			<td><span id="productsModel">MX-XXX</span></td>
-			<td><span id="manufacturersId">アディダス</span></td>
-			<td><input size="2" id="itemCount" type="text" value="1"/></td>
-			<td><span id="productsPrice">30,000</span></td>
+			<td><span id="manufacturersName">アディダス</span></td>
+			<td><span id="quantity">1</span></td>
+			<td><span id="finalPrice">30,000</span></td>
 			<td>
-				<a id="goProductDelete" href="./productList.html?productsIndex=0" onClick="this.href=this.href+'&delete=true'">削除</a>
+				<a id="goProductDelete" href="./productList.html?customersBasketId=0&fixed_mode=delete" onclick="if(confirm('削除します。よろしいですか?')){return true;}else{return false;}">削除</a>
 			</td>
 		</tr>
 	</tbody>


pal-cvs メーリングリストの案内