Forums / Built-in Shipping and Payment Modules / new 8 zone shipping mod help Please??

new 8 zone shipping mod help Please??

Locked

Views: 2,446

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
9 Jul 2008, 10:07 PM
#1
ontwolf avatar

ontwolf

New Zenner

Join Date:
Jan 2008
Location:
ontario canada
Posts:
8
Plugin Contributions:
0

new 8 zone shipping mod help Please??

I am in the process of converting oscommerce mod that calculates shipping cost by percentage of cart amount and the zone in which you live according to SMC.

I have converted mod and it shows up in admin fine and installs, however when the customer arives at estimated shipping cost and checkout page they receive blank page.

When I check debug mod I receive following error:

[09-Jul-2008 16:46:29] PHP Fatal error: Maximum execution time of 60 seconds exceeded in /home/greatcan/public_html/catalog/includes/modules/shipping/smc.php on line 113

line 113 reads: $dest_zone = $check['shipzonecode'];

below is the complete mod:

ANY HELP GREATLY APPRECIATED

 class smc {
    var $code, $title, $description, $enabled, $num_zones;

// class constructor
    function smc() {
      $this->code = 'smc';
      $this->title = MODULE_SHIPPING_SMC_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_SMC_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_SMC_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_SMC_TAX_CLASS;
      $this->enabled = ((MODULE_SHIPPING_SMC_STATUS == 'True') ? true : false);

      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      $this->num_zones = 10;
	  $this->num_zone_start = 2;
    }

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

      $dest_country = $order->delivery['country']['iso_code_2'];
      $dest_zone = 0;
      $error = false;

		$zipcode_prefix = substr($order->delivery['postcode'],0,3);
		global $db;
		$check = $db->Execute("select shipzonecode from " . TABLE_SHIPZONECODE . " where '" . $zipcode_prefix . "' BETWEEN shipzonestartzip and shipzoneendzip");
        while (!$check->EOF)) {




			$dest_zone = $check['shipzonecode'];



          }
		  $check->MoveNext();
//		echo $dest_zone;




      if ($dest_zone == 0) {
        $error = true;
      } else {
	  
		/* This is the Shipping Calculation Area */	  
        $shipping = -1;
        $zones_cost = constant('MODULE_SHIPPING_SMC_COST_' . $dest_zone);
		$order_total = $cart->show_total();
        $zones_table = split("[:,]" , $zones_cost);
        $size = sizeof($zones_table);
        for ($i=0; $i<$size; $i+=2) {
          if ($order_total <= $zones_table[$i]) {
            $shipping = $zones_table[$i+1];
            $shipping_method = MODULE_SHIPPING_SMC_TEXT_WAY . ' ' . $order->delivery['postcode'];
            break;
          }
        }
		/*End of Shipping Calculation Area */

        if ($shipping == -1) {
          $shipping_cost = 0;
          $shipping_method = MODULE_SHIPPING_SMC_UNDEFINED_RATE;
        } else {
			if (strpos($shipping, "%") === false) {
				$shipping_cost = ($shipping) + constant('MODULE_SHIPPING_SMC_HANDLING_' . $dest_zone);
			} else {
				$shipcost = (str_replace("%","",$shipping) / 100);
				$shipping_cost = ($order_total * $shipcost) + constant('MODULE_SHIPPING_SMC_HANDLING_' . $dest_zone);
			}
        }
      }

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_SMC_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => $shipping_method,
                                                     'cost' => $shipping_cost)));

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

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

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

      return $this->quotes;
    }

    function check() {
	global $db;
      if (!isset($this->_check)) {
        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_SMC_STATUS'");
        $this->_check = $check_query->RecordCount();
      }
      return $this->_check;
    }

    function install() {
      global $db;
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Zones Method', 'MODULE_SHIPPING_SMC_STATUS', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
      $db->Execute("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_SMC_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_SMC_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
      for ($i = $this->num_zone_start; $i <= $this->num_zones + ($this->num_zone_start - 1); $i++) {
        $default_countries = 'US';
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_SMC_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())");
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_SMC_COST_" . $i ."', '25:6.50,500:13%,999999:5%', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order amounts. Example: 25:6.50,500:13%,999999:5%,... Amounts less than or equal to 25 would cost 6.50 for Zone " . $i . " destinations.', '6', '0', now())");
      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_SMC_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())");
      }
    }

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

    function keys() {
      $keys = array('MODULE_SHIPPING_SMC_STATUS', 'MODULE_SHIPPING_SMC_TAX_CLASS', 'MODULE_SHIPPING_SMC_SORT_ORDER');

      for ($i = $this->num_zone_start; $i <= $this->num_zones + ($this->num_zone_start - 1); $i++) {
        $keys[] = 'MODULE_SHIPPING_SMC_COUNTRIES_' . $i;
        $keys[] = 'MODULE_SHIPPING_SMC_COST_' . $i;
        $keys[] = 'MODULE_SHIPPING_SMC_HANDLING_' . $i;
      }

      return $keys;
    }
  }
?>
                                            Thanks in advance for any input
10 Jul 2008, 3:21 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: new 8 zone shipping mod help Please??

        while (!$check->EOF)) {




			$dest_zone = $check['shipzonecode'];


[B]
          }
		  $check->MoveNext();
[/B]
```These two lines need to be reversed.  ie: the closing brace for the while() statement needs to come *after* the MoveNext() call, otherwise you end up in an endless loop.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jul 2008, 2:22 AM
#3
ontwolf avatar

ontwolf

New Zenner

Join Date:
Jan 2008
Location:
ontario canada
Posts:
8
Plugin Contributions:
0

Re: new 8 zone shipping mod help Please??

thankyou mod now installs and I am able to configure but shipping charges don't show, It tells me shipping not available to selected country

no errors show up in error log or debug mod

Script was converted from osc mod so I am thinking it has to be a bad variable or missing function but I would think I would get a php error somewhere

Anyone have any ideas??

Thanks Guys in advance

13 Jul 2008, 4:36 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: new 8 zone shipping mod help Please??

Not sure if this is the specific cause or not, but something I noticed while looking at the code you posted earlier was:$order_total = $cart->show_total();should be:```
$order_total = $_SESSION['cart']->show_total();

And you don't need $cart listed in your "global" statement earlier in the same function.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

16 Jul 2008, 4:37 AM
#5
ontwolf avatar

ontwolf

New Zenner

Join Date:
Jan 2008
Location:
ontario canada
Posts:
8
Plugin Contributions:
0

Re: new 8 zone shipping mod help Please??

Thanks to Dr Byte I finally got it to work, now to only tweak it then it will be ready for distribution.

THE FEATURES OF MOD ARE:

  1. Shipping Rate is determined by destination zone according to UPS and DHL 7 Zone zipcode freight chart. Easily
    configurable to other countries and different shipping charts.
  2. Zipcode Zone determined by MYSQL driven data base.
  3. zipcode table easily convertable to most countries
  4. handles shipping by percentage or flat rate
  5. Number of Zones are adjustable set to 7 by default
  6. Start zone is configurable 2 by default
  7. Can have more than 1 percentage or flat rate per zone
  8. handling rate can be added to each zone
  9. Mod doesn't modify any files in ZenCart.

If interested in such a mod
leave me a message

10 Dec 2008, 5:45 PM
#6
hello_wurld avatar

hello_wurld

New Zenner

Join Date:
Dec 2008
Posts:
2
Plugin Contributions:
0

Re: new 8 zone shipping mod help Please??

Did you ever get a working Mod??

I am trying to setup the same SMC scenario

Could really use some direction and help

18 Jun 2009, 10:54 AM
#7
gypsyphoenix avatar

gypsyphoenix

New Zenner

Join Date:
Mar 2009
Posts:
9
Plugin Contributions:
0

Re: new 8 zone shipping mod help Please??

Did you ever get a reply to your request for info on the modified Mod? Also using SMC so very interested.