Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default 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.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default 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:
    Code:
    <div class="buttonRow forward" id="paymentSubmit"><?php echo zen_image_submit(BUTTON_IMAGE_CONTINUE_CHECKOUT, BUTTON_CONTINUE_ALT, 'onclick="submitFunction('.zen_user_has_gv_account($_SESSION['customer_id']).','.$order->info['total'].')"'); ?></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):
    Code:
    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:
    Code:
           $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.

  3. #3
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default Re: checkout_payment: not submitting properly with GV balance

    Quote Originally Posted by DrByte View Post
    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.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default 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:
    Code:
    /* -----
    ** 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.

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default 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.
    Code:
    /* -----
    ** 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) {
                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);
            }
        }
    }

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,492
    Plugin Contributions
    88

    Default 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:
    Code:
    /* -----
    ** 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.length != 0) {
                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);
            }
        }
    }

 

 

Similar Threads

  1. Replies: 2
    Last Post: 12 Apr 2013, 09:27 AM
  2. issues with customized icons not displaying properly
    By svazquez in forum General Questions
    Replies: 1
    Last Post: 4 Nov 2009, 10:18 AM
  3. Category Descriptions With Subcategories Not Showing Properly
    By jmellon in forum Templates, Stylesheets, Page Layout
    Replies: 25
    Last Post: 23 Sep 2009, 02:02 PM
  4. Invoice - Balance due not calculating correctly with module "Edit Orders"
    By AATECH in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 25 Sep 2008, 07:40 PM
  5. Tax is not calculating properly with shipping
    By jenaustin in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 31 Aug 2006, 01:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR