Zen Cart Logo
Forums / Upgrading to 1.5.x / USPS Check Code

USPS Check Code

Views: 1,324

Results 1 to 3 of 3
28 Aug 2011, 12:32
#1
marco_b avatar

marco_b

New Zenner

Join Date:
Dec 2006
Location:
Australia
Posts:
94
Plugin Contributions:
0

USPS Check Code

I had a little look at the beta and checked if my module worked under the new version.

I'm wondering whether the USPS check code built into /admin/modules.php line 30-32 should be moved to the usps::check() method.

It's not really a problem, but since USPS is no longer pre-installed I thought it would make more sense.

I was using modules.php to add some checking related to the modified version. Now I just realised the modules check() method could be used instead to display warning/error html before rendering the table of shipping modules.

03 Sep 2011, 15:08
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: USPS Check Code

I would agree that you should move the check into the USPS module itself ... the less you touch the core the better ...

Something like:

    if (IS_ADMIN_FLAG) {
      if (defined('MODULE_SHIPPING_USPS_STATUS')) {
        //Check USPS Package Dimensions config
        $dimensions=zen_get_configuration_key_value('MODULE_SHIPPING_USPS_DIMENSIONS');
        $dimensions=preg_replace(array('/^[\s,:]*/','/[\s,:]*$/'),'',$dimensions); //Strip leading and trailing whitespace + separators
        $dim_array=preg_split('/[\s,:]+/',$dimensions);
        foreach ($dim_array as $k=>$dparam) {
          if (!preg_match('/^(?P<dimensions>(?:\d{1,3}(?:\.\d{1,5})?x\d{1,3}(?:\.\d{1,5})?x\d{1,3}(?:\.\d{1,5})?)|regular);(?P<weight>\d{1,2}(?:\.\d{1,5})?|\+)(?:;(?P<container>[NRV]))?$/', $dparam)) {
            $dimerr.='<br /><br />The parameters set in Package Dimensions Config #'.($k+1).' are invalid'.($dimerr?'.':(', please enter valid shipping parameters. Current setting will be overridden with default: \'regular;+\''));
          }
        }
        if (preg_match('/^\s*$/',$dimensions)) {
          $shipping_errors.='<br />You must enter valid dimension values. Current setting will be overridden with default: \'regular;+\'';
        }
        $shipping_errors.=$dimerr;
        $this->title .= ($shipping_errors ? '<span class="alert">' . ' Dimension Values Errors ' . '</span>' : '');
        $this->description .= '<span class="alert">' . $shipping_errors . '</span>';
      }
    }

    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
    }

I would also suggest moving the sent/recieved files to the /cache so that it is not using the root of the shop ...

        file_put_contents(DIR_FS_SQL_CACHE . '/uspsRecieve.xml', $body);
        file_put_contents(DIR_FS_SQL_CACHE . '/uspsSend.xml', $output);
04 Sep 2011, 04:41
#3
marco_b avatar

marco_b

New Zenner

Join Date:
Dec 2006
Location:
Australia
Posts:
94
Plugin Contributions:
0

Re: USPS Check Code

Thanks for the suggestions :smile:

I will have it updated in my next version.