Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Multiple ship methods in one module


xtronics

Recommended Posts

I'm writting a module that looks up shipping rates in a Sal table and returns quotes for different shipping methods. I have the checkout_shipping.HP page working properly, but checkout_confirmation.HP shows the wrong shipping type and amount.

 

I've inserted test code and confirmed that the $this->quotes array look correct -(could it be a type casting problem?)

 

I am having problems figuring out what tells it that there is more than one shipping method in a single module.

------------------------------------------------------------------------

The first panacea for a mismanaged nation is inflation

of the currency; the second is war. Both bring a
temporary prosperity; both bring permanent ruin.
Ernest Hemingway
------------------------------------------------------------------------

Link to comment
Share on other sites

Not a casting problem - after running more test code with gettype()

 

Always picks nextday air no matter which button is pressed

 

Here is the code:

 

<?php
/*
 $Id: tship.php,v 1.54 2003/04/08 23:23:42 dgw_ Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class tship {
   var $code, $title, $descrption, $icon, $enabled, $types;

// class constructor
   function tship() {
     global $order;

     $this->code = 'tship';
     $this->title = MODULE_SHIPPING_TSHIP_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_TSHIP_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_TSHIP_SORT_ORDER;
     $this->icon = DIR_WS_ICONS . 'shipping_tship.gif';
     $this->tax_class = MODULE_SHIPPING_TSHIP_TAX_CLASS;
     $this->enabled = ((MODULE_SHIPPING_TSHIP_STATUS == 'True') ? true : false);

     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TSHIP_ZONE > 0) ) {
       $check_flag = false;
       $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TSHIP_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
       while ($check = tep_db_fetch_array($check_query)) {
         if ($check['zone_id'] < 1) {
           $check_flag = true;
           break;
         } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = false;
       }
     }

     $this->types = array('1DA' => 'Next Day Air',
                   '2DA' => '2nd Day Air',
                   '3DS' => '3 Day',
                   'GND' => 'Standard Ground',
                   'EMS' => 'International Insured Express Mail',
                   'HHH' => 'empty');
   }

// class methods
function quote($method = '') {
   global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes;
  
  $error_code = 0;
//   $error_code = 8;
//    $flag = '<br>';
//    foreach  ($order as $key -> $text){
//    $flag .= '#'.$key .'#  #'.$text . '#<br>';
//    }
   if ( (tep_not_null($method)) && (isset($this->types[$method])) ) {
       $prod = $method;
     } else {
       $prod = 'GND';
     }
     

  
   $country_name = tep_get_countries(SHIPPING_ORIGIN_COUNTRY, true);
   
     
   
   $zone_weight=round(0.2+$shipping_weight);
// set up zone rate adders
   $zone_add = array('1DA' => 100,
                   '2DA' => 200,
                   '3DS' => 300,
                   'GND' => 0,
                   'EMS' => "");

   $iso = $order->delivery['country']['iso_code_3'];
   $ship_rate_query = tep_db_query("SELECT * FROM ship_rates where weight = '" .$zone_weight ."'");
   $ship_rate_array = tep_db_fetch_array($ship_rate_query);
   if ($iso=='USA'||$iso=='VIR'||$iso=='ASM'||$iso=='MHL'||$iso=='PRI'||$iso=='UMI'||$iso=='GUM'){
       //USA zip code
       $zip = $order->delivery['postcode'];
         
       //  Valid postal zip code? 
       $len = strlen($zip);
       switch ($len){
           case 5:
               if (ereg ("[0-9][0-9][0-9][0-9][0-9]",$zip) !=1) $error_code = 1;
               break;
           case 10:
               if (ereg ("[0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]",$zip) !=1) $error_code = 1;
               break;
           default:    
               $error_code = 1;
       }
       
       
   
       $zip_3 = substr($order->delivery['postcode'],0,3);
       
       $us_zone_query = tep_db_query("SELECT zone FROM zip2zone where '" . $zip_3 . "' between start and stop ");
       $us_zone_array = tep_db_fetch_array($us_zone_query);
       $us_zone=$us_zone_array[zone];
       if ($us_zone == 0) $error_code =1;
       if (1 <= $us_zone && $us_zone <3) $us_zone =3;// there are no zones 1 and 2
       // look up cost
          
       // Create the three layer quotes array                
       $this->quotes = array('id' => $this->code,
                             'module' => $this->title .' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');
   
                                                                                   
       $n=0;
       $qsize = sizeof($types);
       
       foreach ($this->types as $key => $text) {
           if ($key == 'EMS') break;
           
           $current_zone =  $us_zone + $zone_add[$key]; // add 100 ,200,300 etc to zones for one day, 2nd day ,3 day one day etc
           
           
           $ship_rate=$ship_rate_array['Z'.$current_zone];
           
           
           $methods[] = array('id' => $key,
                           'title' => $text,
                           'cost'  => ($ship_rate  + MODULE_SHIPPING_TSHIP_HANDLING) * $shipping_num_boxes);
                           $n=$n+1;
           }
          
       $this->quotes['methods'] = $methods;
      
  }else{
 // International shipping  
       $int_zone_query = tep_db_query("SELECT * FROM ems_zones where countries_iso_code_3 = '" . $iso . "'");
       $int_zone_array = tep_db_fetch_array($int_zone_query);
       $int_zone=$int_zone_array[ems_zone];
       if ($int_zone == 0) $error_code =3;
       if ($int_zone_array[weight_limit_lb]< $shipping_weight) $error_code = 4;
       // look up cost and Create the three layer quotes array  
       $ship_rate=$ship_rate_array['EMS'.$int_zone];
       if ($ship_rate < 4) $error_code = 5;
                                                                                   
       $this->quotes = array('id' => $this->code,
                             'module' =>title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)',
                            'methods' => array(array('id' => $this->code,
                                                    'title' => $this->types{EMS},
                                                    'cost' => $ship_rate + 2)));       
   }
 //  $error_code = 8;
   //$flag ='<br>';
     //  foreach ($this->quotes{0} as $key => $text) { 
      // $typ =gettype($text);
     //$flag .= '  #'.$key . '#  #' .$text . '# #' . $typ .'#<br>';
       //}

   
       if ($this->tax_class > 0) {
           $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
           }
 
   switch ($error_code) {
       case 0:
       break;
       case 1:
       $this->quotes = array('module' => $this->title,'error' => 'The zip code you entered is not a USA zipcode.<br>Please call +1(785) 841-3089 error_code = ' .$error_code. ' <a href= account.php> click here to fix it</a>');
       break; 
       case 3:
       $this->quotes = array('module' => $this->title,'error' => 'We don\'t have your country in our shipping index.<br>Please call +1(785) 841-3089 error_code = ' .$error_code . ' flag = '.$flag);
       case 4:
       $this->quotes = array('module' => $this->title,'error' => 'Looks like there is a problem with your countries shipping weight limitations .<br>Please call +1(785) 841-3089 error_code = ' .$error_code . ' flag = '.$flag);
          
       default:
       $this->quotes = array('module' => $this->title,
                           'error' => 'An error occured with the shipping calculations.<br> Please call +1(785) 841-3089 error_code = ' .$error_code. ' flag = '.$flag);
       break;
       }    

     if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

     return $this->quotes;
 }
   

function check() {



   if (!isset($this->_check)) {
   $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TSHIP_STATUS'");
   $this->_check = tep_db_num_rows($check_query);
   }
   return $this->_check;
   }
     

   function install() {
     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 ('Enable TSHIP Shipping', 'MODULE_SHIPPING_TSHIP_STATUS', 'True', 'Do you want to offer TSHIP shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");//enable
   
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TSHIP_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_TSHIP_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
    tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_TSHIP_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_TSHIP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
   }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

   function keys() {
     return array('MODULE_SHIPPING_TSHIP_STATUS',  'MODULE_SHIPPING_TSHIP_HANDLING', 'MODULE_SHIPPING_TSHIP_TAX_CLASS',  'MODULE_SHIPPING_TSHIP_SORT_ORDER',
     'MODULE_SHIPPING_TSHIP_ZONE');
   }


  
 }
?>[/QUOTE]

------------------------------------------------------------------------

The first panacea for a mismanaged nation is inflation

of the currency; the second is war. Both bring a
temporary prosperity; both bring permanent ruin.
Ernest Hemingway
------------------------------------------------------------------------

Link to comment
Share on other sites

The problem was that quotes is called twice - the second time with the choisen method where it should return an array with the selected shipping quote in it.

------------------------------------------------------------------------

The first panacea for a mismanaged nation is inflation

of the currency; the second is war. Both bring a
temporary prosperity; both bring permanent ruin.
Ernest Hemingway
------------------------------------------------------------------------

Link to comment
Share on other sites

  • 1 year later...
The problem was that quotes is called twice - the second time with the choisen method where it should return an array with the selected shipping quote in it.

 

What do you mean by the above? What should be changed in the coding?

 

I have everything installed, created the tables, uploaded the data, etc...Works great, installed fine, no problems...Only issue is the above on not properly passing the "selected" shipping option but rather the Next Day Air.

 

Any thoughts on this?

Link to comment
Share on other sites

What do you mean by the above? What should be changed in the coding?

 

I have everything installed, created the tables, uploaded the data, etc...Works great, installed fine, no problems...Only issue is the above on not properly passing the "selected" shipping option but rather the Next Day Air.

 

Any thoughts on this?

 

This is from long ago -- while I was writing the code.

 

The final version at http://www.oscommerce.com/community/contri...ll/search,tship just works.

------------------------------------------------------------------------

The first panacea for a mismanaged nation is inflation

of the currency; the second is war. Both bring a
temporary prosperity; both bring permanent ruin.
Ernest Hemingway
------------------------------------------------------------------------

Link to comment
Share on other sites

This is from long ago -- while I was writing the code.

 

The final version at http://www.oscommerce.com/community/contri...ll/search,tship just works.

 

Hello xtronics:

 

Thanks for replying. I think I know what's going on...I did download the newest version and during the install I noticed in the tship.php within the modules/shipping the code is incomplete. At the very bottom it stops with the unrecognized character symbol right after case 10. I've inserted the last few lines below:

 

LAST FEW LINES OF CODE:

switch ($error_code) {

case 0:

break;

case 1:

$this->quotes = array('module' => $this->title,'error' => ' <font color="#ff0000"><b> Address Error! </b></font><Br>In this USA address, the 5 digit zip code you entered, <b>'. $order->delivery['postcode'] .'</b> code has some charactor that is not a digit. You must enter a valid USA zipcode. <br> <a href= address_book.php> Click here to fix it!</a> <br>Please call +1(785) 841-3089 and mention the error code. error_code = ' .$error_code );

break;

case 10:

$this->quotes = array('module' => $this->title,'error' => '<font color="#ff0000"><b> Address Error! </b></font><Br>In this USA address, the zip code you entered, <b>'. $order->delivery['postcode'] .'</b>is not the correct length for a USA zip

 

END LAST FEW LINES OF CODE: (the characters did not show up and I cannot paste into here, but you can download and see for yourself)

 

Take a look at the files in the contribution you posted. So, what I did now was just copy and paste the last remaining lines of code from the entry in the forums. The 1st time I installed I just copied the entire code from the post in the forum and used that, silly me. Now I'm trying to figure out how to structure the da_surcharge that it's attempting to call data from as I did not see that in your CSV listing.

 

Anyways, let me know. Will keep trying to get this resolved.

 

Thank you so much for the help on this! I really appreciate it! Once we get this squared away I'll upload a new version for everyone to install.

 

Let me know on the da_surcharge table as wlel as the last remaining lines of code. I'll create a full sql file for everyone in the meantime.

 

Anyways, let me know.

 

Thanks!

Shaun

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.
Note: Your post will require moderator approval before it will be visible.

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...