If this is your first visit, check our documentation. To post, register or login.
Forums / Configuring the Zen Cart Admin / Built-in Shipping and Payment Modules / Former Chosen Payment Method Kept in Session, even if not available anymore

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

Started by todoonada on 13 Oct 2023, 6:54 AM · Views: 2,652

Results 1 to 8 of 8
13 Oct 2023, 6:54 AM
#1
todoonada avatar

todoonada

Zen Follower

Join Date:
Nov 2006
Posts:
127
Plugin Contributions:
0

Post #1 by todoonada

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

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

13 Oct 2023, 9:26 AM
#2
lat9 avatar

lat9

Administrator

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

Post #2 by lat9

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
// -----
// 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".

13 Oct 2023, 11:42 PM
#3
todoonada avatar

todoonada

Zen Follower

Join Date:
Nov 2006
Posts:
127
Plugin Contributions:
0

Post #3 by todoonada

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

14 Oct 2023, 12:33 AM
#4
lat9 avatar

lat9

Administrator

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

Post #4 by lat9

My bad, the better version of the code is

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

14 Oct 2023, 3:03 AM
#5
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,908
Plugin Contributions:
23

Post #5 by dbltoe

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

todoonada:

Thank you, sir! That solves the problem

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

14 Oct 2023, 5:12 AM
#6
todoonada avatar

todoonada

Zen Follower

Join Date:
Nov 2006
Posts:
127
Plugin Contributions:
0

Post #6 by todoonada

lat9:

My bad, the better version of the code is

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

dbltoe:

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

Not a native English speaker, not sure if I get it.

14 Oct 2023, 9:18 AM
#7
lat9 avatar

lat9

Administrator

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

Post #7 by lat9

todoonada:

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.

16 Oct 2023, 1:29 AM
#8
todoonada avatar

todoonada

Zen Follower

Join Date:
Nov 2006
Posts:
127
Plugin Contributions:
0

Post #8 by todoonada

lat9:

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