Jump to content
Sign in to follow this  
TomB01

UPS XML 1.7 for Phoenix

Recommended Posts

Trying to get this to work with Phoenix 1.0.4.0.  I edited the upsxml.php file to use 'includes/classes/' instead of DIR_WS_CLASSES.  So, I was able to install and enter all of the appropriate info.  I get two errors, one not so bad, I think, but the other blows up the checkout.

In Admin, I get the following, but it appears to have saved all the values I entered anyway:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none-- in /home1/xxxx/public_html/xxxx/catalog/includes/modules/shipping/upsxml.php on line 1128

In the checkout, it blows up with this:

1146 - Table 'my-database.TABLE_ZONES' doesn't exist

select zone_code from TABLE_ZONES where zone_name = 'Tennessee' and zone_country_id = '223' and length(zone_code) > 0

[TEP STOP]

The Zones table definitely exists and the Zone_code for Tennessee shows "56."

(I also tried UPS Choice and I think there's no chance with that.  Besides, I prefer one that uses a UPS account.)

Share this post


Link to post
Share on other sites

@TomB01

change:

select zone_code from TABLE_ZONES where zone_name = 'Tennessee' and zone_country_id = '223' and length(zone_code) > 0

to:

select zone_code from zones where zone_name = 'Tennessee' and zone_country_id = '223' and length(zone_code) > 0

 

Basically, change TABLE_ZONES to zones .

M


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

Thanks.

Let me ask - should I delete all instances of "TABLE_"?  It appears dozens of times in the upsxml.php file, mostly with "TABLE_CONFIGURATION," but there are "TABLE_ZONES," too.

I'm also getting a similar error message with FedEx WebServices.

Share this post


Link to post
Share on other sites

OK, so it appears the files are case sensitive with the table names.  I'm not sure why that is, because my existing store's database tables appear in PHPMyAdmin in lower case, but the UPS and FedEx files are un-edited and everything works.

I tried deleting "TABLE_" from "TABLE_CONFIGURATION," etc., but found it would not work until I corrected all instances with "configuration."  I also did that with "TABLE_ZONES," changing it to "zones."  That removed all of the errors.  The checkout no longer blows up, but there are no options for UPS (my USPS options continue to work and show shipping costs).  So, I'm thinking that error in the Admin may be more significant than I thought:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none-- in /home1/tomb/public_html/pho-bzr/catalog/includes/modules/shipping/upsxml.php on line 1128

In the upsxml.php file, it says the UPS_SERVICE_CODES are defined in the languages file.  Is there some reason it can't find it?  The UPS_SERVICE_CODES basically define all of the services, so if it's not finding that, I guess Phoenix thinks there are no UPS shipping options to display.

Edited by TomB01

Share this post


Link to post
Share on other sites
2 minutes ago, greasemonkey said:

@TomB01 did you figure out the issue with the constant?

I’m updating the Canada Post Shipping module, which was based on the UPS module and having the same issue. 

See the above I just posted.  Short answer: No.

Share this post


Link to post
Share on other sites
39 minutes ago, TomB01 said:

Let me ask - should I delete all instances of "TABLE_"?  It appears dozens of times in the upsxml.php file, mostly with "TABLE_CONFIGURATION," but there are "TABLE_ZONES," too.

One of the major changes of Phoenix is the removal of the TABLE_ defines ... so basically yes.

For example you should change TABLE_ZONES to zones

And TABLE_CONFIGURATION to configuration

etc.etc

Share this post


Link to post
Share on other sites

@azpro thank you.... I think both @TomB01 and I are good with the tables defines.

We are having an issue with the constant in the below function:

  function get_multioption_upsxml($values) {
    if (tep_not_null($values)) {
      $values_array = explode(',', $values);
      foreach ($values_array as $key => $_method) {
        if ($_method == '--none--') {
          $method = $_method;
        } else {
          $method = constant('UPS_SERVICE_CODE_' . trim($_method));
        }
        $readable_values_array[] = $method;
      }
      $readable_values = implode(', ', $readable_values_array);
      return $readable_values;
    } else {
      return '';
    }
  }

 

Share this post


Link to post
Share on other sites

@greasemonkey

Yep  - that's it exactly.  The UPS_SERVICE_CODE constants are defined in the languages file, but the error says it can't find the constant(s).

Share this post


Link to post
Share on other sites

@TomB01

Back in the day, osC had two files: database_tables.php and filenames.php. These were in the catalog/includes/ directory. There were another set of these in the catalog/admin/includes/ directory. These files defined all of the referenced file names and database tables.

In the evolution of the Community Edition of osC (which Phoenix is), these files were removed, and all of the references were hard coded.

Many of the more popular add-ons have been updated to hard code these filenames and/or database tables. But, there are still a number of popular add-ons that have not be so updated.

If you are trying to install one of these older add-ons, you will need to makes these changes:

When there is a TABLE_xxxxx, you need to change that to the actual table name, *usually* what is in the xxxxx place. Best practices say to type it in lower case, but that shouldn't really matter.

Where there is a FILE_xxxxx, you need to change that to the actual file name, *usually* using what is in the xxxxx place (so, it would become 'xxxxx.php' (yes, you need the single quotes, and add the .php to the end)).

There are also other changes that will need to be made to bring the add-on up to PHP 7 compatibility.

HTH

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

@greasemonkey  I don't know this contribution - but just reading the code ..

The function tries to built $method to something like UPS_SERVICE_CODE_NEXT_DAY ... and this define/constant should / could be found in a lanuage file or in a database (configuration) entry.

You could try to debug with inserting :

<pre>
echo "DEBUG: " . $method;
</pre>

 

Share this post


Link to post
Share on other sites
3 minutes ago, azpro said:

@greasemonkey  I don't know this contribution - but just reading the code ..

The function tries to built $method to something like UPS_SERVICE_CODE_NEXT_DAY ... and this define/constant should / could be found in a lanuage file or in a database (configuration) entry.

You could try to debug with inserting :


<pre>
echo "DEBUG: " . $method;
</pre>

 

I'll give that a try...

 

Share this post


Link to post
Share on other sites
2 minutes ago, TomB01 said:

but the error says it can't find the constant(s).

No - it says :

19 minutes ago, TomB01 said:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none-- in /home1/tomb/public_html/pho-bzr/catalog/includes/modules/shipping/upsxml.php on line 1128

So the $method is not defined ... Maybe if you change to

 

13 minutes ago, greasemonkey said:

if ($_method == '--none--') {

if ($_method === '--none--') { 

so try 3x ===

But just guessing .....

 

Share this post


Link to post
Share on other sites
3 minutes ago, azpro said:

No - it says :

So the $method is not defined ... Maybe if you change to

 

if ($_method === '--none--') { 

so try 3x ===

But just guessing .....

 

Tried adding a 3rd "=" in that line, no go.

Share this post


Link to post
Share on other sites

Do these comments help explain the code better?


 

Quote

// Next two functions are used only in the admin for disallowed shipping options.
// The (short) code numbers are stored in the database
// to stay below 255 characters. The defines themselves are found in the upsxml
// language file prefixed with UPS_SERVICE_CODE_ to avoid collisions with other shipping modules.
// They can be moved to admin/includes/function/general.php if you like but don't forget
// to remove them from this file in future updates or you will get an error in the admin
// about re-declaring functions

 

Share this post


Link to post
Share on other sites

@greasemonkey

Scott - sure in general defines and/or constants can come from file or database ... you could search for UPS_SERVICE_CODE_  ...

But you must understand the function tries to kind of construct the different defines by adding the $method value to UPS_SERVICE_CODE_ - so it will give EG UPS_SERVICE_CODE_NEXT_DAY or UPS_SERVICE_CODE_OVERNIGHT or UPS_SERVICE_CODE_WHATEVER_NAME_THE METHOD HAS ....

And again - I don't know this contribution - but probably there are syntax/code errors related to PHP7.

 

Share this post


Link to post
Share on other sites
3 hours ago, TomB01 said:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none-- in /home1/xxxx/public_html/xxxx/catalog/includes/modules/shipping/upsxml.php on line 1128

This is saying that --none-- was the selected method.  You have to change it to select an actual method.  None is not going to work. 

The code doesn't "look" for the constant definitions.  They are pushed at it.  Putting the definition in either the database or the language file defines the constant in the same place.  The only difference is that one is read from the database in includes/application_top.php and the other is read from a file that is included as part of the load of the module. 

For the TABLE_ entries, you are generally replacing

" . TABLE_WHATEVER_IT_SAYS . "

with whatever_it_says.  The quotation marks, the dots, the TABLE_ all go and the table name needs to be lower case. 

The code used to do

define('TABLE_WHATEVER_IT_SAYS', 'whatever_it_says');

But it doesn't anymore. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

Not much progress - however it would seem to me it is not looping this

      foreach ($values_array as $key => $_method) {

The values_array looks fine to me... but really not 100% where its getting the $key variable from... Must be here?

  function upsxml_cfg_select_multioption_indexed($select_array, $key_value, $key = '') {
    $key_values = explode( ", ", $key_value);
		
    $string = '';
    for ($i=0; $i<sizeof($select_array); $i++) {
      $name = ((tep_not_null($key)) ? 'configuration[' . $key . '][]' : 'configuration_value');
      $string .= '<br /><input type="checkbox" name="' . $name . '" value="' . $select_array[$i] . '"';
      if ( in_array($select_array[$i], $key_values) ) $string .= ' CHECKED';
      $string .= '> ' . constant('UPS_SERVICE_CODE_' . trim($select_array[$i]));
    } 
    $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
    return $string;
  }

I'm confused....

Share this post


Link to post
Share on other sites

you can check / debug with <pre> as i said ... debug from top to bottom to see if the $ value is set / something you expect

Share this post


Link to post
Share on other sites

I think that we are talking about version 1.73 of this App.

1 hour ago, greasemonkey said:

The values_array looks fine to me... but really not 100% where its getting the $key variable from... Must be here?

No, it gets it from the explode immediately prior.  The $key will just be numbers from 0 to whatever.  Only the values come from the selection (indirectly through the form submission). 

Try changing

  function get_multioption_upsxml($values) {
    if (tep_not_null($values)) {
      $values_array = explode(',', $values);
      foreach ($values_array as $key => $_method) {
        if ($_method == '--none--') {
          $method = $_method;
        } else {
          $method = constant('UPS_SERVICE_CODE_' . trim($_method));
        }
        $readable_values_array[] = $method;
      }
      $readable_values = implode(', ', $readable_values_array);
      return $readable_values;
    } else {
      return '';
    }
  }

to

  function get_multioption_upsxml($values) {
    if (!tep_not_null($values)) {
      return '';
    }

    foreach (explode(',', $values) as $_method) {
      $_method = trim($_method);
      $constant_name = 'UPS_SERVICE_CODE_' . $_method;
      if ($_method != '--none--' && defined($constant_name)) {
        $_method = constant($constant_name);
      }
      $readable_values_array[] = $_method;
    }

    return implode(', ', $readable_values_array);
  }

That should get you past the error message at least. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

@ecartz I think I've found it.

@TomB01 please test this....

        tep_db_query("insert into configuration ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Disallowed Shipping Methods', 'MODULE_SHIPPING_UPSXML_TYPES', '', 'Select the UPS services <span style=\"color: red; font-weight: bold\">NOT</span> to be offered. Warning: Disallow too many and you may not get any rates returned at all.', '6', '20', 'get_multioption_upsxml',  'upsxml_cfg_select_multioption_indexed(array(\'01\', \'02\', \'03\', \'07\', \'08\', \'11\', \'12\', \'13\', \'14\', \'54\', \'59\', \'65\', \'70\', \'82\', \'83\', \'85\', \'86\', \'96\'), ',  now())");

To

        tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Disallowed Shipping Methods', 'MODULE_SHIPPING_UPSXML_TYPES', '', 'Select the UPS services <span style=\"color: red; font-weight: bold\">NOT</span> to be offered. Warning: Disallow too many and you may not get any rates returned at all.', '6', '20', 'get_multioption_upsxml',  'upsxml_cfg_select_multioption_indexed(array(\'01\', \'02\', \'03\', \'07\', \'08\', \'11\', \'12\', \'13\', \'14\', \'54\', \'59\', \'65\', \'70\', \'82\', \'83\', \'85\', \'86\', \'96\'), ',  now())");

Notice the space after the second opening (

Working on some other issues

 

Share this post


Link to post
Share on other sites

If all that happened is that you removed that one space, that shouldn't change anything. 

configuration ( configuration_title,

and

configuration (configuration_title,

should do the same thing. And note that that code only changes anything at the time of install.  Once installed, it should do nothing whatsoever. 

In my previous post, the replacement code should have been

  function get_multioption_upsxml($values) {
    if (!tep_not_null($values)) {
      return '';
    }

    $readable_values = [];
    foreach (explode(',', $values) as $_method) {
      $_method = trim($_method);
      $constant_name = 'UPS_SERVICE_CODE_' . $_method;
      if ($_method != '--none--' && defined($constant_name)) {
        $_method = constant($constant_name);
      }
      $readable_values[] = $_method;
    }

    return implode(', ', $readable_values);
  }

Changed variable name and initialized. 


Always back up before making changes.

Share this post


Link to post
Share on other sites

My Dreamweaver is showing a syntax error with "$readable_values = [ ];"

Share this post


Link to post
Share on other sites

This isn't the thread for it, but I have FedEx Web Services (call it 9.6, modded for Phoenix) working.  It was a bunch of those TABLE_ and DIR_WS and DIR_FS things, which you guys explained to us in this thread. 😉

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
Sign in to follow this  

×