Jump to content
fulluvscents

USPS Rate V4, Intl Rate V2 (official support thread)

Recommended Posts

Thanks for sharing your work.  I'm not a programmer, so this should be very helpful.

I will be giving it try.

 

 

Share this post


Link to post
Share on other sites

I had a lot of problems with 1.0.4.1 and waited for 1.0.4.3.  3 is giving some problems, but have been able to work through most.  This hook thing is way over my head.  I'm not a programmer but follow most directions.  

I installed 1.0.4.3, a lot of changes.  I've been working on getting it ready to go live.  I want to load up this USPS package.  I been using it for years under OSC BS 2.3.4. 

Has anyone updated the program to run with Phoenix 1.0.4.3 and beyond.  If so is it on the app site to down load?  The last time I checked on 'USPS Rate V4, Intl Rate V2' it was updated 2 years ago. 

 

 

Share this post


Link to post
Share on other sites

I started with r1.8 and the last time I looked, I could not find it on the Apps Marketplace.

Hmm … guess it was my search error, because it's there, now.  Anyway, those files in my post a page back should work if you start with the r1.8 version, uploaded by kymation as you say - 2 years ago.

 

Do this to the database:

Quote

 

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Country of Origin', 'SHIPPING_ORIGIN_COUNTRY', '223', 'Select the country of origin to be used in shipping quotes.', '7', '1', 'tep_get_country_name', 'tep_cfg_pull_down_country_list(', now());


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Postal Code', 'SHIPPING_ORIGIN_ZIP', 'NONE', 'Enter the Postal Code (ZIP) of the Store to be used in shipping quotes.', '7', '2', now());

 

Then do the stuff in this post: 

It should work.  I've had to re-edit the modules.php file with every update of Phoenix, but my USPS shipping has been working all the way through from 1.0.4.0 to 1.0.5.0.

I've posted this before for you, so if it doesn't work, I apologize.  There may be something else with your store that's different that we're not taking into account.

Edited by TomB01

Share this post


Link to post
Share on other sites

Is their a new upgrade to go with Phoenix 1.0.5.4?

I have been using this add on for years with OSC 2.3.4 and w/BS. 

I'm trying to convert over to Phoenix, I haven't gone live because Phoenix is to unstable for me.  I still need to add and would like it to be this one, USPS shipping package.  One that Phoenix will not knock out on every update. 

Can someone please update the wonderful package?

Thanks

 

Share this post


Link to post
Share on other sites

@dculley stable releases for Phoenix are the .0 releases eg. 1.0.5.0 and 1.0.6.0

Even addons that are actively maintained are unlikely to keep step with every increment.


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites
52 minutes ago, BrockleyJohn said:

@dculley stable releases for Phoenix are the .0 releases eg. 1.0.5.0 and 1.0.6.0

Even addons that are actively maintained are unlikely to keep step with every increment.

The problem is not that it needs to be updated with every increment.  The problem is that the current version of this module requires a core change (to admin/modules.php ).  So every time that the modules.php file gets updated, it wipes out the core change which then needs to be reapplied. 

This could be fixed by adding a hook file or database defined hook to replace the core change.  The hook point was added in this commit.  But no one has updated the package with that.  @greasemonkey uses that hookpoint for another module requiring the same change. 

Someone could also modify the module to use the standard form:  https://github.com/gburton/CE-Phoenix/blob/master/admin/modules.php#L40..L42.  That might avoid the need for a hook.  But again, no one has updated the module to to do that. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

I've started getting an intermittent error with usps.php:

Quote

Warning: Invalid argument supplied for foreach() in
/***/***/***/***/catalog/includes/modules/shipping/usps.php on line 126 

Line 126 in usps.php shows this (along with the rest of the foreach loop):

Quote

          foreach ($Package['ExtraServices']['ExtraService'] as $key => $val) {
            if ( is_array ( $val ) && 
                 array_key_exists ( 'ServiceName', $val ) && 
                 isset ( $iExtras[$val['ServiceName']] ) && 
                 tep_not_null($iExtras[$val['ServiceName']]) && 
                 ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && 
                     $val['AvailableOnline'] == 'True') || 
                   (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && 
                     $val['Available'] == 'True'))) {
              $val['ServiceAdmin'] = $iExtras[$val['ServiceName']];
              $Services[] = $val;
            }

Any clues?  I'm running Phoenix 1.0.5.0 and have the correcting "implode" code in modules.php.
 

Share this post


Link to post
Share on other sites

Looks like it may be an intermittent issue with the USPS server.

Share this post


Link to post
Share on other sites

OK, it's not the USPS server.  The error is 100% consistent and repeatable this morning on my live store:

Warning: Invalid argument supplied for foreach() in
/***/***/***/***/catalog/includes/modules/shipping/usps.php on line 126 

The foreach loop in the usps.php file is as posted above:

126. foreach ($Package['ExtraServices']['ExtraService'] as $key => $val) {
            if ( is_array ( $val ) && 
                 array_key_exists ( 'ServiceName', $val ) && 
                 isset ( $iExtras[$val['ServiceName']] ) && 
                 tep_not_null($iExtras[$val['ServiceName']]) && 
                 ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && 
                     $val['AvailableOnline'] == 'True') || 
                   (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && 
                     $val['Available'] == 'True'))) {
              $val['ServiceAdmin'] = $iExtras[$val['ServiceName']];
              $Services[] = $val;
            }

This only happens on International addresses, not domestic (US) ones.  The ExtraServices are as follows:

Registered Mail, N, Insurance, N, Return Receipt, N, Restricted Delivery, N, Pick-Up, N, Certificate of Mailing, N

As can be seen, I've selected NO (N) ExtraServices.

 

The error is printed 12 times ahead of drawing in the checkout_shipping.php page on the browser.  Once the checkout_shipping.php page is drawn in, there are 3 USPS quotes, and a couple each of UPS and FedEx quotes, now all showing correctly.  I guess it's going through the foreach loop 12 times, which is why the error message prints out that many times.

As best I can tell using file comparisons, etc., the files and database settings on both my live store and test store are identical, but only the live store shows the errors.  In addition, I am manually re-writing the admin/modules.php file with each Phoenix update (I'm at 1.0.5.0) with the following code inserted:

//
//Correction for legacy shipping modules
//        
            
         if (is_array($value) ) {
            $value = implode( ", ", $value);
                $value = preg_replace ("/, --none--/", "", $value);
              }
//
//End correction for legacy shipping modules
//                
  

Ideas? Help?

Share this post


Link to post
Share on other sites

My guess would be that USPS changed something.  This surfaced intermittently because they only changed it on some servers at first.  It is now always wrong because they've updated everything. 

7 hours ago, TomB01 said:

I guess it's going through the foreach loop 12 times, which is why the error message prints out that many times.

No, that error means that it isn't looping through that foreach at all.  It may be reaching that section of code twelve times. 

The simplest thing that you could try would be to change 126 to

foreach (($Package['ExtraServices']['ExtraService'] ?? []) as $key => $val) {

That will probably suppress the error.  If it doesn't, try wrapping the entire loop in

if (is_array($Package['ExtraServices']['ExtraService'] ?? null)) {
  //foreach here
  //} end of foreach
}

That should suppress the error but something may still not be working. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

This is about the right time of year for USPS to break the API. That said, it might simply be that it's always been like that but the warning message was suppressed before. As it's only a warning you're not changing what the code does with Matt's changes, you're just telling it to expect the array could be empty or not exist. If there are no extra services there's nothing to process so there might not be any drama.

Of course, if USPS have changed the structure of the data returned and put the information in a different place then it will need fixing.


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites
Posted (edited)
9 hours ago, BrockleyJohn said:

This is about the right time of year for USPS to break the API. That said, it might simply be that it's always been like that but the warning message was suppressed before. As it's only a warning you're not changing what the code does with Matt's changes, you're just telling it to expect the array could be empty or not exist. If there are no extra services there's nothing to process so there might not be any drama.

Of course, if USPS have changed the structure of the data returned and put the information in a different place then it will need fixing.

@ecartz and @BrockleyJohn,

I greatly appreciate you both adding to the thread and offering suggestions!

I agree that USPS regularly breaks the API from time-to-time.  That's definitely been the history since I've been using OsCommerce, over a decade ago.  However, this is not new.  @ArtcoInc had the very same issue a couple of pages back in this thread, in early September of 2019:

About the only difference is that his error message says line 132; mine is line 126 - but it's the same foreach statement.

I implemented the very first suggestion that @ecartz made like so:

foreach (($Package['ExtraServices']['ExtraService'] ?? []) as $key => $val) {

That appears to have worked!  As BrockleyJohn said, maybe it was just a warning (but horribly presented to customers) and it looks like it's now suppressed.

MANY THANKS!

Edited by TomB01

Share this post


Link to post
Share on other sites

@TomB01

I'm under phx v 1.0.5.8 NOT live yet.

I'm getting ready to upload USPS  Rate V4 Intl Rate V2_r1.8.  I copied down the 'modules.php' and used compare "winmerge' program to check the changes to the admin/modules.php in 1.0.5.8.  The modules.php I took off the forum is no were close to the one in v8 of phx.  So I became nervous to upload. 

What do I need to do?

 

Share this post


Link to post
Share on other sites
Posted (edited)
3 hours ago, dculley said:

@TomB01

I'm under phx v 1.0.5.8 NOT live yet.

I'm getting ready to upload USPS  Rate V4 Intl Rate V2_r1.8.  I copied down the 'modules.php' and used compare "winmerge' program to check the changes to the admin/modules.php in 1.0.5.8.  The modules.php I took off the forum is no were close to the one in v8 of phx.  So I became nervous to upload. 

What do I need to do?

 

Well, you're way ahead of me.  I stopped at 1.0.5.0 and am waiting until 1.0.6.0 to upgrade.

That said, this is the section of code that is in the modules.php file (/catalog/admin/) that has the corrections.  I insert the lines bordered by the comments into the modules.php file, every time I load a new update to Phoenix.  I don't think it really matters if there are other changes to the file, as long as the section below stays the same.

If you don't insert the commented code below, when you attempt to set the parameters for the shipping module in Admin, you'll lose all of the settings and future attempts won't save it back to the database.  (IOW, it becomes corrupted.)  The code that I insert is bordered below by the "Correction/End Correction for legacy shipping modules" section (it also applies to UPSxml add-on and I think the FedEx Web services add-on):

  if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
        foreach ($_POST['configuration'] as $key => $value) {
//
//Correction for legacy shipping modules
//		
			
		 if (is_array($value) ) {
            $value = implode( ", ", $value);
                $value = preg_replace ("/, --none--/", "", $value);
              }
//
//End correction for legacy shipping modules
//				
          tep_db_query("update configuration set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
        }
        tep_redirect(tep_href_link('modules.php', 'set=' . $set . '&module=' . $_GET['module']));
        break;
      case 'install':
      case 'remove':
        $file_extension = substr($PHP_SELF, strrpos($PHP_SELF, '.'));
        $class = basename($_GET['module']);
        if (file_exists($module_directory . $class . $file_extension)) {
          // include lang file
          include($module_language_directory . $language . '/modules/' . $module_type . '/' . $class . $file_extension);
          include($module_directory . $class . $file_extension);
          $module = new $class;
          if ($action == 'install') {
            if ($module->check() > 0) { // remove module if already installed
              $module->remove();
            }

            $module->install();

            $modules_installed = explode(';', constant($module_key));

            if (!in_array($class . $file_extension, $modules_installed)) {
              $modules_installed[] = $class . $file_extension;
            }

            tep_db_query("update configuration set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");
            tep_redirect(tep_href_link('modules.php', 'set=' . $set . '&module=' . $class));
          } elseif ($action == 'remove') {
            $module->remove();

            $modules_installed = explode(';', constant($module_key));

            if (in_array($class . $file_extension, $modules_installed)) {
              unset($modules_installed[array_search($class . $file_extension, $modules_installed)]);
            }

            tep_db_query("update configuration set configuration_value = '" . implode(';', $modules_installed) . "' where configuration_key = '" . $module_key . "'");
            tep_redirect(tep_href_link('modules.php', 'set=' . $set));
          }
        }
        tep_redirect(tep_href_link('modules.php', 'set=' . $set . '&module=' . $class));
        break;
    }
  }

Note that as mentioned in an earlier post up there, you must add these items to the configuration table in the database:

Quote

INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Country of Origin', 'SHIPPING_ORIGIN_COUNTRY', '223', 'Select the country of origin to be used in shipping quotes.', '7', '1', 'tep_get_country_name', 'tep_cfg_pull_down_country_list(', now());


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Postal Code', 'SHIPPING_ORIGIN_ZIP', 'NONE', 'Enter the Postal Code (ZIP) of the Store to be used in shipping quotes.', '7', '2', now());

Also note the change recommended by ecartz that I had to add to the usps.php file (line 126):

Anyway, see if that works -

Edited by TomB01

Share this post


Link to post
Share on other sites

@TomB01

 

Thanks for getting back to me.  I will try this.  Gust one question.  Where do I insert the above code in modules.php?

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, dculley said:

@TomB01

 

Thanks for getting back to me.  I will try this.  Gust one question.  Where do I insert the above code in modules.php?

The only part you insert is that part bounded by the comments for "//Correction …" and "//End correction …"

//
//Correction for legacy shipping modules
//		
			
		 if (is_array($value) ) {
            $value = implode( ", ", $value);
                $value = preg_replace ("/, --none--/", "", $value);
              }
//
//End correction for legacy shipping modules
//

Use the rest of the code that I pasted in with that to find the proper place in the modules.php.  IOW, look for this section:

if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
        foreach ($_POST['configuration'] as $key => $value) {

Insert the "//Correction - //End correction" code on the next line after the last "{" shown immediately above.  Go back up to my previous post if you don't understand, and look for where that "//Correction - //End correction" code is placed.

Edited by TomB01

Share this post


Link to post
Share on other sites

@TomB01

I was following, I saw under your Modules.php line 36 - 92.  I added //Continued from line 36 USPS V4 and //End USPS V4.  So I would know your part.  Than I went to compare files and saw that just inserting would not be the same.  Being I'm not a programmer but purity good at following instructions.   I stopped when I saw the 'hook' coding.  On the Phx side modules.php the code starts on line 41 - 112.  I was truly afraid of missing up.  I'm attaching your modules.php and Phx's.  So you can see.   

I'm no rush.  Look forward to your advice.  And thanks for all your help.

modulesphx.php

modulesyours.php

Share this post


Link to post
Share on other sites

@dculley

modulesphx.php shows this from lines 40 to 47:

        foreach ($_POST['configuration'] as $key => $value) {
          if (is_array($value)) {
            $value = implode(';', $value);
          }

          $key = tep_db_prepare_input($key);
          $value = tep_db_prepare_input($value);
          tep_db_query("UPDATE configuration SET configuration_value = '" . tep_db_input($value) . "' WHERE configuration_key = '" . tep_db_input($key) . "'");

modulesyours.php shows this from lines 35 to 47:

        foreach ($_POST['configuration'] as $key => $value) {
/* kymation mod for Phoenix (11/26/2019) - https://forums.oscommerce.com/topic/383307-usps-rate-v4-intl-rate-v2-official-support-thread/?do=findComment&comment=1793962 */			
//			if( is_array( $value ) )  $value = implode( ', ', $value );
//End kymation mod for Phoenix
//
/* Updated mod in greasemonkey post (11/30/2019) - https://forums.oscommerce.com/topic/494460-ups-xml-17-for-phoenix/?do=findComment&comment=1799248 */
          if (is_array($value) ) {
            $value = implode( ", ", $value);
		        $value = preg_replace ("/, --none--/", "", $value);
		      } 
// End greasemonkey mod
// Continued from line 36 USPS V4
          tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");

Except for the comments, they are essentially the same, except for these two lines:

          $key = tep_db_prepare_input($key);
          $value = tep_db_prepare_input($value);

There was an additional line included by ecartz in the version that I use, but it was mainly applied by user greasemonkey when he was trying to get UPS XML to work.  I've tried it both ways on my installs and it doesn't seem to make a difference, but I kept it just in case.  So, the operative code is this in the NEW Phoenix modules.php:

          if (is_array($value)) {
            $value = implode(';', $value);
          }

Whereas, we were previously including this:

          if (is_array($value) ) {
            $value = implode( ", ", $value);
		        $value = preg_replace ("/, --none--/", "", $value);
		      } 

Without knowing exactly what these changes mean, it appears to me that the newest Phoenix version included the corrective code in the modules.php file by default, except for that seemingly superfluous code ecartz suggested for greasemonkey:

$value = preg_replace ("/, --none--/", "", $value);

The newest Phoenix modules.php includes those new "$key" and "$value" statements above, but those are assigning variables, so I'm not sure there going to interfere with anything (probably something with the Hooks call).  My guess is that you should simply try the newest Phoenix modules.php file - without editing anything - and see if it works.

Do you have a test store installed?  If not, I'd work on that so that you can simply test these things without worry of crashing your live store.  Try it and see if it works.  As stated, there's definitely extra code and features in the newest modules.php file.  However, it appears that Burt and crew have included the important "if (is_array($value)) { $value = implode(", etc., correcting code as standard in modules.php now.

Remember that the only thing that this modules.php correction changed was how the module settings in Admin were saved.  Without that code (it appears it's included by default, now), if you went to change/edit the module settings in Admin, it would lose/change all the configuration values for the usps.php module.  Worst case, you could manually punch those values back into the configuration table in phpAdmin.  (Granted, that would be a lot of work for the USPS module, because there's a ton of settings.)

If you try it and it doesn't work, maybe we can elevate this to ecartz or someone else and see if they can figure it out. 

Share this post


Link to post
Share on other sites

@TomB01

Still on V1.0.5.8 not live - test site

Okay I'm moving ahead. Didn't modify the the 'modules.php' file.  Working on the settings and I see this: 

image.png.cbf7642e647c7485410e30a1c03f6d73.png

Not use to this and the amount side seems to be cut off.  Thought I would stop there.  Before going on with a full test.  Any Idea's?

Thanks

Share this post


Link to post
Share on other sites

@TomB01

I tried typing in the cells and nothing goes in.  When I go to the $ side 1.00 in and click enter or anything nothing saves it just kicks me back the modules/shipping screen.

Share this post


Link to post
Share on other sites

@TomB01

i for got to turn on the error display This is my error


Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_STATUS already defined in /home/xxxxxx/xxxxxx/admin/includes/application_top.php on line 65

Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_CONTENT_WIDTH already defined in /home/xxxxx/txxxxx/admin/includes/application_top.php on line 65

Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_SORT_ORDER already defined in /home/xxxxx/xxxxx/admin/includes/application_top.php on line 65

Share this post


Link to post
Share on other sites
7 minutes ago, dculley said:

@TomB01

i for got to turn on the error display This is my error


Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_STATUS already defined in /home/xxxxxx/xxxxxx/admin/includes/application_top.php on line 65

Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_CONTENT_WIDTH already defined in /home/xxxxx/txxxxx/admin/includes/application_top.php on line 65

Notice: Constant MODULE_CONTENT_FORGOT_PASSWORD_SORT_ORDER already defined in /home/xxxxx/xxxxx/admin/includes/application_top.php on line 65

Opps another program.

Share this post


Link to post
Share on other sites
Posted (edited)

@dculley

I'm sorry - this is beyond me.

As for the "(;" I see something similar at the bottom of my Order-Summary-Products-Status History-Paypal page, but it seems innocuous, so I left it alone.  It's some sort of trailing code that the PHP is not recognizing.

Hopefully, someone else will have some suggestions.

Keep me in mind if you end up willing to pay someone to do a USPS module for Phoenix.  I might be able to chip in something.

EDIT: The other possible issue is going well beyond Phoenix 1.0.5.0.  The changes they made in going to 1.0.5.1 were severe.  It's why I stopped at 1.0.5.0.  I'm not sure we can even make the shipping modules work under the newer changes.

Edited by TomB01

Share this post


Link to post
Share on other sites

@TomB01

I also noticed in going over the old install text it wants under admin/configurations/shipping packaging to set up country of origin & postal code.  Under Phx it is not there to set up.  This might be another problem. 

 

 

 

Share this post


Link to post
Share on other sites

Yes, of course!  Please note my previous posts.  There are two SQL statements included that you need to poke the appropriate values into the configuration table.  They are in my most recent posts (typing this on the phone right now, or I'd copy them again for you).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×