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

svn commit: r1179340 - /ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js

Author: sascharodekamp
Date: Wed Oct  5 17:29:13 2011
New Revision: 1179340

URL: http://svn.apache.org/viewvc?rev=1179340&view=rev
Log:
UPDATE: Ajax callings in CheckoutProcess.js are not handling server-side errors correctly (https://issues.apache.org/jira/browse/OFBIZ-4342) A patch from Jonatan Soto: All methods that do ajax calls in CheckoutProcess.js are not dealing with the server-side errors. They should be treated in the success callback using an existing method called getServerError(data). This method looks for the _ERROR_MESSAGE* keys of the JSON object returned by the server.

Modified:
    ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js

Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js?rev=1179340&r1=1179339&r2=1179340&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/images/checkoutProcess.js Wed Oct  5 17:29:13 2011
@@ -24,17 +24,17 @@ var isBillStepValidate = false;
 jQuery(document).ready(function(){
     // Cart
     var validateCart = jQuery("#cartForm");
-    validateCart.validate(); 
-    
+    validateCart.validate();
+
     var validateShip = jQuery("#shippingForm");
     validateShip.validate();
-    
+
     var validateShipOption = jQuery("#shippingOptionForm");
     validateShipOption.validate();
-    
+
     var validateBill = jQuery("#billingForm");
     validateBill.validate();
-    
+
     // Goto Edit Cart Panel
     jQuery('#openCartPanel').click(function() {
         showEditCartPanel();
@@ -143,8 +143,8 @@ function getServerError(data) {
     var serverError = "";
     if (data._ERROR_MESSAGE_LIST_ != undefined) {
         serverErrorHash = data._ERROR_MESSAGE_LIST_;
-        serverErrorHash.each(function(error) {
-            serverError += error.message;
+        jQuery.each(serverErrorHash, function(i, error) {
+            serverError += error.message + '<br/>';
         });
     }
     if (data._ERROR_MESSAGE_ != undefined) {
@@ -257,24 +257,29 @@ function createUpdateCustomerAndShipping
         async: false,
         data: jQuery('#shippingForm').serialize(),
         success: function(json) {
-            jQuery('#shippingFormServerError').fadeOut('fast');
-            // Process Shipping data response.
-            jQuery('#shipToPartyId').val(json.partyId);
-            jQuery('#billToPartyId').val(json.partyId);
-            jQuery('#shipToContactMechId').val(json.contactMechId);
-            jQuery('#shipToPhoneContactMechId').val(json.phoneContactMechId);
-            jQuery('#emailContactMechId').val(json.emailContactMechId);
-            //jQuery('#completedShippingMethod').html(json.shippingDescription);
-            updateShippingSummary();
-            getShipOptions();
-            result = true;
+                if (!getServerError(json)) {
+                    jQuery('#shippingFormServerError').fadeOut('fast');
+                    // Process Shipping data response.
+                    jQuery('#shipToPartyId').val(json.partyId);
+                    jQuery('#billToPartyId').val(json.partyId);
+                    jQuery('#shipToContactMechId').val(json.contactMechId);
+                    jQuery('#shipToPhoneContactMechId').val(json.phoneContactMechId);
+                    jQuery('#emailContactMechId').val(json.emailContactMechId);
+                    //jQuery('#completedShippingMethod').html(json.shippingDescription);
+                    updateShippingSummary();
+                    getShipOptions();
+                    result = true;
+                } else {
+                    jQuery('#shippingFormServerError').html(serverError);
+                    result = false;
+                }
         },
         error: function(error) {
             if (error != "") {
-                jQuery('#shippingFormServerError').html(serverError);
+                jQuery('#shippingFormServerError').html(error);
             }
             result = false;
-        } 
+        }
     });
     return result;
 }
@@ -289,19 +294,24 @@ function getShipOptions() {
             type: 'POST',
             async: false,
             success: function(json) {
-                jQuery('#shippingFormServerError').fadeOut('fast');
-                isShipStepValidate = true;
-                shipOptions = json.shippingOptions;
-                var shipMethod = jQuery('#shipMethod');
-                shipMethod.find("option").remove();
-                jQuery.each(shipOptions, function(shipOption) {
-                    if (this.productStoreShipMethId){
-                        shipMethod.append(jQuery("<option value = " + this.shippingMethod + ":" + this.productStoreShipMethId + " > " + this.shippingDesc  + " </option>"));
+                if (!getServerError(json)) {
+                        jQuery('#shippingFormServerError').fadeOut('fast');
+                        isShipStepValidate = true;
+                        shipOptions = json.shippingOptions;
+                        var shipMethod = jQuery('#shipMethod');
+                        shipMethod.find("option").remove();
+                        jQuery.each(shipOptions, function(shipOption) {
+                            if (this.productStoreShipMethId){
+                                shipMethod.append(jQuery("<option value = " + this.shippingMethod + ":" + this.productStoreShipMethId + " > " + this.shippingDesc  + " </option>"));
+                            } else {
+                                shipMethod.append(jQuery("<option value = " + this.shippingMethod + " > " + this.shippingDesc  + " </option>"));
+                            }
+                        });
+                        result = true;
                     } else {
-                        shipMethod.append(jQuery("<option value = " + this.shippingMethod + " > " + this.shippingDesc  + " </option>"));
+                        jQuery('#shippingFormServerError').html(serverError);
+                        result = false;
                     }
-                });
-                result = true;
             },
             error: function(error) {
                 if (error != "") {
@@ -328,6 +338,7 @@ function setShippingOption() {
         async: false,
         data: jQuery('#shippingOptionForm').serialize(),
         success: function(json) {
+            if (!getServerError(json)) {
             shipTotal = json.shippingTotal;
                 isShipOptionStepValidate = true;
                 jQuery('#selectedShipmentOption').html(json.shippingDescription);
@@ -336,6 +347,10 @@ function setShippingOption() {
                 //jQuery('#cartGrandTotal').val(json.cartGrandTotal);
                 //jQuery('#totalSalesTax').val(json.totalSalesTax);
                 result = true;
+            } else {
+                jQuery('#shippingFormServerError').html(serverError);
+                result = false;
+            }
         },
         error: function(error) {
             if(error != "") {
@@ -374,13 +389,18 @@ function processBillingAndPayment() {
         data: jQuery('#billingForm').serialize(),
         async: false,
         success: function(json) {
-            jQuery('#billingFormServerError').fadeOut('fast');
-            isBillStepValidate = true;
-            jQuery('#billToContactMechId').val(json.contactMechId);
-            jQuery('#paymentMethodId').val(json.paymentMethodId);
-            jQuery('#billToPhoneContactMechId').val(json.phoneContactMechId);
-            updateBillingSummary();
-            result = true;
+            if (!getServerError(json)) {
+                    jQuery('#billingFormServerError').fadeOut('fast');
+                    isBillStepValidate = true;
+                    jQuery('#billToContactMechId').val(json.contactMechId);
+                    jQuery('#paymentMethodId').val(json.paymentMethodId);
+                    jQuery('#billToPhoneContactMechId').val(json.phoneContactMechId);
+                    updateBillingSummary();
+                    result = true;
+                } else {
+                    jQuery('#shippingFormServerError').html(serverError);
+                    result = false;
+                }
         },
         error: function(error) {
             if(error != "") {
@@ -430,8 +450,13 @@ function addPromoCode() {
         type: 'POST',
         data: {"productPromoCodeId" : jQuery('#productPromoCode').val()},
         success: function(json) {
-            jQuery('#cartFormServerError').fadeOut('fast');
-            updateCartData();
+            if (!getServerError(json)) {
+                jQuery('#cartFormServerError').fadeOut('fast');
+                updateCartData();
+            } else {
+                jQuery('#shippingFormServerError').html(serverError);
+                result = false;
+            }
         },
         error: function(error) {
             if(error != "") {
@@ -452,7 +477,11 @@ function getProductLineItemIndex(event, 
         async: false,
         data: formValues,
         success: function(json) {
-            itemIndex = json.itemIndex;
+            if (!getServerError(json)) {
+                itemIndex = json.itemIndex;
+            } else {
+                jQuery('#shippingFormServerError').html(serverError);
+            }
         }
     });
     return itemIndex;
@@ -491,32 +520,37 @@ function updateCartData(elementId, formV
         type: 'POST',
         data: formValues,
         success: function(json) {
-            if (json.totalQuantity == 0) {
-                jQuery('#emptyCartCheckoutPanel').show();
-                jQuery('#checkoutPanel').hide();
-                jQuery('#microCartNotEmpty').hide();
-                jQuery('#microCartEmpty').show();
-                jQuery('#quickCheckoutEnabled').hide();
-                jQuery('#quickCheckoutDisabled').show();
-                jQuery('#onePageCheckoutEnabled').hide();
-                jQuery('#onePageCheckoutDisabled').show();
-                jQuery('#googleCheckoutEnabled').hide();
-                jQuery('#googleCheckoutDisabled').show();
-                jQuery('#microCartPayPalCheckout').hide();
-            } else {
-                // Replace whole cart panel with updated cart values for updating line item in case of gift item is added or remove in cart after applying coupon code
-                // No need to calculate individual value for shopping cart when whole cart is updating
-                jQuery.ajax({
-                    url: 'UpdateCart',
-                    type: 'POST',
-                    cache: false,
-                    success: function(data) {
-                        jQuery('#cartPanel').html(data);
-                        initCartProcessObservers();
+            if (!getServerError(json)) {
+                    if (json.totalQuantity == 0) {
+                        jQuery('#emptyCartCheckoutPanel').show();
+                        jQuery('#checkoutPanel').hide();
+                        jQuery('#microCartNotEmpty').hide();
+                        jQuery('#microCartEmpty').show();
+                        jQuery('#quickCheckoutEnabled').hide();
+                        jQuery('#quickCheckoutDisabled').show();
+                        jQuery('#onePageCheckoutEnabled').hide();
+                        jQuery('#onePageCheckoutDisabled').show();
+                        jQuery('#googleCheckoutEnabled').hide();
+                        jQuery('#googleCheckoutDisabled').show();
+                        jQuery('#microCartPayPalCheckout').hide();
+                    } else {
+                        // Replace whole cart panel with updated cart values for updating line item in case of gift item is added or remove in cart after applying coupon code
+                        // No need to calculate individual value for shopping cart when whole cart is updating
+                        jQuery.ajax({
+                            url: 'UpdateCart',
+                            type: 'POST',
+                            cache: false,
+                            success: function(data) {
+                                jQuery('#cartPanel').html(data);
+                                initCartProcessObservers();
+                            }
+                        });
                     }
-                });
+                } else {
+                    jQuery('#shippingFormServerError').html(serverError);
+                    result = false;
+                }
             }
-        }
     });
 }
 function processOrder() {