You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/10/29 10:39:05 UTC

svn commit: r830874 - in /ofbiz/trunk: applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Author: jleroux
Date: Thu Oct 29 09:39:04 2009
New Revision: 830874

URL: http://svn.apache.org/viewvc?rev=830874&view=rev
Log:
This allows to print localized descriptions in the POS.
Also some unrelated generics changes in PosTransaction.java

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java
    ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java?rev=830874&r1=830873&r2=830874&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java Thu Oct 29 09:39:04 2009
@@ -647,6 +647,10 @@
         public String getDescription() {
             return (configOption.getString("description") != null? configOption.getString("description"): "no description");
         }
+        
+        public String getDescription(Locale locale) {
+            return (configOption.getString("description") != null? (String) configOption.get("description", locale): "no description");
+        }        
 
         public String getId() {
             return configOption.getString("configOptionId");

Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=830874&r1=830873&r2=830874&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Thu Oct 29 09:39:04 2009
@@ -112,7 +112,7 @@
     protected String currency = null;
     protected String orderId = null;
     protected String partyId = null;
-    protected Locale locale = Locale.getDefault();
+    protected Locale locale = null;
     protected boolean isOpen = false;
     protected int drawerIdx = 0;
 
@@ -130,7 +130,8 @@
         this.productStoreId = (String) session.getAttribute("productStoreId");
         this.facilityId = (String) session.getAttribute("facilityId");
         this.currency = (String) session.getAttribute("currency");
-        this.locale = (Locale) session.getAttribute("locale");
+//        this.locale = (Locale) session.getAttribute("locale"); This is legacy code and may come (demo) from ProductStore.defaultLocaleString defined in demoRetail and is incompatible with how localisation is handled in the POS 
+        this.locale = Locale.getDefault(); 
 
         this.cart = new ShoppingCart(session.getDelegator(), productStoreId, locale, currency);
         this.ch = new CheckOutHelper(session.getDispatcher(), session.getDelegator(), cart);
@@ -251,9 +252,9 @@
         return cart.size();
     }
 
-    public Map getItemInfo(int index) {
+    public Map<String, Object> getItemInfo(int index) {
         ShoppingCartItem item = cart.findCartItem(index);
-        Map itemInfo = FastMap.newInstance();
+        Map<String, Object> itemInfo = FastMap.newInstance();
         itemInfo.put("productId", item.getProductId());
         itemInfo.put("description", item.getDescription());
         itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity()));
@@ -278,7 +279,7 @@
         return itemInfo;
     }
 
-    public List getItemConfigInfo(int index) {
+    public List<Map<String, Object>> getItemConfigInfo(int index) {
         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
         // I think I need to initialize the list in a special way
         // to use foreach in receipt.java
@@ -287,15 +288,13 @@
         if (this.isAggregatedItem(item.getProductId())) {
             ProductConfigWrapper pcw = null;
             pcw = item.getConfigWrapper();
-            List selected = pcw.getSelectedOptions();
-            Iterator iter = selected.iterator();
-            while (iter.hasNext()) {
-                ConfigOption configoption = (ConfigOption)iter.next();
-                Map itemInfo = FastMap.newInstance();
+            List<ConfigOption> selected = pcw.getSelectedOptions();
+            for(ConfigOption configoption : selected) {
+                Map<String, Object> itemInfo = FastMap.newInstance();
                 if (configoption.isSelected() && !configoption.isDefault()) {
                     itemInfo.put("productId", "");
                     itemInfo.put("sku", "");
-                    itemInfo.put("configDescription", configoption.getDescription());
+                    itemInfo.put("configDescription", configoption.getDescription(locale));
                     itemInfo.put("configQuantity", UtilFormatOut.formatQuantity(item.getQuantity()));
                     itemInfo.put("configBasePrice", UtilFormatOut.formatPrice(configoption.getOffsetPrice()));
                     //itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");
@@ -306,12 +305,12 @@
         return list;
     }
 
-    public Map getPaymentInfo(int index) {
+    public Map<String, Object> getPaymentInfo(int index) {
         ShoppingCart.CartPaymentInfo inf = cart.getPaymentInfo(index);
         GenericValue infValue = inf.getValueObject(session.getDelegator());
         GenericValue paymentPref = null;
         try {
-            Map fields = FastMap.newInstance();
+            Map<String, Object> fields = FastMap.newInstance();
             fields.put("paymentMethodTypeId", inf.paymentMethodTypeId);
             if (inf.paymentMethodId != null) {
                 fields.put("paymentMethodId", inf.paymentMethodId);
@@ -319,7 +318,7 @@
             fields.put("maxAmount", inf.amount);
             fields.put("orderId", this.getOrderId());
 
-            List paymentPrefs = session.getDelegator().findByAnd("OrderPaymentPreference", fields);
+            List<GenericValue> paymentPrefs = session.getDelegator().findByAnd("OrderPaymentPreference", fields);
             if (UtilValidate.isNotEmpty(paymentPrefs)) {
                 //Debug.log("Found some prefs - " + paymentPrefs.size(), module);
                 if (paymentPrefs.size() > 1) {
@@ -336,7 +335,7 @@
         }
         //Debug.log("PaymentPref - " + paymentPref, module);
 
-        Map payInfo = FastMap.newInstance();
+        Map<String, Object> payInfo = FastMap.newInstance();
 
         // locate the auth info
         GenericValue authTrans = null;
@@ -357,8 +356,8 @@
         //Debug.log("AuthTrans - " + authTrans, module);
 
         if ("PaymentMethodType".equals(infValue.getEntityName())) {
-            payInfo.put("description", infValue.getString("description"));
-            payInfo.put("payInfo", infValue.getString("description"));
+            payInfo.put("description", (String) infValue.get("description", locale));
+            payInfo.put("payInfo", (String) infValue.get("description", locale));
             payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
         } else {
             String paymentMethodTypeId = infValue.getString("paymentMethodTypeId");
@@ -369,7 +368,7 @@
                 Debug.logError(e, module);
             }
             if (pmt != null) {
-                payInfo.put("description", pmt.getString("description"));
+                payInfo.put("description", (String) pmt.get("description", locale));
                 payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
             }
 
@@ -394,9 +393,10 @@
                 payInfo.put("cardNumber", cardStr);  // masked cardNumber
 
             } else if ("GIFT_CARD".equals(paymentMethodTypeId)) {
-                GenericValue gc = null;
+                 @SuppressWarnings("unused") 
+                GenericValue gc = null; 
                 try {
-                    gc = infValue.getRelatedOne("GiftCard");
+                    gc = infValue.getRelatedOne("GiftCard"); //FIXME is this really useful ? (Maybe later...)
                 } catch (GenericEntityException e) {
                     Debug.logError(e, module);
                 }
@@ -467,7 +467,6 @@
          try {
             int index = Integer.parseInt(cartIndex);
             ShoppingCartItem product = cart.findCartItem(index);
-            Delegator delegator = cart.getDelegator();
             pcw = product.getConfigWrapper();
         } catch (Exception e) {
             trace("general exception", e);
@@ -686,8 +685,8 @@
     }
 
     public int checkPaymentMethodType(String paymentMethodTypeId) {
-        Map fields = UtilMisc.toMap("paymentMethodTypeId", paymentMethodTypeId, "productStoreId", productStoreId);
-        List values = null;
+        Map<String, String> fields = UtilMisc.toMap("paymentMethodTypeId", paymentMethodTypeId, "productStoreId", productStoreId);
+        List<GenericValue> values = null;
         try {
             values = session.getDelegator().findByAndCache("ProductStorePaymentSetting", fields);
         } catch (GenericEntityException e) {
@@ -699,7 +698,7 @@
             return NO_PAYMENT;
         } else {
             boolean isExternal = true;
-            Iterator i = values.iterator();
+            Iterator<GenericValue> i = values.iterator();
             while (i.hasNext() && isExternal) {
                 GenericValue v = (GenericValue) i.next();
                 //Debug.log("Testing [" + paymentMethodTypeId + "] - " + v, module);