Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Former Chosen Payment Method Kept in Session, even if not available anymore

    This error occurs on ZC 1.5.8. On version 1.5.7d it is not a problem.

    The situtation:
    I got two shipping methods. One allows payment by cash on delivery (COD) among other payment methods, the other does not.
    I go to checkout, choose the shipping which allows COD, go to payment, choose COD, go to checkout confirmation. Everything is displayed correctly. I do not check out.
    Now I changed my mind and click on "Checkout" in the top menu, to start the whole process again. This time I choose the shipping option, which does not allow COD. Next screen is checkout payment. There is no more COD option for payment. The radio button for the other payment option (bank transfer) is not active. On version 1.5.8 I can click on the "Continue" button, even no payment option is chosen and go to the next screen. The next screen shows COD as payment option, which is wrong. There is no COD fee of course.
    On version 1.5.7d I get an error when I click the "continue" button without choosing a payment option.

    I made the following code modification to disable COD on the flat shipping method:
    In file includes/templates/template_default/templates/tpl_checkout_payment_default.php line 124

    Code:
    <?php
        if (sizeof($selection) > 1) {
            if (empty($selection[$i]['noradio'])) {
     ?>
    <!-- Start my code -->
      <!-- If flat is shipping method, do not display COD option -->
    <?php
        if($_SESSION['shipping']['id']=='flat_flat' && $selection[$i]['id']=='cod')
            continue;
    ?>
    <!-- End my code -->
    
    
    <?php echo zen_draw_radio_field('payment', $selection[$i]['id'], ($selection[$i]['id'] == ($_SESSION['payment'] ?? '')), 'id="pmt-'.$selection[$i]['id'].'"'); ?>
    If anybody got any idea, how I can fix it, I am happy to hear it.
    Last edited by todoonada; 13 Oct 2023 at 07:58 AM.

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

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    While I can't explain why that worked on zc157 and not on zc158, a more reliable method (that will also work for any template that you use) would be to create a file (/includes/modules/pages/checkout_payment/header_php_no_cod_for_flat.php) that contains:

    PHP Code:
    <?php
    // -----
    // Don't allow cod payment method if flat-rate shipping is chosen.
    //
    if ($_SESSION['shipping']['id'] === 'flat_flat' && $_SESSION['payment'] === 'cod') {
        unset(
    $_SESSION['payment']);
    }
    That requires that the customer re-select their payment method if the currently-chosen shipping method is "Flat Rate" and the currently-chosen payment method is "cod".

  3. #3
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    Thank you, sir! That solves the problem
    I have to add, that I have to keep my original code, otherwise the COD option is displayed when flat shipping is chosen.
    I added your file and now it is not possible to advance to the next screen if no payment option is chosen.

    Two questions:
    In your code should the php-section starting with <?php be closed with ?> ? Both work, but which is technically correctly?

    The code throws a php warning:
    PHP Warning: Undefined array key "payment" in zencart-1.5.8/includes/modules/pages/checkout_payment/header_php_no_cod_for_flat.php

    I guess it might be an error in future versions of php. I have quite a lot of the same types of warnings in other files. Do you know how to prevent this warning?

    Thank you

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

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    My bad, the better version of the code is

    PHP Code:
     <?php
    // -----
    // Don't allow cod payment method if flat-rate shipping is chosen.
    //
    if ($_SESSION['shipping']['id'] === 'flat_flat' && isset($_SESSION['payment']) && $_SESSION['payment'] === 'cod') {
        unset(
    $_SESSION['payment']);
    }
    Note the blank line after the ending }. Current PHP programming suggests not using a ?> unless 'changing' to HTML output mode.

  5. #5
    Join Date
    Jan 2004
    Location
    N of San Antonio TX
    Posts
    9,155
    Plugin Contributions
    11

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    She must be really busy to let you get by with that one.

    Quote Originally Posted by todoonada View Post
    Thank you, sir! That solves the problem

  6. #6
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    Quote Originally Posted by lat9 View Post
    My bad, the better version of the code is

    PHP Code:
     <?php
    // -----
    // Don't allow cod payment method if flat-rate shipping is chosen.
    //
    if ($_SESSION['shipping']['id'] === 'flat_flat' && isset($_SESSION['payment']) && $_SESSION['payment'] === 'cod') {
        unset(
    $_SESSION['payment']);
    }
    Note the blank line after the ending }. Current PHP programming suggests not using a ?> unless 'changing' to HTML output mode.
    Thank you. Good to know.

    Quote Originally Posted by dbltoe View Post
    She must be really busy to let you get by with that one.
    Not a native English speaker, not sure if I get it.

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

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    Quote Originally Posted by todoonada View Post
    Not a native English speaker, not sure if I get it.
    @dbltoe was referring to your "Thank you, sir", which I normally correct because I'm a ma'am.

  8. #8
    Join Date
    Nov 2006
    Posts
    108
    Plugin Contributions
    0

    Default Re: Former Chosen Payment Method Kept in Session, even if not available anymore

    Quote Originally Posted by lat9 View Post
    @dbltoe was referring to your "Thank you, sir", which I normally correct because I'm a ma'am.
    It is a "Sorry and thank you, ma'am" then.

 

 

Similar Threads

  1. v151 Disable a payment method for a chosen shipping method?
    By chowyungunz in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 12 Jun 2015, 12:56 PM
  2. No Payment Options - This is currently the only payment method available to use on ..
    By keeno79 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 11 May 2009, 02:58 PM
  3. Only show payment method when UPS shipping method chosen?
    By helen610 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 28 Aug 2008, 03:04 AM
  4. Session not available when file is called by ajax
    By yellow1912 in forum Contribution-Writing Guidelines
    Replies: 1
    Last Post: 19 Aug 2008, 04:52 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