osCmax v2.5 User Manual
Results 1 to 7 of 7

Adding a shipping module from scratch

This is a discussion on Adding a shipping module from scratch within the osCommerce 2.2 Modification Help forums, part of the osCommerce 2.2 Forums category; Hi there, I am trying to add a new shipping module from scratch. I have located the built in shipping ...

      
  1. #1
    New Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0


    Default Adding a shipping module from scratch

    Hi there, I am trying to add a new shipping module from scratch. I have located the built in shipping modules, flat.php, ups.php, etc and I have created a new .php page and I have attempted to customize it to my needs but I am having a devil of a time changing all the fields. I have changed the title and description of the module but I can't seem to figure out how to add/change the fields that show up when you click on the "edit" button to customize the info. Any tips/tricks on how to go about this? I can provide additional info if needed.

    Thanks,
    Kevin

  2. #2
    osCMax Development Team
    pgmarshall's Avatar
    Join Date
    Feb 2009
    Location
    London
    Posts
    2,678
    Rep Power
    49


    Default Re: Adding a shipping module from scratch

    Which shipping firm is it?

    Regards,
    pgmarshall
    _______________________________

  3. #3
    New Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0


    Default Re: Adding a shipping module from scratch

    Hi pgmarshall, the shipping firm is KBM, does that help?

  4. #4
    osCMax Development Team
    pgmarshall's Avatar
    Join Date
    Feb 2009
    Location
    London
    Posts
    2,678
    Rep Power
    49


    Default Re: Adding a shipping module from scratch

    Which shipping firm is it?

    Regards,
    pgmarshall
    _______________________________

  5. #5
    New Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0


    Default Re: Adding a shipping module from scratch

    Hi pgmarshall, the shipping firm is KBM.

  6. #6
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Post Re: Adding a shipping module from scratch

    To help you on your way... Here's one I created last week called Courier, based on Table Rate. Just change courier for kbm, Courier for KBM, COURIER for KBM - should be good to go, if you need all of this functionality.

    File: catalog/includes/modules/shipping/courier.php
    PHP Code:
    <?php
    /*
    Courier based on..
    $Id: table.php 3 2006-05-27 04:59:07Z user $

      osCMax Power E-Commerce
      http://oscdox.com

      Copyright 2006 osCMax

      Released under the GNU General Public License
    */

      
    class courier {
        var 
    $code$title$description$icon$enabled;

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

          
    $this->code 'courier';
          
    $this->title MODULE_SHIPPING_COURIER_TEXT_TITLE;
          
    $this->description MODULE_SHIPPING_COURIER_TEXT_DESCRIPTION;
          
    $this->sort_order MODULE_SHIPPING_COURIER_SORT_ORDER;
          
    $this->icon '';
          
    $this->tax_class MODULE_SHIPPING_COURIER_TAX_CLASS;
          
    $this->enabled = ((MODULE_SHIPPING_COURIER_STATUS == 'True') ? true false);

          if ( (
    $this->enabled == true) && ((int)MODULE_SHIPPING_COURIER_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_COURIER_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;
            }
          }
        }

    // class methods
        
    function quote($method '') {
          global 
    $order$cart$shipping_weight$shipping_num_boxes;

          if (
    MODULE_SHIPPING_COURIER_MODE == 'price') {
            
    $order_total $cart->show_total();
          } else {
            
    $order_total $shipping_weight;
          }

          
    $table_cost split("[:,]" MODULE_SHIPPING_COURIER_COST);
          
    $size sizeof($table_cost);
          for (
    $i=0$n=$size$i<$n$i+=2) {
            if (
    $order_total <= $table_cost[$i]) {
              
    $shipping $table_cost[$i+1];
              break;
            }
          }

          if (
    MODULE_SHIPPING_COURIER_MODE == 'weight') {
            
    $shipping $shipping $shipping_num_boxes;
          }

          
    $this->quotes = array('id' => $this->code,
                                
    'module' => MODULE_SHIPPING_COURIER_TEXT_TITLE,
                                
    'methods' => array(array('id' => $this->code,
                                
    #
                                                         
    'title' => MODULE_SHIPPING_COURIER_TEXT_WAY,
                                                         
    'cost' => $shipping MODULE_SHIPPING_COURIER_HANDLING)));

          if (
    $this->tax_class 0) {
            
    $this->quotes['tax'] = tep_get_tax_rate($this->tax_class$order->delivery['country']['id'], $order->delivery['zone_id']);
          }

          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_COURIER_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 Courier Method', 'MODULE_SHIPPING_COURIER_STATUS', 'True', 'Do you want to offer Courier?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Courier Table', 'MODULE_SHIPPING_COURIER_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())");
          
    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 ('Table Method', 'MODULE_SHIPPING_COURIER_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");
          
    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_COURIER_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_COURIER_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_COURIER_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', 'MODULE_SHIPPING_COURIER_SORT_ORDER', '0', 'Sort order of display.', '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_COURIER_STATUS''MODULE_SHIPPING_COURIER_COST''MODULE_SHIPPING_COURIER_MODE''MODULE_SHIPPING_COURIER_HANDLING''MODULE_SHIPPING_COURIER_TAX_CLASS''MODULE_SHIPPING_COURIER_ZONE''MODULE_SHIPPING_COURIER_SORT_ORDER');
        }
      }
    ?>
    File: catalog/includes/languages/english/modules/shipping/courier.php
    PHP Code:
    <?php
    /*
    courier based on...
    $Id: table.php 3 2006-05-27 04:59:07Z user $

      osCMax Power E-Commerce
      http://oscdox.com

      Copyright 2006 osCMax2005 osCMax, 2002 osCommerce

      Released under the GNU General Public License
    */

    define('MODULE_SHIPPING_COURIER_TEXT_TITLE''Courier');
    define('MODULE_SHIPPING_COURIER_TEXT_DESCRIPTION''Courier Rate');
    define('MODULE_SHIPPING_COURIER_TEXT_WAY''Courier Delivery');
    define('MODULE_SHIPPING_COURIER_TEXT_WEIGHT''Weight');
    define('MODULE_SHIPPING_COURIER_TEXT_AMOUNT''Amount');
    ?>
    EJ
    Last edited by ridexbuilder; 07-25-2011 at 03:03 PM. Reason: forum is screwing with me again - pasting in stuff
    Hosting plans with installation, configuration, contributions, support and maintenance.

  7. #7
    New Member
    Join Date
    Jul 2011
    Posts
    9
    Rep Power
    0


    Default Re: Adding a shipping module from scratch

    Thanks, that worked. This is some old code that was used, for some reason when I attempt to use this code it hides all the other built in shipping templates (fedex1.php, usps.php, etc, see screen capture) then when I remove the PHP file from the shipping directory the other shipping templates reappear, any idea why??

    PHP Code:
    <?php
    /*
    Courier based on..
    $Id: table.php 3 2006-05-27 04:59:07Z user $

      osCMax Power E-Commerce
      http://oscdox.com

      Copyright 2006 osCMax

      Released under the GNU General Public License
    */

      
    class KBM {
        var 
    $code$title$description$icon$enabled;

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

          
    $this->code 'KBM';
          
    $this->title 'KBM';
          
    $this->description 'KBM';
          
    $this->sort_order MODULE_SHIPPING_KBM_SORT_ORDER;
          
    $this->icon '';
          
    $this->tax_class MODULE_SHIPPING_KBM_TAX_CLASS;
          
    $this->enabled = ((MODULE_SHIPPING_KBM_STATUS == 'True') ? true false);

          if ( (
    $this->enabled == true) && ((int)MODULE_SHIPPING_KBM_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_KBM_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;
            }
          }
        }

    // class methods
        
    function quote($method '') {
          global 
    $order;

          
    $this->quotes = array('id' => $this->code,
                                
    'module' => MODULE_SHIPPING_KBM_TEXT_TITLE,
                                
    'methods' => array(array('id' => $this->code,
                                                         
    'title' => '<FONT COLOR=FF0000><B>' MODULE_SHIPPING_KBM_TEXT_WAY '</B></FONT>',
                                                         
    'cost' => SHIPPING_HANDLING MODULE_SHIPPING_KBM_COST)));

          if (
    $this->tax_class 0) {
            
    $this->quotes['tax'] = tep_get_tax_rate($this->tax_class$order->delivery['country']['id'], $order->delivery['zone_id']);
          }
          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_KBM_STATUS'");
            
    $this->_check tep_db_num_rows($check_query);
          }
          return 
    $this->_check;
        }

        function 
    install() {

          
    // VF Added the following - specific to KBM
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Customer No', 'MODULE_SHIPPING_KBM_CUSTOMER', ' ', 'The customer number required by KBM Parcel Web Services.', '6', '1', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Contract No', 'MODULE_SHIPPING_KBM_CONTRACT', ' ', 'The contract number required by KBM Parcel Web Services.', '6', '2', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Web service Key (WSID)', 'MODULE_SHIPPING_KBM_KEY', ' ', 'The development or production key (development for testing)', '6', '3', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Web service password', 'MODULE_SHIPPING_KBM_PASSWORD', ' ', 'The password for the key.', '6', '4', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enable Free Shipping', 'MODULE_SHIPPING_KBM_STATUS', '1', 'Do you want to offer Free shipping?', '6', '5', now())");
          
    tep_db_query("insert into " TABLE_CONFIGURATION " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Free Shipping Cost', 'MODULE_SHIPPING_KBM_COST', '0.00', 'What is the Shipping cost? The Handling fee will also be added.', '6', '6', 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_KBM_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '7', '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_KBM_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '8', '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', 'MODULE_SHIPPING_KBM_SORT_ORDER', '0', 'Sort order of display.', '6', '9', now())");
        }

        function 
    remove() {
          
    $keys '';
          
    $keys_array $this->keys();
          for (
    $i=0$i<sizeof($keys_array); $i++) {
            
    $keys .= "'" $keys_array[$i] . "',";
          }
          
    $keys substr($keys0, -1);

          
    tep_db_query("delete from " TABLE_CONFIGURATION " where configuration_key in (" $keys ")");
        }

        function 
    keys() {
          return array(
    'MODULE_SHIPPING_KBM_CUSTOMER','MODULE_SHIPPING_KBM_CONTRACT','MODULE_SHIPPING_KBM_KEY','MODULE_SHIPPING_KBM_PASSWORD','MODULE_SHIPPING_KBM_STATUS''MODULE_SHIPPING_KBM_COST''MODULE_SHIPPING_KBM_TAX_CLASS''MODULE_SHIPPING_KBM_ZONE''MODULE_SHIPPING_KBM_SORT_ORDER'');
        }
      }
    ?>
    Attached Images Attached Images

Similar Threads

  1. [osCmax v2.5x] Adding new shipping module epic_fail
    By peterittner in forum osCmax v2 Customization/Mods
    Replies: 1
    Last Post: 01-05-2011, 02:38 PM
  2. Create osCmax Template From Scratch
    By usuk2007 in forum Introduce yourself!
    Replies: 6
    Last Post: 04-15-2009, 08:03 AM
  3. oscommerce installation from scratch
    By bokachoda in forum osCommerce 2.2 Installation Help
    Replies: 20
    Last Post: 03-13-2009, 12:08 PM
  4. How to remove scratch price from special products
    By padma in forum osCMax v1.7 General Mods Discussion
    Replies: 4
    Last Post: 02-10-2009, 07:40 AM
  5. osCommerce MS2Max from scratch - Urgent help needed!
    By pram0310 in forum osCMax v1.7 Installation
    Replies: 3
    Last Post: 12-02-2004, 06:22 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •