Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How do I copy this zones shipping module zones.php


sahilsaid

Recommended Posts

Posted

Hi,

 

I successfully copied the table shipping file but I am getting error after copying/cloning the zones shipping file (zones.php). I am using the same method.

 

Here is the zones.php file

 

<?php

 class zones {
   var $code, $title, $description, $enabled, $num_zones, $vendors_id; //multi vendor

   // class constructor
   function zones() {
     $this->code = 'zones';
     $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
     $this->icon = '';
   }

   //MVS Start
   function sort_order($vendors_id = '1') {
     $sort_order = @ constant('MODULE_SHIPPING_ZONES_SORT_ORDER_' . $vendors_id);
     if (isset ($sort_order)) {
       $this->sort_order = $sort_order;
     } else {
       $this->sort_order = '-';
     }
     return $this->sort_order;
   }

   function tax_class($vendors_id = '1') {
     $this->tax_class = constant('MODULE_SHIPPING_ZONES_TAX_CLASS_' . $vendors_id);
     return $this->tax_class;
   }

   function enabled($vendors_id = '1') {
     $this->enabled = false;
     $status = @ constant('MODULE_SHIPPING_ZONES_STATUS_' . $vendors_id);
     if (isset ($status) && $status != '') {
       $this->enabled = (($status == 'True') ? true : false);
     }
     return $this->enabled;
   }

   //Set the number of zones used for this vendor
   function num_zones($vendors_id = '1') {
     $vendors_data_query = tep_db_query("select zones
                                         from " . TABLE_VENDORS . "
                                         where vendors_id = '" . (int) $vendors_id . "'");
     $vendors_data = tep_db_fetch_array($vendors_data_query);
     $this->num_zones = $vendors_data['zones'];
     return $this->num_zones;
   }
   //MVS End

   //Get a quote
   function quote($method = '', $module = '', $vendors_id = '1') {
     global $HTTP_POST_VARS, $shipping_weight, $order, $cart, $shipping_num_boxes;
     //MVS Start
     //return an error if the module is not enabled for this vendor
     if ($this->enabled($vendors_id) < 1) {
       $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;
       return $this->quotes;
     }
     //MVS End

     $dest_country = $order->delivery['country']['iso_code_2'];

     //Zones within countries
     $dest_state = $order->delivery['state'];
     $dest_zone_id = $order->delivery['zone_id'];
     if ($dest_zone_id > 0) {
       $zone_query = tep_db_query("select distinct zone_code from " . TABLE_ZONES . " where zone_id = '" . $dest_zone_id . "'");
       if (tep_db_num_rows($zone_query) == 1) {
         $dest_zone_n = tep_db_fetch_array($zone_query);
         $dest_state = $dest_zone_n['zone_code'];
       }
     }

     $state_shipping = 0;
     //Zones within countries End

     $dest_zone = 0;
     $error = false;

     for ($i = 1; $i <= $this->num_zones($vendors_id); $i++) {
       $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $vendors_id . '_' . $i);
       $country_zones = split("[,]", $countries_table);
       if (in_array($dest_country, $country_zones)) {
         $dest_zone = $i;
         break;
       }
     }
     if ($dest_zone == 0) {
       //Zones within countries	 
       for ($i = 1; $i <= $this->num_zones($vendors_id); $i++) {
         $countries_table = constant('MODULE_SHIPPING_ZONES_COUNTRIES_' . $vendors_id . '_' . $i);
         $country_zones = split("[,]", $countries_table);
         if (in_array($dest_country, $country_zones)) {
           $dest_zone = $i;
           $state_shipping = 1;
           break;
         }

         // rest of the world
         if ($countries_table == 'WORLD') {
           $dest_zone = $i;
           break;
         }
       }
     }
     //Zones within countries End	

     if ($dest_zone == 0) {
       $error = true;
	$this->enabled = false;
     } else {
       $shipping = -1;
       $zones_cost = constant('MODULE_SHIPPING_ZONES_COST_' . $vendors_id . '_' . $dest_zone);

       $zones_table = split("[:,]", $zones_cost);
       $size = sizeof($zones_table);
       for ($i = 0; $i < $size; $i += 2) {
         if ($shipping_weight <= $zones_table[$i]) {
           $shipping = $zones_table[$i +1];
           if ($state_shipping == 1) {
             $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_state . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS;
             break;
           } else {
             $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS;
             break;
           }
         }
       }

       if ($shipping == -1) {
         $shipping_cost = 0;
         $shipping_method = MODULE_SHIPPING_ZONES_UNDEFINED_RATE;
	  $this->enabled = false;
       } else {
         //MVS Start
         $vendors_data_query = tep_db_query("select handling_charge,
                                                    handling_per_box
                                             from " . TABLE_VENDORS . "
                                             where vendors_id = '" . (int) $vendors_id . "'");
         $vendors_data = tep_db_fetch_array($vendors_data_query);

         //Set handling to the handling per box times number of boxes, or handling charge if it is larger
         $handling_charge = $vendors_data['handling_charge'];
         $handling_per_box = $vendors_data['handling_per_box'];
         if ($handling_charge > $handling_per_box * $shipping_num_boxes) {
           $handling = $handling_charge;
         } else {
           $handling = $handling_per_box * $shipping_num_boxes;
         }

         //Set handling to the module's handling charge if it is larger
         $module_handling = constant('MODULE_SHIPPING_ZONES_HANDLING_' . $vendors_id . '_' . $dest_zone);
         $handling += $module_handling;

         if (strpos($shipping, "%") === false) {
           $shipping_cost = ($shipping * $shipping_num_boxes) + $handling;
         } else {
           $shipcst = (str_replace("%", "", $shipping) / 100);
           $shipping_cost = ($shipping_weight * $shipcst) + $handling;
         }
         // Calculate shipping amount with tax if applicable
         //		 if (constant('MODULE_SHIPPING_ZONES_TAX_CLASS_' . $vendors_id) > 0 ) { 
         //		 $shp_tax_rate = tep_get_tax_rate(constant('MODULE_SHIPPING_ZONES_TAX_CLASS_' . $vendors_id), $order->delivery['country']['id'], $order->delivery['zone_id']);
         //		 $shipping_cost_without_tax = $shipping_cost - $handling;
         //		 $shp_tax_amount = $shipping_cost_without_tax * ($shp_tax_rate / 100);		 
         //		 $shipping_cost = $shipping_cost_without_tax + $shp_tax_amount + $handling;

         //		 }
         //MVS End
       }
     }

     $this->quotes = array (
       'id' => $this->code,
       'module' => MODULE_SHIPPING_ZONES_TEXT_TITLE,
       'methods' => array (
         array (
           'id' => $this->code,
           'title' => $shipping_method,
           'cost' => $shipping_cost
         )
       )
     );
     // $this->tax_class = constant(MODULE_SHIPPING_ZONES_TAX_CLASS_ . $vendors_id);
     if ($this->tax_class($vendors_id) > 0) {
       $this->quotes['tax'] = tep_get_tax_rate($this->tax_class($vendors_id), $order->delivery['country']['id'], $order->delivery['zone_id']);
     }
     if (tep_not_null($this->icon))
       $this->quotes['icon'] = tep_image($this->icon, $this->title);

	if ($shipping_cost==0) {
$this->quotes = '';
}

else {

    // if ($error == true)
     //  $this->quotes['error'] = MODULE_SHIPPING_ZONES_INVALID_ZONE;

     return $this->quotes;
   }
}
   function check($vendors_id = '1') {
     if (!isset ($this->_check)) {
       //multi vendor add  "vendors_id = '". $vendors_id ."' and"
       $check_query = tep_db_query("select configuration_value from " . TABLE_VENDOR_CONFIGURATION . " where vendors_id = '" . $vendors_id . "' and configuration_key = 'MODULE_SHIPPING_ZONES_STATUS_" . $vendors_id . "'");
       $this->_check = tep_db_num_rows($check_query);
     }
     return $this->_check;
   }

   //MVS start
   function install($vendors_id = '1') {
     $vID = $vendors_id;
     //multi vendor add 'vendors_id' to field names and '" . $vID . "', to values
     tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('" . $vendors_id . "', 'Enable Zones Method', 'MODULE_SHIPPING_ZONES_STATUS_" . $vendors_id . "', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
     tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('" . $vendors_id . "', 'Tax Class', 'MODULE_SHIPPING_ZONES_TAX_CLASS_" . $vendors_id . "', '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_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . $vendors_id . "', 'Sort Order', 'MODULE_SHIPPING_ZONES_SORT_ORDER_" . $vendors_id . "', '0', 'Sort order of display.', '6', '0', now())");
     for ($i = 1; $i <= $this->num_zones($vendors_id); $i++) {
       $default_countries = '';
       if ($i == 1) {
         $default_countries = 'US,CA';
       }
       tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . $vendors_id . "', 'Zone " . $i . " Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $vendors_id . "_" . $i . "', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())");
       tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . $vendors_id . "', 'Zone " . $i . " Shipping Table', 'MODULE_SHIPPING_ZONES_COST_" . $vendors_id . "_" . $i . "', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', now())");
       tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (vendors_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('" . $vendors_id . "', 'Zone " . $i . " Handling Fee', 'MODULE_SHIPPING_ZONES_HANDLING_" . $vendors_id . "_" . $i . "', '0', 'Handling Fee for this shipping zone', '6', '0', now())");
     }
   }

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

   function keys($vendors_id) {
     $keys = array (
       'MODULE_SHIPPING_ZONES_STATUS_' . $vendors_id,
       'MODULE_SHIPPING_ZONES_TAX_CLASS_' . $vendors_id,
       'MODULE_SHIPPING_ZONES_SORT_ORDER_' . $vendors_id
     );

     for ($i = 1; $i <= $this->num_zones($vendors_id); $i++) {
       $keys[] = 'MODULE_SHIPPING_ZONES_COUNTRIES_' . $vendors_id . '_' . $i;
       $keys[] = 'MODULE_SHIPPING_ZONES_COST_' . $vendors_id . '_' . $i;
       $keys[] = 'MODULE_SHIPPING_ZONES_HANDLING_' . $vendors_id . '_' . $i;
     }
     //MVS End

     return $keys;
   }
 }

?>

 

I used find and replace function to replace all "zones" with "airmail2" for example and all "MODULE_SHIPPING_ZONES" to "MODULE_SHIPPING_AIRMAIL2" and then renamed the module file and language file. But I am getting error on module screen reading as following:

 

Fatal error: Call to undefined method rmairmail2::zones() in /home/thechea6/public_html/thecheaplaptops_madmin/vendor_modules.php on line 148

Posted

I used find and replace function to replace all "zones" with "airmail2" for example and all "MODULE_SHIPPING_ZONES" to "MODULE_SHIPPING_AIRMAIL2" and then renamed the module file and language file. But I am getting error on module screen reading as following:

 

Fatal error: Call to undefined method rmairmail2::zones() in /home/thechea6/public_html/thecheaplaptops_madmin/vendor_modules.php on line 148

 

 

Found the answer myself. The answer is in the error itself. do not remove/rename the following function near the top, just keep it as is and it should work. BTW I am using this module with MVS.

 

// class constructor

function zones() {

$this->code = 'zones';

$this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;

$this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;

$this->icon = '';

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...