[Yanel-commits] rev 58726 - in public/yanel/contributions/realms/konakart-yanel-realm/res-types: overview/src/java/org/wyona/yanel/resources/konakart/overview payment/src/java/org/wyona/yanel/resources/konakart/payment shared/src/java/org/wyona/yanel/resources/konakart/shared shopping-cart/src/java/org/wyona/yanel/resources/konakart/shoppingcart

michi at wyona.com michi at wyona.com
Wed Jun 15 13:52:25 CEST 2011


Author: michi
Date: 2011-06-15 13:52:23 +0200 (Wed, 15 Jun 2011)
New Revision: 58726

Modified:
   public/yanel/contributions/realms/konakart-yanel-realm/res-types/overview/src/java/org/wyona/yanel/resources/konakart/overview/KonakartOverviewSOAPInfResource.java
   public/yanel/contributions/realms/konakart-yanel-realm/res-types/payment/src/java/org/wyona/yanel/resources/konakart/payment/KonakartPaymentSOAPInfResource.java
   public/yanel/contributions/realms/konakart-yanel-realm/res-types/shared/src/java/org/wyona/yanel/resources/konakart/shared/SharedResource.java
   public/yanel/contributions/realms/konakart-yanel-realm/res-types/shopping-cart/src/java/org/wyona/yanel/resources/konakart/shoppingcart/KonakartShoppingCartSOAPInfResource.java
Log:
coupon logic implemented

Modified: public/yanel/contributions/realms/konakart-yanel-realm/res-types/overview/src/java/org/wyona/yanel/resources/konakart/overview/KonakartOverviewSOAPInfResource.java
===================================================================
--- public/yanel/contributions/realms/konakart-yanel-realm/res-types/overview/src/java/org/wyona/yanel/resources/konakart/overview/KonakartOverviewSOAPInfResource.java	2011-06-15 11:42:52 UTC (rev 58725)
+++ public/yanel/contributions/realms/konakart-yanel-realm/res-types/overview/src/java/org/wyona/yanel/resources/konakart/overview/KonakartOverviewSOAPInfResource.java	2011-06-15 11:52:23 UTC (rev 58726)
@@ -198,7 +198,7 @@
                 log.warn("DEBUG: Create default order ...");
                 orderDefault = kkEngine.createOrder(sessionId, items, languageId);
                 //OrderIf orderDefault = kkEngine.createOrder(sessionId, items, languageId);
-                shipping = shared.getShippingCost(items, sessionId, languageId);
+                shipping = shared.getShippingCost(items, sessionId, languageId, getEnvironment().getRequest().getSession(true));
                 orderDefault.setShippingQuote(shipping);
                 orderDefault = kkEngine.getOrderTotals(orderDefault, languageId);
 
@@ -512,6 +512,11 @@
             lang = "de";
         }
 
+        javax.servlet.http.HttpSession session = getEnvironment().getRequest().getSession(true);
+        if (session.getAttribute("coupon") != null) {
+            content.append("<br/><br/>Gutschein: Sie bezahlen keine Lieferkosten auf dieser Bestellung / Bon: les frais de livraison vous sont offerts pour cette commande<br/>");
+        }
+
         content.append("<br/><br/><strong>Rechnungsadresse / Adresse de facturation</strong><br/>");
         if(lang.equals("fr")) {
             if(customer.getGender().equals("f")) {

Modified: public/yanel/contributions/realms/konakart-yanel-realm/res-types/payment/src/java/org/wyona/yanel/resources/konakart/payment/KonakartPaymentSOAPInfResource.java
===================================================================
--- public/yanel/contributions/realms/konakart-yanel-realm/res-types/payment/src/java/org/wyona/yanel/resources/konakart/payment/KonakartPaymentSOAPInfResource.java	2011-06-15 11:42:52 UTC (rev 58725)
+++ public/yanel/contributions/realms/konakart-yanel-realm/res-types/payment/src/java/org/wyona/yanel/resources/konakart/payment/KonakartPaymentSOAPInfResource.java	2011-06-15 11:52:23 UTC (rev 58726)
@@ -307,6 +307,26 @@
                     appendErr("pc", rootElement, doc);
                 }
             }
+
+            String coupon  = req.getParameter("coupon");
+            if(coupon != null && coupon.length() > 0) {
+                appendField("coupon", coupon, rootElement, doc);
+                String couponCode = getResourceConfigProperty("coupon-code");
+                if (couponCode != null) {
+                    if (coupon.toLowerCase().equals(couponCode.toLowerCase())) {
+                        javax.servlet.http.HttpSession session = getEnvironment().getRequest().getSession(true);
+                        session.setAttribute("coupon", coupon);
+                    } else {
+                        log.warn("Coupon '" + coupon + "' did not match!");
+                        appendErr("coupon", rootElement, doc);
+                        redirect = false;
+                    }
+                } else {
+                    log.warn("No coupon code property 'coupon-code' configured inside resource configuration!");
+                }
+            } else {
+                log.info("No coupon specified, hence proceed ...");
+            }
         } else {
             String remarks = (String) getEnvironment().getRequest().getSession(true).getAttribute("checkout-data-remarks");
             if(remarks != null) appendField("remarks", remarks, rootElement, doc);

Modified: public/yanel/contributions/realms/konakart-yanel-realm/res-types/shared/src/java/org/wyona/yanel/resources/konakart/shared/SharedResource.java
===================================================================
--- public/yanel/contributions/realms/konakart-yanel-realm/res-types/shared/src/java/org/wyona/yanel/resources/konakart/shared/SharedResource.java	2011-06-15 11:42:52 UTC (rev 58725)
+++ public/yanel/contributions/realms/konakart-yanel-realm/res-types/shared/src/java/org/wyona/yanel/resources/konakart/shared/SharedResource.java	2011-06-15 11:52:23 UTC (rev 58726)
@@ -1,4 +1,4 @@
-/*-
+/*
  * Copyright 2010 Wyona
  */
 
@@ -298,7 +298,7 @@
      * Calculate the shipping cost for a basket.
      * TODO: Make this function more generic.
      */
-    public ShippingQuoteIf getShippingCost(BasketIf[] items, String sessionId, int languageId) throws Exception {
+    public ShippingQuoteIf getShippingCost(BasketIf[] items, String sessionId, int languageId, HttpSession session) throws Exception {
         // We calculate the shipping cost ourselves in this function,
         // because Konakart has certain limitations as to what you can do.
         CreateOrderOptionsIf orderOptions = new CreateOrderOptions();
@@ -376,13 +376,21 @@
             }
         }
 
+        String coupon = (String) session.getAttribute("coupon");
+
         if(bottles_shipping_price != null) {
-            try {
-                shipping.setCustom1(bottles_shipping_price.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
-            } catch(Exception e) {
-                shipping.setCustom1(bottles_shipping_price.toString());
+            if (coupon != null) {
+                log.info("No wine shipping costs, because coupon exists");
+                shipping.setCustom1("0");
+            } else {
+                try {
+                    shipping.setCustom1(bottles_shipping_price.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
+                } catch(Exception e) {
+                    shipping.setCustom1(bottles_shipping_price.toString());
+                }
             }
         } else {
+            log.info("No wine shipping costs.");
             shipping.setCustom1("");
         }
 
@@ -395,12 +403,18 @@
         }
 
         if(baskets_shipping_price != null) {
-            try {
-                shipping.setCustom2(baskets_shipping_price.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
-            } catch(Exception e) {
-                shipping.setCustom2(baskets_shipping_price.toString());
+            if (coupon != null) {
+                log.info("No Geschenk shipping costs, because coupon exists");
+                shipping.setCustom2("0");
+            } else {
+                try {
+                    shipping.setCustom2(baskets_shipping_price.setScale(2, BigDecimal.ROUND_HALF_EVEN).toString());
+                } catch(Exception e) {
+                    shipping.setCustom2(baskets_shipping_price.toString());
+                }
             }
         } else {
+            log.info("No Geschenk shipping costs.");
             shipping.setCustom2("");
         }
 
@@ -435,7 +449,12 @@
             total = new BigDecimal("0");
         }
 
-        shipping.setTotalExTax(total);
+        if (coupon == null) {
+            shipping.setTotalExTax(total);
+        } else {
+            log.info("No total shipping costs, because coupon exists.");
+        }
+
         shipping.setTotalIncTax(bottles_total_rebate);
 
         // Name of shipping method

Modified: public/yanel/contributions/realms/konakart-yanel-realm/res-types/shopping-cart/src/java/org/wyona/yanel/resources/konakart/shoppingcart/KonakartShoppingCartSOAPInfResource.java
===================================================================
--- public/yanel/contributions/realms/konakart-yanel-realm/res-types/shopping-cart/src/java/org/wyona/yanel/resources/konakart/shoppingcart/KonakartShoppingCartSOAPInfResource.java	2011-06-15 11:42:52 UTC (rev 58725)
+++ public/yanel/contributions/realms/konakart-yanel-realm/res-types/shopping-cart/src/java/org/wyona/yanel/resources/konakart/shoppingcart/KonakartShoppingCartSOAPInfResource.java	2011-06-15 11:52:23 UTC (rev 58726)
@@ -1,4 +1,4 @@
-/*-
+/*
  * Copyright 2010 Wyona
  */
 
@@ -38,6 +38,8 @@
 import javax.xml.transform.Transformer;
 import java.net.URLEncoder;
 
+import javax.servlet.http.HttpSession;
+
 import org.w3c.dom.Element;
 
 /**
@@ -197,7 +199,7 @@
             log.debug("Content language: " + getContentLanguage());
         }
 
-        javax.servlet.http.HttpSession httpSession = getEnvironment().getRequest().getSession(true);
+        HttpSession httpSession = getEnvironment().getRequest().getSession(true);
         Element customerElement = (Element) rootElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "customer"));
 
         // If user is logged in, get customer id, email, etc.
@@ -335,7 +337,7 @@
             ShippingQuoteIf shipping;
 
             try {
-                shipping = shared.getShippingCost(items, sessionId, languageId);
+                shipping = shared.getShippingCost(items, sessionId, languageId, httpSession);
             } catch(Exception e) {
                 // Order is empty or module is broken
                 shipping = null;
@@ -358,13 +360,15 @@
                 Element shippingCost = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "shipping-price-ex-rebate"));
                 shippingCost.appendChild(doc.createTextNode("" + single_price));
 
-                // Custom shipping cost
+                // INFO: Shipping costs of Wein
                 Element shippingCustom1 = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "shipping-custom1"));
                 shippingCustom1.appendChild(doc.createTextNode("" + shipping.getCustom1()));
 
+                // INFO: Shipping costs of Geschenk
                 Element shippingCustom2 = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "shipping-custom2"));
                 shippingCustom2.appendChild(doc.createTextNode("" + shipping.getCustom2()));
                 
+                // INFO: Mengenrabatt
                 Element shippingCustom3 = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "shipping-custom3"));
                 shippingCustom3.appendChild(doc.createTextNode("" + shipping.getCustom3()));
 
@@ -388,6 +392,10 @@
                 // <total-shipping-price-inc-rebate>
                 Element totalPlusShipping = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "total-shipping-price-inc-rebate"));
                 totalPlusShipping.appendChild(doc.createTextNode("" + all_price));
+
+                if (httpSession.getAttribute("coupon") != null) {
+                    Element couponElement = (Element) shoppingCartElement.appendChild(doc.createElementNS(KONAKART_NAMESPACE, "coupon"));
+                }
             } else {
                 // <shipping-module-not-available>
                 // TODO: This is not very good, do something more useful...



More information about the Yanel-commits mailing list