Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

ohiowebpro

UPSXML Saving Disallowed Shipping Methods

Recommended Posts

Working with the UPSXML addon in OSC v2.3. Everything is working fine except the option in the admin to disallow shipping methods using the check boxes. When I check any of the boxes and save, they do not stay checked. I confirmed the same thing with multiple browsers and thought maybe the database is recording, but the form is not populating correctly, but the options on the checkout page stay. Has anyone seen this before? Could it be a php settings issue?

 

All the other settings save ok, it is just the checkboxes. I am thinking it could be an issue with OSC saving checkboxes in general and not necessarily related to upsxml. Was looking for another settings location with checkboxes and did not find on.

 

Thank you.

Share this post


Link to post
Share on other sites

I bit more info that I figured out about my issue:

The problem seems to lie in how the UPS XML module saves to the database. In the configuration table in the database for the disallowed shipping methods, the only thing that is saved in the value field is "Array" so when I add the methods I do not want as comma separated values, the methods are correctly removed from the checkout options. The problem with this as more than a temp solution is that if you go back to the options in admin and save, it resets back to "Array." Anyone know where there might be an array not being converted to the comma separated values? Hard to believe no one else has had this problem.

Share this post


Link to post
Share on other sites

Many people have had this problem. Most of them look in the support thread for the module to find the answer.

 

Answer: You didn't make the changes to admin/module.php. Go do that.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

OK, so I should have done step three even though I have USPS Methods installed. Thank you!

 

P.S. I searched the forum and I did not see this issue come up.

Share this post


Link to post
Share on other sites

The forum search engine is nearly worthless. I use Google.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Find This code

*****************************************
 
  if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
        reset($HTTP_POST_VARS['configuration']);
        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
 
***********************************************
INSERT THE FOLLOWING CODE AFTER THE ABOVE LINE:
***********************************************
 
        if (is_array($value) ) {
          $value = implode( ", ", $value);
     $value = preg_replace ("/, --none--/", "", $value);
   }

Share this post


Link to post
Share on other sites

Well...I did follow the instructions, but apparently, going back to USPS Rates V7 (had to, in order to retain insured USPS) goofed up the UPS aspect of my modules.php.  I never knew, because I never had to go back and change anything in the UPS shipping module...so previously-saved variables remained in place until I stupidly uninstalled it.  Now, when I try to save the settings, it -appears- to work, except the methods don't stay checked.  When I look at the configuration table in the DB, it just says "Array" where it should say "US_01, US_02" etc.

 

Someone mind looking at this and tell me how to fix it so it saves my methods correctly without breaking the USPS module?

    if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
        $module_name = '';
        // detect custom modules..
        if( array_key_exists('MODULE_SHIPPING_USPS_STATUS', $HTTP_POST_VARS['configuration']) ){    
            $module_name = 'usps';
        }
        reset($HTTP_POST_VARS['configuration']);
        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
    				switch( $module_name ) {
                case 'usps':
                    /*
                     * TODO: review
                    * USPS Methods
                    */
                    if( is_array( $value ) ){
                        $value = implode( ", ", $value);
                        $value = ereg_replace (", --none--", "", $value);
                    }
                    /*
                     * /end
                    */
                    break;
            }
		  tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
        }
        tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
        break;
      case 'install':
      case 'remove':

Share this post


Link to post
Share on other sites

I don't know why you have that switch() statement in there. Remove that, but keep the contents of the case 'usps', and all modules should work.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Thanks Jim.  I finally got it working last night by changing it as follows:

    switch ($action) {
      case 'save':
        $module_name = '';
        // detect custom modules..
        if( array_key_exists('MODULE_SHIPPING_USPS_STATUS', $HTTP_POST_VARS['configuration']) ){    
            $module_name = 'usps';
        } else if( array_key_exists('MODULE_SHIPPING_UPSXML_RATES_STATUS', $HTTP_POST_VARS['configuration']) ){    
            $module_name = 'ups';
        }        	
        reset($HTTP_POST_VARS['configuration']);
        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
    switch( $module_name ) {
                case 'usps':

                    if( is_array( $value ) ){
                        $value = implode( ", ", $value);
                        $value = ereg_replace (", --none--", "", $value);
                    }
                    break;
                    
                case 'ups':
                    if( is_array( $value ) ){
                        $value = implode( ", ", $value);
                        $value = ereg_replace (", --none--", "", $value);
                    }
                    break;                    
            }
		  tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
        }
        tep_redirect(tep_href_link(FILENAME_MODULES, 'set=' . $set . '&module=' . $HTTP_GET_VARS['module']));
        break;
      case 'install':
      case 'remove':

Monkey-see, monkey-do, heh.

 

Eagerly anticipating USPS Codes :)

Edited by Supertex

Share this post


Link to post
Share on other sites

That's a lot of unnecessary extra code, although it will still work.

 

The heart of the code is

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

The if() statement triggers only on an array, so any module that does not use arrays will not be affected. Any variable that is an array will be turned into a comma-separated string, which then is safely stored in the database. This is really all that you need.

 

You line $value = ereg_replace (", --none--", "", $value); will never execute, as it is a string function inside an if() that only runs when there is an array. In addition, ereg() is deprecated in PHP 5.3 and will throw a fatal error in later versions. I don't believe that it is actually needed; if it is you will need to replace it with a str_replace() and put that somewhere else in the code.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

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

×