Jump to content
Sign in to follow this  
TomB01

UPS XML 1.7 for Phoenix

Recommended Posts

Here's a partial screen cap:

I only need a couple of UPS options in-between USPS and FedEx and I may be able to rebuild my store with Phoenix 1.0.4.0. 😊

USPS&FedEx.jpg

Share this post


Link to post
Share on other sites
1 hour ago, TomB01 said:

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

This is probably a sign that it is either out of date or building against the wrong version of PHP.  I haven't used Dreamweaver in ages, so I don't know which.  In general, Phoenix runs on PHP 7.  The short array syntax dates back to PHP 5.4. 

I can't read it, but Google claims that this shows how to change the PHP version under site setup:  https://helpx.adobe.com/dreamweaver/using/setting-coding-environment.html


Always back up before making changes.

Share this post


Link to post
Share on other sites

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none--

Is telling you that a constant is missing.  What that constant is used for...I don't know as using these ancient addons is not the way forward (in my opinion).    It's a bit like buying a new car then putting on the tyres from your old beat-up car 😕 

Try add this to the LANGUAGE File of the addon;

define('UPS_SERVICE_CODE_--none--', 'None');


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites
14 hours ago, ecartz said:

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. 

Yes, I believe I', chasing my tail here.

I'm gonna move my part of this convo over to the Canada Post thread - as I believe (although the code is almost identical) my issue is separate/different.

 

 

Share this post


Link to post
Share on other sites
2 hours ago, burt said:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none--

Is telling you that a constant is missing.  What that constant is used for...I don't know as using these ancient addons is not the way forward (in my opinion).    It's a bit like buying a new car then putting on the tyres from your old beat-up car 😕 

Try add this to the LANGUAGE File of the addon;

define('UPS_SERVICE_CODE_--none--', 'None');

9 hours ago, ecartz said:

This is probably a sign that it is either out of date or building against the wrong version of PHP.  I haven't used Dreamweaver in ages, so I don't know which.  In general, Phoenix runs on PHP 7.  The short array syntax dates back to PHP 5.4. 

I can't read it, but Google claims that this shows how to change the PHP version under site setup:  https://helpx.adobe.com/dreamweaver/using/setting-coding-environment.html

But of course - my version of Dreamweaver has no option for changing the PHP environment.

I tried it, though, and no go.  UPS options still do not appear in my checkout.  My logging e-mail says the following:

Quote

UPSXML Rates Error: Error 110108: Missing/Illegal Shipper/CountryCode experienced by customer with id 1 Sandman Tibet on 2019-11-28 08:40:12

That's the same error I was getting all yesterday.

Edited by TomB01

Share this post


Link to post
Share on other sites

Back to the original code:

Quote

  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 '';
    }
  }

and same error logging:

Quote

UPSXML Rates Error: Error 110108: Missing/Illegal Shipper/CountryCode experienced by customer with id 1 Sandman Tibet on 2019-11-28 08:46:57

That's progress, though!  Yesterday, it was blowing up the shopping cart completely!

 

Share this post


Link to post
Share on other sites
2 hours ago, burt said:

Warning: constant(): Couldn't find constant UPS_SERVICE_CODE_--none--

Is telling you that a constant is missing.  What that constant is used for...I don't know as using these ancient addons is not the way forward (in my opinion).    It's a bit like buying a new car then putting on the tyres from your old beat-up car 😕 

Try add this to the LANGUAGE File of the addon;

define('UPS_SERVICE_CODE_--none--', 'None'); 

Thanks!  If there were some new tyres to try, I'd do it.  Shipping is my threshold gate for updating.  I've tried numerous times the last few years, but all were failures (even tried the other guy's car once - it failed, too).  I do not know why new shipping tyres are not being created, but it seems amazing to me.  There are three primaries for shipping in the US and depending on what and where you sell to, the pricing can vary tremendously.  The stuff I sell varies from $1 to $2000 and probably 30-40% of my sales are international.  I have to have the options of USPS, UPS, and FedEx available.  Maybe shipping options are not an issue outside of the US?  I don't know.

Please understand - Phoenix is fantastic!  What you have done is nothing short of monumental!  It is greatly appreciated and as stated, this is further than I've ever gotten before.

Anyway, I tried this and same error logging replied:

Quote

UPSXML Rates Error: Error 110108: Missing/Illegal Shipper/CountryCode experienced by customer with id 1 Sandman Tibet on 2019-11-28 08:54:09

Share this post


Link to post
Share on other sites

Tom - I understand it can be frustrating ... I am a shopwoner - as you are - so I am not  a professional coder. But I have learned to read code - debug and write code ... The thing is this contrib is ancient and by the looks of it poorly written. So what you are facing is lots of repairs - some due to PHP& upgrades - some due to Old-school coding.

Sometimes you have to face reality - Your old car is broken. I would team-up with Scott (and maybe others) and ask a quote in the commercial forum for a newly written piece of software. Maybe the old contribution can easily be upgraded - I don't know.

Share this post


Link to post
Share on other sites
1 minute ago, azpro said:

Tom - I understand it can be frustrating ... I am a shopwoner - as you are - so I am not  a professional coder. But I have learned to read code - debug and write code ... The thing is this contrib is ancient and by the looks of it poorly written. So what you are facing is lots of repairs - some due to PHP& upgrades - some due to Old-school coding.

Sometimes you have to face reality - Your old car is broken. I would team-up with Scott (and maybe others) and ask a quote in the commercial forum for a newly written piece of software. Maybe the old contribution can easily be upgraded - I don't know.

Thanks for the advice.  I never liked UPS that much anyway. 😉

USPS is my absolute primary shipping and that now works.  If I have FedEx, too - maybe I can make a go of it.  I will keep working and try to follow up as you suggest in the meantime.

Share this post


Link to post
Share on other sites
1 hour ago, TomB01 said:
Quote

UPSXML Rates Error: Error 110108: Missing/Illegal Shipper/CountryCode experienced by customer with id 1 Sandman Tibet on 2019-11-28 08:40:12

That's the same error I was getting all yesterday.

Try running

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());

in phpMyAdmin.  Then go into admin > Configuration and edit the values to be correct.  Or just change the initial values in that SQL from '223' and 'NONE' to the correct values.  223 is the value for the US.  'NONE' isn't going to be correct anywhere. 

Sorry, I was still looking at the --none-- error which has an entirely different cause. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
41 minutes ago, ecartz said:

Try running


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());

in phpMyAdmin.  Then go into admin > Configuration and edit the values to be correct.  Or just change the initial values in that SQL from '223' and 'NONE' to the correct values.  223 is the value for the US.  'NONE' isn't going to be correct anywhere. 

Sorry, I was still looking at the --none-- error which has an entirely different cause. 

Well, I have it working!

It wasn't your post specifics, but the idea you hit upon in the SQL inserts above.  I kept looking at the error codes e-mails that were stating "Missing/Illegal Shipper/Country Code" trying to figure out which was the issue - Shipper or Country Code.  I decided to create log files on the server.  Then I compared the Phoenix log file to my working 2.3.4 log file.  The UPS reply on the working log file was lengthy.  Then I went to WinMerge to compare the two log files exactly.  The 2.3.4 log file had CountryCode "US", the Phoenix log file had CountryCode "United States."  Long story short, my Chrome browser was auto-filling the Admin settings for UPS XML shipping and I accepted "United States" instead of following the instructions that stated Enter the country's two-character code.  What a dummy I am!

Checked it again, then the error code changed to "Invalid Destination."  I guessed the UPS Server was very smart, so I input my own real address.  It worked.

Bottom line, the insert into the languages file suggested by Burt fixed the Admin errors about the "UPS_SERVICE_CODE_."  Elsewhere, I had to input into the upsxml.php file, complete path strings instead of the DIR_ stuff, and remove the TABLE_ prefixes and use lowercase database table names.  Then I ensured that correct data was entered into the Admin settings, and used a REAL checkout address.

Success!

 

Attached are the modified-for-Phoenix includes/modules/shipping/upsxml.php and includes/languages/english/modules/shipping/upsxml.php files. (Enter your own store's path string where needed.)

 

upsxml.php

upsxml.php

Edited by TomB01
removed personal path strings from files

Share this post


Link to post
Share on other sites

Sorry - my store's path string was in the files.  I'll clean that up and re-post them.  Not sure about the time limit on editing, but was able to edit the original post with clean files above.  Sorry for the cleanup!

Edited by TomB01

Share this post


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

Attached are the modified-for-Phoenix

I'm glad for you Tom!!

It would be great if you upload them to the market as an addon so all users can find them easily.

@burt would you consider including these modules in the next version of OSC?

Best regards

Valqui


Please do not falsify my words. Are you interested in knowing who does it? Send me a PM.

The Phoenix Club won't allow me to join - why not?

Setting up a new Frozen site with so many nice addons available on the market. 

:heart: Community Oscommerce fan :heart:

 

Share this post


Link to post
Share on other sites
57 minutes ago, valquiria23 said:

I'm glad for you Tom!!

It would be great if you upload them to the market as an addon so all users can find them easily.

@burt would you consider including these modules in the next version of OSC?

Best regards

Valqui

Thanks!  I will work on new updates to the addons (both UPS and FedEx).

Share this post


Link to post
Share on other sites

@TomB01 hey Tom, I mentioned I was trying to update the Canada Post module, which is based on this UPS module....

Anyway, I figured out my issue (real amateurish...😜) and I'm guessing you may be having the same issue.

Did you make the edit from the original instructions to admin/modules.php???? Adding

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

It would go after the below (line 35 in a fresh copy):

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

Give it a try and report back... Like I said, this was my issue....

I'll need some help so we don't require this edit to a core file???? Anyone?

Edited by greasemonkey

Share this post


Link to post
Share on other sites
1 hour ago, greasemonkey said:

@TomB01 hey Tom, I mentioned I was trying to update the Canada Post module, which is based on this UPS module....

Anyway, I figured out my issue (real amateurish...😜) and I'm guessing you may be having the same issue.

Did you make the edit from the original instructions to admin/modules.php???? Adding


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

It would go after the below (line 35 in a fresh copy):


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

Give it a try and report back... Like I said, this was my issue....

I'll need some help so we don't require this edit to a core file???? Anyone?

Kymation had introduced that fix for the USPS Rates add-on, so it was already in my modules.php.  At least some if it anyway:

Quote

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

As you say, after the #35 "POST" line.  However, his suggestion did not have the "value = preg_replace ..." line.  I seemed to have passed all the USPS, UPS, and FedEx gauntlets without it, though.

Share this post


Link to post
Share on other sites
7 hours ago, greasemonkey said:

I'll need some help so we don't require this edit to a core file???? Anyone?

Well, right now we don't have the necessary hook.  So let's add it.  See here.  Find

   $action = (isset($_GET['action']) ? $_GET['action'] : '');

Add before it add

   $OSCOM_Hooks->call('modules', 'preAction');

Now, in includes/hooks/admin/modules/ create a file called canadapost.php or upsxml.php or whatever.php.  I'm going to proceed as if named whatever.  In that file, create a class named hook_admin_modules_whatever, e.g.

  class hook_admin_modules_whatever {

    function listen_preAction() {
      if (isset($_GET['module']) && 'whatever.php' == $_GET['module'] && isset($_GET['action']) && 'save' == $_GET['action'] && isset($_POST['configuration'])) {
        foreach ($_POST['configuration'] as $key => &$value) {
          if (isset($value) && is_array($value)) {
            $value = implode(', ', $value);
            if (false !== strpos($value, '--none--')) {
              $value = str_replace(', --none--', '', $value);
              $value = str_replace('--none--, ', '', $value);
              $value = str_replace('--none--', '', $value);
            }
          }
        }
        unset($value);
      }
    }

  }

My suggestion would be that whatever should be the name of the module.  Note that in the

'whatever.php' == $_GET['module']

whatever must be the name of the module. 

After you test that this works, I'll ask Gary to make the core change so that in future versions, you don't have to change admin/modules.php

Edited by ecartz

Always back up before making changes.

Share this post


Link to post
Share on other sites

@ecartz Although my skills are basic (if not already obvious...lol) , I was under the impression we now had site wide hooks in Phoenix.

Is admin/modules.php not covered under these hooks?

Share this post


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

@ecartz Although my skills are basic (if not already obvious...lol) , I was under the impression we now had site wide hooks in Phoenix.

Is admin/modules.php not covered under these hooks?

Two things:

1.  A siteWide hook may not be the best solution for running on one particular page. 

2.  The siteWide hook in /admin runs inside template_top.php which runs after the action is processed. 

This solution is consistent with the solution on the catalog (categories) page which adds some number of hooks to that page.  The equivalent development has not been done on the modules page (nor most pages in admin with the exception of the categories page). 


Always back up before making changes.

Share this post


Link to post
Share on other sites
18 minutes ago, ecartz said:

Two things:

1.  A siteWide hook may not be the best solution for running on one particular page. 

2.  The siteWide hook in /admin runs inside template_top.php which runs after the action is processed. 

This solution is consistent with the solution on the catalog (categories) page which adds some number of hooks to that page.  The equivalent development has not been done on the modules page (nor most pages in admin with the exception of the categories page). 

Thank you for the explanation - makes sense. 

Share this post


Link to post
Share on other sites

@ecartz I'm testing your hook today... And not having much success.

The hook seems to registered (only cause I forgot to rename the class from hook_admin_modules_whatever to hook_admin_modules_canadapost it gives a warning).

But will not seem to work.

I've modified admin/modules.php to be:

  $OSCOM_Hooks->call('modules', 'preAction');

  $action = (isset($_GET['action']) ? $_GET['action'] : '');

Do note: I'm working with the Canada Post module .... (if this needs to be moved to that thread... mods please do so). Was anyone able to get this working with UPS?

The core change to admin/modules.php for UPS and Canada Post are identical however - and do work:

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

However the hook (which I have tried exactly as above) and also modified to be identical to the original (below)

<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2014 osCommerce

  Released under the GNU General Public License
*/

  class hook_admin_modules_canadapost {

    function listen_preAction() {
      if (isset($_GET['module']) && 'canadapost.php' == $_GET['module'] && isset($_GET['action']) && 'save' == $_GET['action'] && isset($_POST['configuration'])) {
        foreach ($_POST['configuration'] as $key => &$value) {
          if (isset($value) && is_array($value)) {
             $value = implode( ", ", $value);
		     $value = preg_replace ("/, --none--/", "", $value);
          }
        }
        unset($value);
      }
    }

  }

Does not work.

Both "save" into the DB as "Array"

I can print_r the array... but can't save the array.

Share this post


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

The hook seems to registered (only cause I forgot to rename the class from hook_admin_modules_whatever to hook_admin_modules_canadapost it gives a warning).

What warning does it give? 

I'm willing to pursue a core change, but if we change core, I would prefer

          if (isset($value) && is_array($value)) {
            $value = implode(';', $value);
            if (false !== strpos($value, '--none--')) {
              $value = str_replace(';--none--', '', $value);
              $value = str_replace('--none--;', '', $value);
              $value = str_replace('--none--', '', $value);
            }
          }

which would require a change in the modules as well as it uses the more common semi-colon rather than a comma. 

I would prefer to get the hook working, as I'm not sure the --none-- part belongs in core.  I do think the implode part should be in core, but it wouldn't necessarily help you as you need a comma for the current modules. 

For debugging purposes, you might try a

print_r($_GET);

Or

print_r([$_GET, $_POST, $OSCOM_Hooks]);

 


Always back up before making changes.

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  

×