Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

USPSMethods


BradWaite

Recommended Posts

Hi all.

 

I added USPSMethods to the Contributions a few days ago.

 

In a nutshell, it allows you to choose which USPS shipping methods will be presented to the customer. For example, if you only want customers to choose between Parcel Post and Priority Mail, you can uncheck Express and First Class in the admin interface. When the customer checks out, he doesn't even see Express or First Class.

 

In order to make this work, I had to add a new function to general.php that allows a config option to have multiple values - tep_cfg_select_multioption. Previously, the only choice was to use radio buttons ( with tep_cfg_select_option), which are exclusive - only one option can be chosen at a time. This may have been done elsewhere, but I haven't come across it. In any case, it should be useful to other developers.

 

Brad Waite

W Cubed

Link to comment
Share on other sites

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

Brilliant! This is like magic -- I went to sleep last night thinking about making a mod something like this (some overseas user chose a USPS method I had never heard of), and behold, when I woke up this morning Brad's post about the contribution was waiting for me.

 

Just two comments:

 

The final step of this mod, editing catalog/includes/modules/shipping/usps.php, was written before one more line was added in version 1.36 to fix an important bug. So now the step is to replace

if ($order->delivery['country']['id'] == STORE_COUNTRY) {

       $request  = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">';

       $services_count = 0;         

       if (isset($this->service)) {

         $this->types = array($this->service => $this->types[$this->service]);

       }         

       reset($this->types);

       while (list($key, $value) = each($this->types)) {

         $request .= '<Package ID="' . $services_count . '">' .

with

if ($order->delivery['country']['id'] == STORE_COUNTRY) {

       $request  = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">';

       $services_count = 0;

       if (isset($this->service)) {

         $this->types = array($this->service => $this->types[$this->service]);

       }

       reset($this->types);

 $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);

       while (list($key, $value) = each($this->types)) {

         if ( !in_array($key, $allowed_types) ) continue;

   $request .= '<Package ID="' . $services_count . '">' .

 

And the other thing is the list of allowable methods may need some tweeking to filter some of the international services. I have not yet completed this analysis, but for instance, there is something called Global Express Guaranteed Document Service (and a Non-Document variation) that is not appropriate for what my store sells. Presumably, the platform Brad has provided will allow for dealing with these.

Link to comment
Share on other sites

The final step of this mod, editing catalog/includes/modules/shipping/usps.php, was written before one more line was added in version 1.36 to fix an important bug.  So now the step is to replace
        if (isset($this->service)) {

         $this->types = array($this->service => $this->types[$this->service]);

       }

 

My bad. I'd already fixed that myself (before the addition to CVS) by adding

 

        if ($method) $this->types = array($method => $type->types[$method]);

 

into the quote() function in usps.php. It was simpler than the CVS solution, but USPSMethods should have been based on the CVS code, not mine.

 

And the other thing is the list of allowable methods may need some tweeking to filter some of the international services.  I have not yet completed this analysis, but for instance, there is something called Global Express Guaranteed Document Service (and a Non-Document variation) that is not appropriate for what my store sells.  Presumably, the platform Brad has provided will allow for dealing with these.

 

Actually, I didn't even consider international options so the methods won't be checked if the delivery address is not in the same country as the store (US). Back to coding...

 

Thanks for the heads-up.

 

Brad

Link to comment
Share on other sites

The contribution fails to revive properly after being disabled, unless you add the following to the install function after the other lines that look similar, at about line 94:

tep_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'Express, Priority, First Class, Parcel', 'Select the USPS services to be offered.', '6', '14', 'tep_cfg_select_multioption(array('Express', 'Priority', 'First Class', 'Parcel'), ',  now())");

 

Then, the module will behave better and show the new service options without then necessity of manually inserting into the configuration table.

Link to comment
Share on other sites

The contribution fails to revive properly after being disabled, unless you add the following to the install function after the other lines that look similar

 

Drat! I was going to mention that. I guess I'll have to release a new version. Again, good catch.

 

Brad

Link to comment
Share on other sites

jeff i dont see anu codes there.

 

I actually did try using cute ftp. However, looks like i messed up I am getting this , message whenever I click anything on my website

 

"Fatal error: Cannot redeclare tep_set_banner_status() (previously declared in /home/kashmira/public_html/catalog/includes/functions/general.php:664) in /home/kashmira/public_html/catalog/includes/functions/banner.php on line 15

i uploaded the backup files but i am still getting the same message

 

Someone please help

Link to comment
Share on other sites

I am trying to install USPS methods...

can someone guide where the following code needs to be installed

Execute the following SQL command on your catalog database:

 

 

INSERT INTO configuration

( configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added )

VALUES

( 'Shipping Methods', 'MODULE_SHIPPING_USPS_TYPES', 'Express, Priority, First Class, Parcel', 'Select the USPS services to be offered.', '6', '14', 'tep_cfg_select_multioption(array('Express', 'Priority', 'First Class', 'Parcel'), ', now() )

 

 

What configuaration are we talking about!

 

thanks for your help

Link to comment
Share on other sites

The sql command should be entered while running phpMyAdmin, a tool that shows you what is in the database and allows you to modify not only the contents but the structure of the database. The table in the database that is changed by this particular command is named 'configuration' and holds execution parameters for osC.

 

Some server control panels have phpMyAdmin built in (under MySQL), or you can get the open source script here:

http://www.phpmyadmin.net/

 

Learning how to use this is essential to your continuing ability to extend and maintain osC, as you can see the contributions often require it.

Link to comment
Share on other sites

FYI, if you've got USPSMethods v1.1, there's a somewhat easier way to install it. Insert the rest of the code as described in the instructions (other than Step 1), then simply turn the USPS module off and back on again. The install() function automatically executes the required SQL commands.

 

HTH,

 

Brad

Link to comment
Share on other sites

well I tried to do that

but i got this errror in shipping module in the cobtrol panel

 

Parse error: parse error, unexpected '.' in /home/public_html/catalog/includes/modules/shipping/usps.php on line 141

 

Also, the code in my USPS seems to be different than what u have displayed in your contribution

 

if ($order->delivery['country']['id'] == STORE_COUNTRY) {

$request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="' . MODULE_SHIPPING_USPS_PASSWORD . '">';

$services_count = 0;

 

if (isset($this->service)) {

$this->types = array($this->service => $this->types[$this->service]);

}

 

reset($this->types);

while (list($key, $value) = each($this->types)) {

$request .= '<Package ID="' . $services_count . '">' .

 

Any suggestions

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...