I am trying to add some changes to the latest USPS (K6) to test for media mail eligibility. I added a new table that has two fields -- products_id and media_mail_eligible. I have made a number of changes in files to make this work, and it does seem to. The last change now is in usps.php -- test each item to see if its media mail eligible. If the number of items in the cart equals number of media mail items, then allow media mail. Otherwise, don't show that option.
The code isn't working, it allows media mail for everything. But more importantly it crashed Paypal integration. When clicking on PayPal option on shopping cart screen, the page goes white. The logs show this error:
Code:
[03-Nov-2014 19:07:26 America/Los_Angeles] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/walbur5/public_html/includes/modules/shipping/usps.php:1) in /home/walbur5/public_html/includes/modules/payment/paypalwpp.php on line 1635
[03-Nov-2014 19:07:26 America/Los_Angeles] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/walbur5/public_html/includes/modules/shipping/usps.php:1) in /home/walbur5/public_html/includes/functions/functions_general.php on line 46
If I replace my revised usps.php with the original K6, PayPal works fine -- but of course doesn't have any of my code.
The code I added replaces the example of $chk_cart for categories.
PHP Code:
if (true) {
error_log($_SESSION['cart']->count_contents() . ' items in cart -- ' . $type );
$skip_media = 0;
$chk_cart = 0;
$chk_cart += $_SESSION['cart']->in_cart_media_check('media_mail_eligible','1'); // 1 means media mail eligible
//if $chk)cart = the entire contents of hte cart, then media mail eligible
if ($chk_cart = $_SESSION['cart']->count_contents()) {
$skip_media = 0; // false
} else {
$skip_media = 1; // true
}
error_log($chk_cart . ' media mail eligible items -- ' . $type . 'skip_media = ' . $skip_media );
// $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','15');
}
I created the new function in_cart_media_check since I don't use the products table for storing the info, but the new table. I simply changed the appropriate code to work. It seems to work (based on error_log output).
2nd code change:
PHP Code:
if (true) {
if ($skip_media == 1 && $type == 'Media Mail Parcel') {
continue;
}
}
I will admit I don't quite understand what the test is doing -- I simply left it from the original code, which seemed to imply that the test looked for cases where the example (Priority Mail small box) shouldn't be allowed and "continue" made that happen, but I think that must be wrong.
So there's two questions (which perhaps should be divided into two forum topics, but the code is the same for both):
1) How did I lose Paypal?
2) what is wrong with this code that it can't skip media mail when it should?
I am attaching the whole usps.php file in case something strange has been added that the above code isn't the cause of-- since the PayPal error suggests line 1. Thanks for all the help!
Bookmarks