[pal-cvs 2805] [549] delete an item from cart.

svnno****@sourc***** svnno****@sourc*****
2007年 9月 8日 (土) 07:57:23 JST


Revision: 549
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=549
Author:   shinsuke
Date:     2007-09-08 07:57:23 +0900 (Sat, 08 Sep 2007)

Log Message:
-----------
delete an item from cart. fixed a wrong final price

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/java/jp/sf/pal/pompei/web/user/cart/ProductListPage.java
    pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/ProductDetailsAction.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:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/CartService.java	2007-09-07 22:57:23 UTC (rev 549)
@@ -18,7 +18,7 @@
 
     public abstract void updateCustomersBasket(CustomersBasket customersBasket);
 
-    public abstract void deleteCustomersBasket(CustomersBasket customersBasket);
+    public abstract void deleteCustomersBasket(BigDecimal customersBasketId);
 
     public abstract void cleanupCustomersBasket(BigDecimal customersId);
 

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:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/service/impl/CartServiceImpl.java	2007-09-07 22:57:23 UTC (rev 549)
@@ -51,12 +51,19 @@
         getCustomersBasketBhv().insert(customersBasket);
     }
 
-    public void deleteCustomersBasket(CustomersBasket customersBasket) {
-        getCustomersBasketBhv().update(customersBasket);
+    public void deleteCustomersBasket(BigDecimal customersBasketId) {
+        CustomersBasketCB cb = new CustomersBasketCB();
+        cb.query().setCustomersBasketId_Equal(customersBasketId);
+        CustomersBasket basket = getCustomersBasketBhv().selectEntity(cb);
+        if (basket != null) {
+            getCustomersBasketBhv().delete(basket);
+        } else {
+            // TODO throw exception
+        }
     }
 
     public void updateCustomersBasket(CustomersBasket customersBasket) {
-        getCustomersBasketBhv().delete(customersBasket);
+        getCustomersBasketBhv().update(customersBasket);
     }
 
     public void cleanupCustomersBasket(BigDecimal customersId) {

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:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListAction.java	2007-09-07 22:57:23 UTC (rev 549)
@@ -4,25 +4,22 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 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.PompeiConstants;
 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;
 
 /**
  * カート画面でのアクション処理を記述します。
@@ -118,6 +115,13 @@
         this.productDxo = productDxo;
     }
 
+    public Class<?> doDelete() {
+        getCartService().deleteCustomersBasket(
+                getProductListPage().getCustomersBasketId());
+        //TODO put message
+        return null;
+    }
+
     public Class<?> initialize() {
         return null;
     }
@@ -137,7 +141,10 @@
             return null;
         }
 
-        // TODO delete
+        // delete
+        if (isDelete()) {
+            doDelete();
+        }
 
         getCartService().cleanupCustomersBasket(customers.getCustomersId());
 
@@ -148,8 +155,7 @@
         List<Map<String, Object>> products = new ArrayList<Map<String, Object>>();
         // TODO Dxo... it may be difficult..
         for (CustomersBasket basket : baskets) {
-            totalPrice = totalPrice.add(basket.getProducts().getProductsPrice()
-                    .multiply(basket.getCustomersBasketQuantity()));
+            totalPrice = totalPrice.add(basket.getFinalPrice());
             ProductsDescription pd = getProductService()
                     .getProdcutsDescription(basket.getProductsId());
             ManufacturersInfo mi = getManufacturerService()
@@ -175,12 +181,18 @@
         return null;
     }
 
+    private boolean isDelete() {
+        return getProductListPage().getMode() != null
+                && getProductListPage().getMode().equals(
+                        PompeiConstants.DELETE_MODE);
+    }
+
     /**
      *
      */
     private ProductListPage productListPage;
 
-    public Class<?> doAdd() {
+    public Class<?> doUpdate() {
         return null;
     }
 

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListPage.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListPage.java	2007-09-07 09:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/cart/ProductListPage.java	2007-09-07 22:57:23 UTC (rev 549)
@@ -14,10 +14,12 @@
      */
     private static final long serialVersionUID = 5628720748778592569L;
 
-    private Integer itemCount;
+    private BigDecimal quantity;
 
-    private String manufacturersId;
+    private BigDecimal customersBasketId;
 
+    private String manufacturersName;
+
     private int productsIndex;
 
     private List<Map<String, Object>> productsItems;
@@ -30,24 +32,42 @@
 
     private String title;
 
+    private BigDecimal finalPrice;
+
     private BigDecimal totalPrice;
 
-    public Integer getItemCount() {
-        return itemCount;
+    private String mode;
+
+    /**
+     * @return customersBasketId
+     */
+    public BigDecimal getCustomersBasketId() {
+        return customersBasketId;
     }
 
-    public void setItemCount(Integer itemCount) {
-        this.itemCount = itemCount;
+    /**
+     * @param customersBasketId 設定する customersBasketId
+     */
+    public void setCustomersBasketId(BigDecimal customersBasketId) {
+        this.customersBasketId = customersBasketId;
     }
 
-    public String getManufacturersId() {
-        return manufacturersId;
+    public BigDecimal getQuantity() {
+        return quantity;
     }
 
-    public void setManufacturersId(String manufacturersId) {
-        this.manufacturersId = manufacturersId;
+    public void setQuantity(BigDecimal quantity) {
+        this.quantity = quantity;
     }
 
+    public String getManufacturersName() {
+        return manufacturersName;
+    }
+
+    public void setManufacturersName(String manufacturersId) {
+        this.manufacturersName = manufacturersId;
+    }
+
     public int getProductsIndex() {
         return productsIndex;
     }
@@ -96,18 +116,46 @@
         this.title = title;
     }
 
+    public BigDecimal getFinalPrice() {
+        return finalPrice;
+    }
+
+    public void setFinalPrice(BigDecimal totalPrice) {
+        this.finalPrice = totalPrice;
+    }
+
+    public int getProductsCount() {
+        return getProductsIndex() + 1;
+    }
+
+    /**
+     * @return mode
+     */
+    public String getMode() {
+        return mode;
+    }
+
+    /**
+     * @param mode 設定する mode
+     */
+    public void setMode(String mode) {
+        this.mode = mode;
+    }
+
+    /**
+     * @return totalPrice
+     */
     public BigDecimal getTotalPrice() {
         return totalPrice;
     }
 
+    /**
+     * @param totalPrice 設定する totalPrice
+     */
     public void setTotalPrice(BigDecimal totalPrice) {
         this.totalPrice = totalPrice;
     }
 
-    public int getProductsCount() {
-        return getProductsIndex() + 1;
-    }
-
     public String getProductListLinkHref() {
         return UrlBuilderUtil.createProductListUrl();
     }

Modified: pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/ProductDetailsAction.java
===================================================================
--- pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/ProductDetailsAction.java	2007-09-07 09:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/java/jp/sf/pal/pompei/web/user/product/ProductDetailsAction.java	2007-09-07 22:57:23 UTC (rev 549)
@@ -98,7 +98,7 @@
             customersBasket.setProducts(products);
             customersBasket.setFinalPrice(calculateFinalPrice(customersBasket));
             cartService.addCustomersBasket(customersBasket);
-            // TODO put message
+            FacesMessageUtil.addInfoMessage("added.product.to.cart");
         } else {
             //  add
             customersBasket.setCustomersBasketQuantity(customersBasket
@@ -110,15 +110,14 @@
             // TODO put message
         }
 
-        FacesMessageUtil.addInfoMessage("added.product.to.cart");
         return null;
     }
 
     private BigDecimal calculateFinalPrice(CustomersBasket customersBasket) {
         if (customersBasket != null) {
             //TODO tax
-            return customersBasket.getProducts().getProductsPrice().pow(
-                    customersBasket.getCustomersBasketQuantity().intValue());
+            return customersBasket.getProducts().getProductsPrice().multiply(
+                    customersBasket.getCustomersBasketQuantity());
         }
         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:18:28 UTC (rev 548)
+++ pompei/portlets/pompei-core/trunk/src/main/webapp/view/user/cart/productList.html	2007-09-07 22:57:23 UTC (rev 549)
@@ -39,7 +39,7 @@
 		</tr>
 	</tfoot>
 </table>
-<input type="submit" id="doAdd" value="カートを更新する" />
+<input type="submit" id="doUpdate" value="カートを更新する" />
 <br />
 <br />
 <a id="productListLink" href="">一覧へ戻る</a>


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