Zen Cart Logo
Forums / Bug Reports / checkout_payment: not submitting properly with GV balance

checkout_payment: not submitting properly with GV balance

Views: 1,054

Results 1 to 7 of 7
15 Jul 2016, 6:38 PM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

checkout_payment: not submitting properly with GV balance

Something is "funny" on the checkout_payment when the customer has a GV balance and the store uses authorizenet_aim (and possibly others; I'm guessing that it's any payment that accepts card data on-site) as a payment method.

Choose a customer who has a GC balance, so the GC block is displayed on the checkout_payment page. Go through the checkout steps to checkout_payment, don't select a payment method and click the "continue" button. The form submits without displaying the javascript alert that indicates that no payment method was chosen. The page is subsequently re-displayed due to the checkout_confirmation page's error-checking.

Under the same conditions, if the customer doesn't have a GC balance, the javascript alert is properly displayed.

The issue appears to be that the ***submitter ***variable is being set due to the simple presence of those GV-related values.

18 Jul 2016, 6:58 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

Re: checkout_payment: not submitting properly with GV balance

Upon further investigation, it appears that the cause is the following section in tpl_checkout_payment_default.php:

<div class="buttonRow forward" id="paymentSubmit"><?php echo zen_image_submit(BUTTON_IMAGE_CONTINUE_CHECKOUT, BUTTON_CONTINUE_ALT, 'onclick=[B]"submitFunction('.zen_user_has_gv_account($_SESSION['customer_id']).','.$order->info['total'].')"[/B]'); ?></div>

The submitFunction, present in /includes/modules/pages/checkout_payment/jscript_main.php, looks like (note that the *submitter *variable is initialized to null earlier in that module):

function submitFunction($gv,$total) {
  if ($gv >=$total) {
    submitter = 1;
  }
}

Finally, the submitter value is checked by the javascript generated by the javascript_validation function present in /includes/classes/payment.php:

       $js =  $js . "\n" . '  if (payment_value == null && submitter != 1) {' . "\n";
       $js =  $js .'    error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n";
       $js =  $js .'    error = 1;' . "\n";
       $js =  $js .'  }' . "\n\n";
       $js =  $js .'  if (error == 1 && submitter != 1) {' . "\n";
       $js =  $js .'    alert(error_message);' . "\n";
       $js =  $js . '    return false;' . "\n";
       $js =  $js .'  } else {' . "\n";
       if ($this->doesCollectsCardDataOnsite == true && PADSS_AJAX_CHECKOUT == '1') {
         $js .= '   return collectsCardDataOnsite(payment_value);' . "\n";
       }
       $js =  $js .'    return true;' . "\n";

The issue is that the *submitter *value is being set upon the button-click when the customer's GV ***balance ***is larger than the order's total ... not when the GV amount-applied is larger than the order's total. That being set results in the error messages issued by the payment-class not being alerted.

I'm at a loss as to what the real purpose of the *submitter *value is; I'm guessing that it's to distinguish between the coupon/GV forms auto-submittal (with no associated submit button) and the form submittal via the actual button on the bottom of the page.

18 Jul 2016, 9:53 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: checkout_payment: not submitting properly with GV balance

Yes, the submitter var is just used to help trigger which field gets submitted, and avoid a payment-selection error if they're actually just submitting their GV amount first, so they can select payment after a page refresh with the updated amount to be paid.

19 Jul 2016, 12:25 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

Re: checkout_payment: not submitting properly with GV balance

DrByte:

Yes, the submitter var is just used to help trigger which field gets submitted, and avoid a payment-selection error if they're actually just submitting their GV amount first, so they can select payment after a page refresh with the updated amount to be paid.
Thanks, DrByte, for the confirmation. I should have (and post) a solution later today.

20 Jul 2016, 12:27 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

Re: checkout_payment: not submitting properly with GV balance

Today, tomorrow ...

I've reviewed the as-shipped Zen Cart modules (don't know if there are other order-totals lurking out there that also use the ***submitFunction ***interface and the ***submitter ***value). The built-in modules affected by the change are:

  1. /includes/classes/payments.php (conditional processing based on the submitter value)
  2. /includes/modules/order_total/ot_coupon.php (issues a submitFunction(0,0))
  3. /includes/modules/order_total/ot_gv.php (issues a submitFunction() and a submitFunction(0,0))
  4. /includes/modules/pages/checkout_payment/jscript_main.php (contains both the submitFunction and the submitter variable declarations)
  5. /includes/templates/YOUR_TEMPLATE/tpl_checkout_payment_default.php (issues a submitFunction (customers_gv_balance, orders_total)
    The key, in my mind, was to find a solution that didn't require multiple modules (especially the template) to be modified. Here's my change to the submitFunction processing (present in that jscript_main.php file) that appears to work. I've left the console.log calls intact; if they're left in the final output, they'll need a wrapper-function to be compatible with IE-8 and below:
/* -----
** Variable-argument function.  When supplied, arg1 is the customer's GV available-balance and arg2 is the order's total value.
*/
function submitFunction ()
{      
    var arg_count = arguments.length;
    submitter = null;
    var arg_list = '';
    for (var i = 0; i < arg_count; i++) {
        arg_list += arguments[i] + ', ';
    }
    console.log('submitFunction, '+arg_count+' arguments:'+arg_list);
    if (arg_count == 2) {
        var ot_codes = [].slice.call(document.querySelectorAll('[id^=disc-]'));
        for (var i = 0; i < ot_codes.length; i++) {
            if (ot_codes[i].value != '') {
                submitter = 1;
            }
        }
        var ot_gv = document.getElementsByName( 'cot_gv' );
        if (ot_gv) {
            console.log('Checking ot_gv value ('+ot_gv[0].value+') against order total ('+arguments[1]+')');
            if (ot_gv[0].value >= arguments[1]) {
                submitter = 1;
            }
        }
    }
    console.log('submitFunction, on exit submitter='+submitter);
}

The change presumes that any order-total returning a block for the credit_selection method identifies the associated input field with an id="disc-{something}" attribute.

This change recognizes that the submitter value only "matters" when the submit-button is pressed and sets that value to 1 when the page-submit request is associated with one or more of the following conditions:

  1. An order-total discount code is present on the page and is not empty, i.e. the customer has entered a coupon or GV code in the associated box.
  2. The ot_gv order-total is installed, the customer has a non-zero GV balance, has chosen to apply some/all to the order and that amount is >= the order's current total. In this case, no payment-module needs to be selected because the order's cost is covered by the voucher.
20 Jul 2016, 6:43 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

Re: checkout_payment: not submitting properly with GV balance

Oops, found another condition under which the submitter value should be set: When the order's total is 0, either as a result of a 100% coupon or it's a free product or whatever. I've also taken the liberty of filling in those blanks regarding my previous comment on using console.log and also supporting IE versions 8 and below.

The IE issue (this one, anyway) is due to the fact that those older versions of IE define the console and its associated methods only if the console window is currently open and will result in javascript errors unless checked prior to use.

/* -----
** Variable-argument function.  When supplied, arg1 is the customer's GV available-balance and arg2 is the order's total value.
*/
function submitFunction ()
{      
    var arg_count = arguments.length;
    submitter = null;
    var arg_list = '';
    for (var i = 0; i < arg_count; i++) {
        arg_list += arguments[i] + ', ';
    }
    zcLog2Console('submitFunction, '+arg_count+' arguments:'+arg_list);
    if (arg_count == 2) {
       [B] if (arguments[1] == 0) {
            submitter = 1;
        }[/B]
        var ot_codes = [].slice.call(document.querySelectorAll('[id^=disc-]'));
        for (var i = 0; i < ot_codes.length; i++) {
            if (ot_codes[i].value != '') {
                submitter = 1;
            }
        }
        var ot_gv = document.getElementsByName( 'cot_gv' );
        if (ot_gv) {
            zcLog2Console('Checking ot_gv value ('+ot_gv[0].value+') against order total ('+arguments[1]+')');
            if (ot_gv[0].value >= arguments[1]) {
                submitter = 1;
            }
        }
    }
    zcLog2Console('submitFunction, on exit submitter='+submitter);
}

function zcLog2Console (message)
{
    if (window.console) {
        if (typeof(console.log) == 'function') {
            console.log (message);
        }
    }
}
26 Jul 2016, 1:04 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,083
Plugin Contributions:
56

Re: checkout_payment: not submitting properly with GV balance

Darn it, here's another update. When the store doesn't support gift-certificates, a javascript error occurs:

/* -----
** Variable-argument function.  When supplied, arg1 is the customer's GV available-balance and arg2 is the order's total value.
*/
function submitFunction ()
{      
    var arg_count = arguments.length;
    submitter = null;
    var arg_list = '';
    for (var i = 0; i < arg_count; i++) {
        arg_list += arguments[i] + ', ';
    }
    zcLog2Console('submitFunction, '+arg_count+' arguments:'+arg_list);
    if (arg_count == 2) {
        if (arguments[1] == 0) {
            submitter = 1;
        }
        var ot_codes = [].slice.call(document.querySelectorAll('[id^=disc-]'));
        for (var i = 0; i < ot_codes.length; i++) {
            if (ot_codes[i].value != '') {
                submitter = 1;
            }
        }
        var ot_gv = document.getElementsByName( 'cot_gv' );
        if (ot_gv[B].length != 0[/B]) {
            zcLog2Console('Checking ot_gv value ('+ot_gv[0].value+') against order total ('+arguments[1]+')');
            if (ot_gv[0].value >= arguments[1]) {
                submitter = 1;
            }
        }
    }
    zcLog2Console('submitFunction, on exit submitter='+submitter);
}

function zcLog2Console (message)
{
    if (window.console) {
        if (typeof(console.log) == 'function') {
            console.log (message);
        }
    }
}