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.
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".
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
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.
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.:smile:
Quote:
Originally Posted by
todoonada
Thank you, sir! That solves the problem
Re: Former Chosen Payment Method Kept in Session, even if not available anymore
Quote:
Originally Posted by
lat9
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
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.
Re: Former Chosen Payment Method Kept in Session, even if not available anymore
Quote:
Originally Posted by
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.
Re: Former Chosen Payment Method Kept in Session, even if not available anymore
Quote:
Originally Posted by
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.